Skip to content

Commit e28a41d

Browse files
committed
Update backspace logic to automatically remove paired backticks when deleting inline code blocks
1 parent e149aae commit e28a41d

1 file changed

Lines changed: 23 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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,29 @@ export const create_handle_key_down = (
319319
return
320320
}
321321

322+
if (selection?.isCollapsed && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
323+
const raw_pos = refs.raw_caret_pos_ref.current
324+
const text_before = props.value.substring(0, raw_pos)
325+
const backticks_count = (text_before.match(/`/g) || []).length
326+
327+
if (
328+
backticks_count > 0 &&
329+
backticks_count % 2 == 0 &&
330+
text_before.endsWith('`')
331+
) {
332+
const start_pos = text_before.lastIndexOf('`', raw_pos - 2)
333+
if (start_pos != -1) {
334+
e.preventDefault()
335+
const new_value =
336+
props.value.substring(0, start_pos) + props.value.substring(raw_pos)
337+
338+
refs.has_modified_current_entry_ref.current = true
339+
utils.update_value(new_value, start_pos)
340+
return
341+
}
342+
}
343+
}
344+
322345
if (e.ctrlKey || e.metaKey) {
323346
e.preventDefault()
324347
const raw_pos = refs.raw_caret_pos_ref.current

0 commit comments

Comments
 (0)