Commit c315599
authored
fix(super-editor): prevent cursor jump when changing font from toolbar (#2468)
When the user selects a font from the toolbar dropdown, the hidden
ProseMirror editor loses focus. On re-focus, the browser places the DOM
selection at an arbitrary position inside the off-screen contenteditable
(left: -9999px). ProseMirror's DOMObserver reads this stale position via
a selectionchange event and overwrites PM state, causing the cursor to
jump to position 2 (near the top of the document).
The wrapped focus in PresentationEditor only called view.dom.focus()
without calling selectionToDOM(), unlike ProseMirror's original focus()
which stops the observer, focuses, syncs the selection, then restarts.
Fix: call view.domObserver.suppressSelectionUpdates() after focusing when
the editor was not previously focused. This tells PM to re-apply its own
selection to the DOM instead of reading the stale browser position.1 parent 5eca65b commit c315599
3 files changed
Lines changed: 23 additions & 0 deletions
File tree
- packages/super-editor/src/core/presentation-editor
- tests
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
753 | 753 | | |
754 | 754 | | |
755 | 755 | | |
| 756 | + | |
756 | 757 | | |
757 | 758 | | |
758 | 759 | | |
| |||
791 | 792 | | |
792 | 793 | | |
793 | 794 | | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
794 | 805 | | |
795 | 806 | | |
796 | 807 | | |
| |||
packages/super-editor/src/core/presentation-editor/tests/PresentationEditor.draggableFocus.test.ts
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
121 | 127 | | |
122 | 128 | | |
123 | 129 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
136 | 142 | | |
137 | 143 | | |
138 | 144 | | |
| |||
0 commit comments