Skip to content

Commit 8014a4c

Browse files
committed
Restore caret position and ensure proper focus handling on focus updates
- after entering a symbol and re-focusing into the prompt field, cursor is moved to the very beginning ├── apps │ └── editor │ └── src │ └── views │ ├── prompt │ │ ├── backend │ │ │ ├── message-handlers │ │ │ │ └── handle-hash-sign-quick-pick.ts │ │ │ └── prompt-view-provider.ts │ │ └── frontend │ │ ├── Main │ │ │ ├── Main.tsx │ │ │ └── MainView │ │ │ └── MainView.tsx │ │ ├── Prompt.tsx │ │ └── hooks │ │ └── use-prompt │ │ └── use-prompt.ts │ └── shared │ └── utils │ └── hash-sign-quick-pick │ ├── hash-sign-quick-pick.ts │ └── symbols │ └── index.ts ├── docs │ └── api-tools │ └── _category_.json └── packages └── ui └── src └── components └── editor └── common └── prompts └── PromptField ├── PromptField.tsx └── hooks └── use-handlers ├── handle-input-change.ts ├── handle-input-click.ts └── use-handlers.ts
1 parent eaac012 commit 8014a4c

1 file changed

Lines changed: 11 additions & 0 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/use-handlers.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ export const use_handlers = (
154154
props_ref.current.on_caret_position_change(caret_pos)
155155
params.set_caret_position(display_pos)
156156

157+
params.input_ref.current.focus({ preventScroll: true })
157158
set_caret_position_for_div(params.input_ref.current, display_pos)
158159
on_set()
159160
}
@@ -171,7 +172,17 @@ export const use_handlers = (
171172
if (params.input_ref.current) {
172173
requestAnimationFrame(() => {
173174
if (!params.input_ref.current) return
175+
const caret_to_restore =
176+
props_ref.current.caret_position_to_set ?? raw_caret_pos_ref.current
177+
174178
params.input_ref.current.focus({ preventScroll: true })
179+
180+
const display_pos = map_raw_pos_to_display_pos({
181+
raw_pos: caret_to_restore,
182+
raw_text: props_ref.current.value,
183+
context_file_paths: props_ref.current.selected_files ?? []
184+
})
185+
set_caret_position_for_div(params.input_ref.current, display_pos)
175186
})
176187
}
177188
}, [props.focus_key])

0 commit comments

Comments
 (0)