Skip to content

Commit 136810e

Browse files
committed
Refactor chat history navigation to correctly restore the caret position after updating the input value
1 parent 5ce6e82 commit 136810e

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,20 +362,30 @@ export const use_handlers = (
362362

363363
e.preventDefault()
364364

365+
const update_and_set_caret = (value: string) => {
366+
props.on_change(value)
367+
set_caret_position_after_change(
368+
input_ref,
369+
value.length,
370+
value,
371+
props.context_file_paths ?? []
372+
)
373+
}
374+
365375
if (e.key === 'ArrowUp') {
366376
if (history_index < active_history.length - 1) {
367377
const new_index = history_index + 1
368378
set_history_index(new_index)
369-
props.on_change(active_history[new_index])
379+
update_and_set_caret(active_history[new_index])
370380
}
371381
} else if (e.key === 'ArrowDown') {
372382
if (history_index > 0) {
373383
const new_index = history_index - 1
374384
set_history_index(new_index)
375-
props.on_change(active_history[new_index])
385+
update_and_set_caret(active_history[new_index])
376386
} else if (history_index === 0) {
377387
set_history_index(-1)
378-
props.on_change('')
388+
update_and_set_caret('')
379389
}
380390
}
381391
}

‎packages/vscode/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@
591591
"type": "string",
592592
"scope": "resource",
593593
"description": "System instructions for the Edit Context API tool.",
594-
"default": "You're a helpful coding assistant. Don't introduce redundant comments in code."
594+
"default": "You're a helpful coding assistant. Don't explain changes in inline comments."
595595
},
596596
"codeWebChat.chatPresetsForAskAboutContext": {
597597
"type": "array",

‎packages/vscode/src/views/panel/backend/message-handlers/handle-at-sign-quick-pick/handle-at-sign-quick-pick.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const at_sign_quick_pick = async (params: {
6868
})
6969

7070
if (filtered_paths.length == 1) {
71-
return `\`${filtered_paths[0]}\` `
71+
return `\`${filtered_paths[0]}\``
7272
} else if (filtered_paths.length > 1) {
7373
const filtered_paths_set = new Set(filtered_paths)
7474
quick_pick_items_to_show = all_quick_pick_items.filter((item) =>
@@ -94,7 +94,7 @@ const at_sign_quick_pick = async (params: {
9494
)
9595

9696
if (selected_path_item) {
97-
return `\`${selected_path_item.fullPath}\` `
97+
return `\`${selected_path_item.fullPath}\``
9898
}
9999
return
100100
}

0 commit comments

Comments
 (0)