-
-
Notifications
You must be signed in to change notification settings - Fork 373
Description
We implemented custom highlighting using Decoration.inline and discovered an issue with selecting text from the keyboard using Shift + Arrow combinations in the Safari browser.
In Safari, when using keyboard selection (Shift + Arrow), the selection area can only be enlarged and cannot be reduced back. Once the selection has started to expand, it continues to expand in both directions, regardless of the direction of the arrow keys, and does not return to a smaller range.
This is probably because the anchor and head values switch places depending on the direction of the hotkey used, which leads to incorrect selection logic when using Decoration.inline.
Steps to reproduce
- Select a word in the editor
- Press
Shift + ArrowRightto expand the selection - Press
Shift + ArrowLeftto reduce the selection
Expected behavior
- The selection expands to the right
- After pressing
Shift + ArrowLeft, the selection shrinks back toward the original range
Actual behavior
- The selection expands to the right
- After pressing
Shift + ArrowLeft, the selection expands in the opposite direction instead of shrinking
Example
To demonstrate the problem, a minimal editor based on basic schema was prepared. A plugin using Decoration.inline was added to the editor to implement custom highlighting. The example is available in CodeSandbox and reproduces the described behavior - https://codesandbox.io/p/sandbox/inline-decoration-selection-tvkfyq
Plugin code
import { Plugin, PluginKey } from "prosemirror-state";
import { Decoration, DecorationSet } from "prosemirror-view";
const selectionPlugin = () =>
new Plugin({
key: new PluginKey("customSelection"),
props: {
decorations(state) {
return DecorationSet.create(state.doc, [
Decoration.inline(state.selection.from, state.selection.to, {
class: "customSelection",
}),
]);
},
},
});
Environment
prosemirror-view: 1.41.5
prosemirror-state: 1.4.4
Safari: 26.1 (21622.2.11.11.9)
macOS: 26.1
