Skip to content

Commit 2ac6ae2

Browse files
committed
Skip badge overlap mode when editor is not focused
Same root cause as the auto-select guard in `EditableText/Selection`: slate-react's throttled `selectionchange` listener can sync a clamped DOM cursor back into `editor.selection` after the user has clicked away. `BadgeColumn` would then read a non-null `editor.selection`, `highlightOverlapsSelection` would return true if the synthetic cursor happened to land in a highlighted range, and the badge would flip from `dot` to overlap mode without an actual user selection. Gate `editorSelection` on `ReactEditor.isFocused(editor)` so badges fall back to dot mode whenever the editor isn't focused. REDMINE-21261
1 parent a5b3893 commit 2ac6ae2

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • entry_types/scrolled/package/src/frontend/inlineEditing/EditableText

entry_types/scrolled/package/src/frontend/inlineEditing/EditableText/BadgeColumn.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

33
import {FloatingPortal} from '@floating-ui/react';
4-
import {useSlate} from 'slate-react';
4+
import {useSlate, ReactEditor} from 'slate-react';
55

66
import {Badge, useAnchoredFloating} from 'pageflow-scrolled/review';
77
import {useFloatingPortalRoot} from '../../FloatingPortalRootProvider';
@@ -11,11 +11,17 @@ import {highlightOverlapsSelection} from './highlightOverlapsSelection';
1111

1212
export function BadgeColumn({highlights, anchors}) {
1313
const editor = useSlate();
14+
// Treat `editor.selection` as a live cursor only while the editor
15+
// is focused. After the user clicks away, slate-react's throttled
16+
// `selectionchange` listener can sync a clamped DOM cursor back
17+
// into `editor.selection`, which would otherwise flip badges back
18+
// to overlap mode without any actual selection.
19+
const editorSelection = ReactEditor.isFocused(editor) ? editor.selection : null;
1420

1521
return highlights.map(highlight => (
1622
<PositionedBadge key={highlight.key}
1723
highlight={highlight}
18-
editorSelection={editor.selection}
24+
editorSelection={editorSelection}
1925
anchors={anchors} />
2026
));
2127
}

0 commit comments

Comments
 (0)