Skip to content

Commit ac096a2

Browse files
committed
Prevent multiple prompt submissions by ignoring enter key repeat events
- it's been reported that holding e.g. 'enter' invokes on submit repeatedly └── packages └── ui └── src └── components └── editor └── common └── prompts ├── PromptField │ ├── PromptField.module.scss │ ├── PromptField.stories.tsx │ ├── PromptField.tsx │ ├── components │ │ ├── Tooltip.module.scss │ │ ├── Tooltip.tsx │ │ └── index.ts │ ├── hooks │ │ ├── use-drag-drop.ts │ │ ├── use-dropdown.ts │ │ ├── use-ghost-text.ts │ │ ├── use-handlers │ │ │ ├── handle-copy.ts │ │ │ ├── handle-cut.ts │ │ │ ├── handle-input-change.ts │ │ │ ├── handle-input-click.ts │ │ │ ├── handle-key-down.ts │ │ │ ├── handle-paste.ts │ │ │ ├── handle-submit.ts │ │ │ ├── index.ts │ │ │ ├── types.ts │ │ │ ├── use-handlers.ts │ │ │ └── utils.ts │ │ └── use-keyboard-shortcuts.ts │ └── index.ts ├── Template │ ├── Template.module.scss │ ├── Template.tsx │ └── index.ts └── shared └── symbols ├── caret.ts ├── get-highlighted-text.tsx ├── index.ts ├── position-mapping.ts ├── prompt-symbols.module.scss ├── reconstruct-raw-value.ts └── use-symbol-deletion.ts
1 parent 123fecc commit ac096a2

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • packages/ui/src/components/editor/common/prompts/PromptField/hooks/use-handlers

‎packages/ui/src/components/editor/common/prompts/PromptField/hooks/use-handlers/handle-key-down.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,14 @@ export const create_handle_key_down = (
405405
const handle_enter_key = (e: React.KeyboardEvent<HTMLDivElement>) => {
406406
if (props.send_with_shift_enter && e.shiftKey) {
407407
e.preventDefault()
408-
handle_submit(e)
408+
if (!e.repeat) {
409+
handle_submit(e)
410+
}
409411
} else if (!props.send_with_shift_enter && !e.shiftKey) {
410412
e.preventDefault()
411-
handle_submit(e)
413+
if (!e.repeat) {
414+
handle_submit(e)
415+
}
412416
} else {
413417
e.preventDefault()
414418
const selection = window.getSelection()

0 commit comments

Comments
 (0)