Skip to content

Commit 038c832

Browse files
committed
chore(user-input): drop redundant inline comments from the mention-dismiss fix
Trims the inline // explanations added in the previous commit down to the two declaration-level doc comments that carry real information — matching the repo's no-inline-comments convention.
1 parent 3c11e59 commit 038c832

2 files changed

Lines changed: 15 additions & 30 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/prompt-editor/use-prompt-editor.test.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ describe('usePromptEditor mention menu dismissal', () => {
103103

104104
act(() => {
105105
typeInto(textarea, '@f')
106-
// `onChange` in the real component is wired to `handleInputChange`; the
107-
// hook only exposes it through the returned object, so invoke it the
108-
// same way `<textarea onChange={editor.handleInputChange} />` would.
109106
result().handleInputChange({
110107
target: textarea,
111108
currentTarget: textarea,
@@ -131,24 +128,18 @@ describe('usePromptEditor mention menu dismissal', () => {
131128
})
132129
expect(result().mentionQuery).toBe('f')
133130

134-
// Radix's DismissableLayer calls this on outside pointerdown / Escape —
135-
// never on a programmatic `plusMenuRef.current.close()`.
136131
act(() => {
137132
result().handlePlusMenuClose()
138133
})
139134
expect(result().mentionQuery).toBeNull()
140135

141-
// The same click that dismissed the popover also moves the caret via
142-
// native textarea behavior; the caret lands back at the end of the text,
143-
// i.e. still inside the unterminated "@f" token. Simulate the resulting
144-
// onSelect/onMouseUp without any further keystroke.
145136
act(() => {
146137
textarea.setSelectionRange(2, 2)
147138
result().handleSelectAdjust()
148139
})
149140

150141
expect(result().mentionQuery).toBeNull()
151-
expect(openMenu.open).toHaveBeenCalledTimes(1) // only the original open — no reopen
142+
expect(openMenu.open).toHaveBeenCalledTimes(1)
152143

153144
unmount()
154145
})
@@ -173,7 +164,6 @@ describe('usePromptEditor mention menu dismissal', () => {
173164
})
174165
expect(openMenu.open).toHaveBeenCalledTimes(1)
175166

176-
// User keeps editing the same token — this must reopen it.
177167
act(() => {
178168
typeInto(textarea, '@fo', 3)
179169
result().handleInputChange({
@@ -208,8 +198,6 @@ describe('usePromptEditor mention menu dismissal', () => {
208198
})
209199
expect(openMenu.open).toHaveBeenCalledTimes(1)
210200

211-
// Clear the field and start a brand new mention elsewhere in the text —
212-
// a stale dismissal must never leak onto an unrelated token.
213201
act(() => {
214202
typeInto(textarea, '@f done. @g', 11)
215203
result().handleInputChange({

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/prompt-editor/use-prompt-editor.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,10 @@ export function usePromptEditor({
180180
const [slashQuery, setSlashQuery] = useState<string | null>(null)
181181

182182
/**
183-
* Start offset of a mention/slash token the user just dismissed via outside
184-
* click or Escape. A dismiss alone doesn't move the caret, so the very next
185-
* `selectionchange`/click still lands inside the still-open token range and
186-
* would otherwise reopen the menu it was just closed — the "can't click
187-
* away" bug. Suppresses exactly one reopen per token; cleared the moment
188-
* the user types again (`handleInputChange`) so editing the token still
189-
* works normally.
183+
* Start offset of a mention/slash token most recently dismissed by the user
184+
* (outside click or Escape) without a following keystroke — suppresses a
185+
* single reopen of the menu for that exact token when the caret's own
186+
* selection-change handler runs immediately after.
190187
*/
191188
const dismissedMentionStartRef = useRef<number | null>(null)
192189
const dismissedSlashStartRef = useRef<number | null>(null)
@@ -447,18 +444,23 @@ export function usePromptEditor({
447444
[textareaRef, addContextNotified]
448445
)
449446

447+
/**
448+
* Only reachable via Radix's own dismiss detection (outside click /
449+
* Escape) — programmatic closes (`skillsMenuRef.current?.close()`) bypass
450+
* `onOpenChange` and never call this.
451+
*/
450452
const handleSkillsMenuClose = useCallback(() => {
451-
// See `handlePlusMenuClose` — only reachable via a real Radix dismiss.
452453
dismissedSlashStartRef.current = slashRangeRef.current?.start ?? null
453454
slashRangeRef.current = null
454455
setSlashQuery(null)
455456
}, [])
456457

458+
/**
459+
* Only reachable via Radix's own dismiss detection (outside click /
460+
* Escape) — programmatic closes (`plusMenuRef.current?.close()`) bypass
461+
* `onOpenChange` and never call this.
462+
*/
457463
const handlePlusMenuClose = useCallback(() => {
458-
// Only reachable via Radix's own dismiss detection (outside click / Escape) —
459-
// programmatic closes (`plusMenuRef.current?.close()`) bypass `onOpenChange`
460-
// and never call this. Remember the token so the caret's own selection-change
461-
// handler (fired by the same click) doesn't immediately reopen it.
462464
dismissedMentionStartRef.current = mentionRangeRef.current?.start ?? null
463465
atInsertPosRef.current = null
464466
mentionRangeRef.current = null
@@ -490,8 +492,6 @@ export function usePromptEditor({
490492
return
491493
}
492494

493-
// The user just dismissed the menu for this exact token (outside click /
494-
// Escape) and hasn't typed since — a caret move alone must not reopen it.
495495
if (active.start === dismissedMentionStartRef.current) {
496496
if (mentionRangeRef.current !== null) {
497497
mentionRangeRef.current = null
@@ -529,7 +529,6 @@ export function usePromptEditor({
529529
return
530530
}
531531

532-
// See the mirrored check in `syncMentionState`.
533532
if (active.start === dismissedSlashStartRef.current) {
534533
if (slashRangeRef.current !== null) {
535534
slashRangeRef.current = null
@@ -628,8 +627,6 @@ export function usePromptEditor({
628627
const caret = e.target.selectionStart ?? finalValue.length
629628
valueRef.current = finalValue
630629
setValueState(finalValue)
631-
// A keystroke is an active edit — always let it reopen a just-dismissed
632-
// menu, even for the same token the user clicked away from.
633630
dismissedMentionStartRef.current = null
634631
dismissedSlashStartRef.current = null
635632
syncMentionState(e.target, finalValue, caret)

0 commit comments

Comments
 (0)