Skip to content

Commit 50a533e

Browse files
committed
Implement word-wise deletion Ctrl/Cmd + Backspace for the prompt input field
1 parent dca44ee commit 50a533e

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ export const use_handlers = (
722722
}
723723

724724
const handle_key_down = (e: React.KeyboardEvent<HTMLDivElement>) => {
725-
const { key, shiftKey } = e
725+
const { key, shiftKey, altKey } = e
726726

727727
// Handle arrow-right when ghost text is present
728728
if (key === 'ArrowRight' && ghost_text && !shiftKey) {
@@ -819,6 +819,37 @@ export const use_handlers = (
819819
}
820820

821821
if (key == 'Backspace') {
822+
if (e.ctrlKey || e.metaKey) {
823+
e.preventDefault()
824+
const raw_pos = raw_caret_pos_ref.current
825+
if (raw_pos === 0) return
826+
827+
const value = props.value
828+
let i = raw_pos - 1
829+
830+
// First, skip any whitespace characters before the cursor.
831+
while (i >= 0 && /\s/.test(value[i])) {
832+
i--
833+
}
834+
835+
// Then, delete the word or symbol group before that.
836+
if (i >= 0) {
837+
const is_word_char = /\w/.test(value[i])
838+
while (i >= 0) {
839+
const current_is_word = /\w/.test(value[i])
840+
if (/\s/.test(value[i]) || current_is_word !== is_word_char) {
841+
break
842+
}
843+
i--
844+
}
845+
}
846+
847+
const new_start_pos = i + 1
848+
const new_value =
849+
value.substring(0, new_start_pos) + value.substring(raw_pos)
850+
update_value(new_value, new_start_pos)
851+
return
852+
}
822853
handle_backspace_key(e)
823854
return
824855
}

‎packages/vscode/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gemini-coder",
33
"displayName": "Code Web Chat",
44
"description": "CWC is a free AI coding assistant without agents",
5-
"version": "1.588.0",
5+
"version": "1.589.0",
66
"scripts": {
77
"build": "npx vsce package --no-dependencies",
88
"vscode:prepublish": "rimraf out && npm run compile",

0 commit comments

Comments
 (0)