Skip to content

Commit 27901e4

Browse files
committed
docs(rich-md-editor): preserve bubble reveal + blur rationale via a helper + TSDoc
1 parent e3e702a commit 27901e4

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/menus

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/menus/bubble-menu.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ function hasFormattableSelection(editor: Editor, from: number, to: number): bool
3232
return editor.state.doc.textBetween(from, to, ' ').trim().length > 0
3333
}
3434

35+
/**
36+
* Reveals the bubble menu for the current selection. Both calls are required and must stay in order:
37+
* `show` alone leaves the bar visible but unpositioned (its internal `updatePosition` no-ops until the
38+
* menu is shown), so the follow-up `updatePosition` anchors it. Both are step-free transactions, so
39+
* neither marks the document dirty.
40+
*/
41+
function revealBubbleMenu(editor: Editor, key: PluginKey): void {
42+
editor.commands.setMeta(key, 'show')
43+
editor.commands.setMeta(key, 'updatePosition')
44+
}
45+
3546
/** Pins the toolbar to the viewport so it stays put while the document scrolls instead of tracking the text. */
3647
const FLOATING_OPTIONS = { strategy: 'fixed' } as const
3748

@@ -91,6 +102,12 @@ export function EditorBubbleMenu({ editor, scrollContainerRef }: EditorBubbleMen
91102
}
92103
}, [editor])
93104

105+
/**
106+
* Linear-style reveal: the toolbar stays hidden while the pointer is down (the drag gate in
107+
* `shouldShow`) and surfaces on release. `mouseup`/`blur` listen on `window` so a release outside
108+
* the editor — or off-screen, where no `mouseup` fires — still clears the drag flag; otherwise it
109+
* could wedge `true` and suppress the toolbar for later keyboard selections.
110+
*/
94111
useEffect(() => {
95112
const dom = editor.view.dom
96113
const onPointerDown = () => {
@@ -100,10 +117,7 @@ export function EditorBubbleMenu({ editor, scrollContainerRef }: EditorBubbleMen
100117
if (!isPointerDownRef.current || editor.isDestroyed) return
101118
isPointerDownRef.current = false
102119
const { from, to } = editor.state.selection
103-
if (hasFormattableSelection(editor, from, to)) {
104-
editor.commands.setMeta(bubbleMenuKey, 'show')
105-
editor.commands.setMeta(bubbleMenuKey, 'updatePosition')
106-
}
120+
if (hasFormattableSelection(editor, from, to)) revealBubbleMenu(editor, bubbleMenuKey)
107121
}
108122
const onWindowBlur = () => {
109123
isPointerDownRef.current = false

0 commit comments

Comments
 (0)