Skip to content

Commit bf41371

Browse files
committed
Prevent automatic chat input focus and selection during mode and prompt type switching
- briefly, once warning gets removed, text is being selected. The selection is temporary, quickly removed. The brief selection should no take place. - when mode changes, should only focus on prompt field, without text selection. Continue text selection when prompt type changes.
1 parent fb2399b commit bf41371

3 files changed

Lines changed: 26 additions & 20 deletions

File tree

‎apps/editor/src/views/panel/frontend/Panel.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export const Panel = () => {
5555
web_prompt_type,
5656
api_prompt_type,
5757
chat_input_focus_key,
58+
set_chat_input_focus_key,
5859
chat_input_focus_and_select_key,
59-
set_chat_input_focus_and_select_key,
6060
context_size_warning_threshold,
6161
can_undo,
6262
web_configurations_collapsed,
@@ -440,15 +440,15 @@ export const Panel = () => {
440440
set_active_view('main')
441441
set_main_view_scroll_reset_key((k) => k + 1)
442442
handle_mode_change(MODE.WEB)
443-
handle_web_prompt_type_change('edit-files')
444-
set_chat_input_focus_and_select_key((k) => k + 1)
443+
handle_web_prompt_type_change('edit-files', true)
444+
set_chat_input_focus_key((k) => k + 1)
445445
}}
446446
on_api_calls_click={() => {
447447
set_active_view('main')
448448
set_main_view_scroll_reset_key((k) => k + 1)
449449
handle_mode_change(MODE.API)
450-
handle_api_prompt_type_change('edit-files')
451-
set_chat_input_focus_and_select_key((k) => k + 1)
450+
handle_api_prompt_type_change('edit-files', true)
451+
set_chat_input_focus_key((k) => k + 1)
452452
}}
453453
version={version}
454454
checkpoints={checkpoints}

‎apps/editor/src/views/panel/frontend/hooks/panel/use-panel.ts‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,29 @@ export const use_panel = (vscode: any) => {
184184
return () => window.removeEventListener('message', handle_message)
185185
}, [])
186186

187-
const handle_web_prompt_type_change = (prompt_type: WebPromptType) => {
187+
const handle_web_prompt_type_change = (
188+
prompt_type: WebPromptType,
189+
prevent_selection?: boolean
190+
) => {
188191
set_web_mode(prompt_type)
189-
set_chat_input_focus_and_select_key((k) => k + 1)
192+
if (!prevent_selection) {
193+
set_chat_input_focus_and_select_key((k) => k + 1)
194+
}
190195
set_main_view_scroll_reset_key((k) => k + 1)
191196
post_message(vscode, {
192197
command: 'SAVE_WEB_PROMPT_TYPE',
193198
prompt_type: prompt_type
194199
})
195200
}
196201

197-
const handle_api_prompt_type_change = (prompt_type: ApiPromptType) => {
202+
const handle_api_prompt_type_change = (
203+
prompt_type: ApiPromptType,
204+
prevent_selection?: boolean
205+
) => {
198206
set_api_mode(prompt_type)
199-
set_chat_input_focus_and_select_key((k) => k + 1)
207+
if (!prevent_selection) {
208+
set_chat_input_focus_and_select_key((k) => k + 1)
209+
}
200210
set_main_view_scroll_reset_key((k) => k + 1)
201211
post_message(vscode, {
202212
command: 'SAVE_API_PROMPT_TYPE',
@@ -213,10 +223,10 @@ export const use_panel = (vscode: any) => {
213223
web_prompt_type == 'code-at-cursor' ||
214224
web_prompt_type == 'find-relevant-files'
215225
) {
216-
handle_api_prompt_type_change(web_prompt_type)
226+
handle_api_prompt_type_change(web_prompt_type, true)
217227
}
218228
} else if (new_mode == MODE.WEB && api_prompt_type) {
219-
handle_web_prompt_type_change(api_prompt_type)
229+
handle_web_prompt_type_change(api_prompt_type, true)
220230
}
221231

222232
set_mode(new_mode)
@@ -273,8 +283,8 @@ export const use_panel = (vscode: any) => {
273283
web_prompt_type,
274284
api_prompt_type,
275285
chat_input_focus_key,
286+
set_chat_input_focus_key,
276287
chat_input_focus_and_select_key,
277-
set_chat_input_focus_and_select_key,
278288
context_size_warning_threshold,
279289
can_undo,
280290
web_configurations_collapsed,

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,16 @@ export const use_handlers = (
155155
])
156156

157157
useEffect(() => {
158-
if (params.input_ref.current && !props.warning) {
158+
if (params.input_ref.current && !props_ref.current.warning) {
159159
requestAnimationFrame(() => {
160160
if (!params.input_ref.current) return
161161
params.input_ref.current.focus({ preventScroll: true })
162162
})
163163
}
164-
}, [props.focus_key, props.warning])
164+
}, [props.focus_key])
165165

166166
useEffect(() => {
167-
if (params.input_ref.current && !props.warning) {
167+
if (params.input_ref.current && !props_ref.current.warning) {
168168
requestAnimationFrame(() => {
169169
if (!params.input_ref.current) return
170170
params.input_ref.current.focus({ preventScroll: true })
@@ -180,11 +180,7 @@ export const use_handlers = (
180180
}
181181
})
182182
}
183-
}, [
184-
props.focus_and_select_key,
185-
props.warning,
186-
props.prompt_type
187-
])
183+
}, [props.focus_and_select_key])
188184

189185
const update_value = (new_value: string, caret_pos?: number) => {
190186
if (new_value === props.value) return

0 commit comments

Comments
 (0)