Problem
I'm using Toast UI Editor with the color syntax plugin. When I apply a color to selected text:
- Issue 1: The cursor jumps to the beginning of the line/paragraph (only on first color change)
- Issue 2: When changing text to the same color or partially changing color, the highlight still displays
Environment
- Toast UI Editor: [version]
- @toast-ui/editor-plugin-color-syntax: [version]
- Browser: [browser + version]
Expected Behavior
- Selection/cursor should remain at the end of selected text after color is applied
- Changing to same color should remove the color (not display highlight)
Actual Behavior
- Cursor jumps to beginning of line after applying color (first time only)
- Highlight background still appears even after changing to same color
Attempts Made
- Tried setting
tr.setSelection()before and after dispatch - Tried saving/restoring selection using
editorNode.getSelection()/setSelection() - Tried wrapping dispatch with setTimeout
- Tried calling original command instead of custom implementation
None of these approaches solved the cursor jumping issue.
Question
- How can I prevent the selection from being reset after the color command?
- Is there a proper way to handle selection preservation in Toast UI Editor plugins?
- Should I use a different approach (hooks, events, etc.) instead of overriding the command?
Any insights would be appreciated!