Skip to content

Commit 8dd86aa

Browse files
committed
Enable backspace to delete entire symbol tokens in the prompt editor
- backspace at the end of 'pasted X tokens' doesn't remove the whole symbol
1 parent 7f0eac2 commit 8dd86aa

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

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

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,27 @@ export const create_handle_key_down = (
326326

327327
if (selection?.isCollapsed && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
328328
const raw_pos = refs.raw_caret_pos_ref.current
329+
330+
const symbol_ranges = get_symbol_ranges({
331+
text: props.value,
332+
selected_files: props.selected_files ?? []
333+
})
334+
335+
const symbol_at_caret = symbol_ranges.find(
336+
(range) => range.end === raw_pos
337+
)
338+
339+
if (symbol_at_caret) {
340+
e.preventDefault()
341+
const new_value =
342+
props.value.substring(0, symbol_at_caret.start) +
343+
props.value.substring(raw_pos)
344+
345+
refs.has_modified_current_entry_ref.current = true
346+
utils.update_value(new_value, symbol_at_caret.start)
347+
return
348+
}
349+
329350
const text_before = props.value.substring(0, raw_pos)
330351
const backticks_count = (text_before.match(/`/g) || []).length
331352

0 commit comments

Comments
 (0)