Skip to content

Commit 11818e4

Browse files
committed
Remove unnecessary setTimeout calls when triggering @ and # sign handlers in the prompt field input change handler
1 parent 6808b6e commit 11818e4

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎packages/ui/src/components/editor/panel/PromptField/hooks/use-handlers.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,16 @@ export const use_handlers = (
437437
set_history_index(-1)
438438

439439
if (char_before_caret == '@') {
440-
setTimeout(() => {
441-
props.on_at_sign_click()
442-
}, 150)
440+
const is_at_start = caret_position == 1
441+
const is_after_space =
442+
caret_position > 1 &&
443+
/\s/.test(new_display_value.charAt(caret_position - 2))
444+
445+
if (is_at_start || is_after_space) {
446+
props.on_at_sign_click()
447+
}
443448
} else if (char_before_caret == '#') {
444-
setTimeout(() => {
445449
props.on_hash_sign_click()
446-
}, 150)
447450
}
448451
}
449452

0 commit comments

Comments
 (0)