Text-Editor: B/I/U sync via queryCommandState + RTF-Reihenfolge fixen

User: B/I/U Toggle-Buttons hinken hinterher oder zeigen invertiert.
Im WYSIWYG sieht alles richtig aus aber Rhino zeigt nur die LETZTE
gesetzte Schriftart fuer alles.

Fix 1 — B/I/U sync:
- selectionchange-Listener pollt jetzt queryCommandState fuer
  bold/italic/underline und syncen das an Toolbar-State
- toggleBold/Italic/Underline machen nur noch exec() — kein manuelles
  setBold(b => !b) mehr (war out-of-sync wenn execCommand wegen
  fehlender Selection nicht griff)
- B/I/U-Button-Highlight reflektiert jetzt die echte Cursor-Position

Fix 2 — RTF nimmt nur letzte Schrift:
Reihenfolge im _commit war falsch. Vorher: RichText → TextHeight →
_apply_font → _apply_align. _apply_font setzt te.Font (Default-Font)
NACH dem RichText → schiesst die per-Run-Fonts in der RTF tot.

Neue Reihenfolge:
1. PlainText (Initial-Content)
2. TextHeight, Font, Align (Defaults fuer ALLES)
3. RichText (ueberschreibt Defaults pro Run)

Plus Font-Tabelle in _runs_to_rtf jetzt mit \fnil\fcharset0 Marker
(Rhinos RTF-Parser kann sonst font-Eintraege ignorieren und Default
verwenden).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-21 02:00:03 +02:00
parent 51987dcc38
commit 1596bbd941
2 changed files with 33 additions and 20 deletions
+9 -3
View File
@@ -237,6 +237,10 @@ export default function TextEditorApp() {
if (ed.contains(sel.anchorNode)) {
try { savedRangeRef.current = sel.getRangeAt(0).cloneRange() }
catch (e) {}
// B/I/U Toolbar-State an die echte Cursor-Position syncen
try { setBold(document.queryCommandState('bold')) } catch (e) {}
try { setItalic(document.queryCommandState('italic')) } catch (e) {}
try { setUnderline(document.queryCommandState('underline')) } catch (e) {}
}
}
document.addEventListener('selectionchange', onSelChange)
@@ -322,9 +326,11 @@ export default function TextEditorApp() {
fn()
}
const toggleBold = () => { setBold(b => !b); exec('bold') }
const toggleItalic = () => { setItalic(b => !b); exec('italic') }
const toggleUnderline = () => { setUnderline(b => !b); exec('underline') }
// setState NICHT manuell — der selectionchange-Listener syncen das
// an die echte queryCommandState-Antwort, sonst hinkt's hinterher.
const toggleBold = () => exec('bold')
const toggleItalic = () => exec('italic')
const toggleUnderline = () => exec('underline')
const doAlign = (a) => { setAlign(a)
exec(a === 'center' ? 'justifyCenter' : a === 'right' ? 'justifyRight' : 'justifyLeft') }
const doSup = () => exec('superscript')