Skip to content

Commit 0c35efd

Browse files
committed
Collapse selection range for empty prompt inputs and remove focus_key effect
1 parent 0208539 commit 0c35efd

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎packages/ui/src/components/editor/panel/PromptField/PromptField.tsx‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,6 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
250250
props.context_file_paths
251251
])
252252

253-
useEffect(() => {
254-
if (input_ref.current) {
255-
input_ref.current.focus()
256-
}
257-
}, [props.focus_key])
258-
259253
useEffect(() => {
260254
if (input_ref.current) {
261255
const handle_click_outside = (event: MouseEvent) => {
@@ -426,6 +420,9 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
426420
if (selection) {
427421
const range = document.createRange()
428422
range.selectNodeContents(input_ref.current)
423+
if (!props.value) {
424+
range.collapse(true)
425+
}
429426
selection.removeAllRanges()
430427
selection.addRange(range)
431428
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@ export const use_handlers = (
356356
if (selection) {
357357
const range = document.createRange()
358358
range.selectNodeContents(params.input_ref.current)
359+
if (!params.input_ref.current.textContent) {
360+
range.collapse(true)
361+
}
359362
selection.removeAllRanges()
360363
selection.addRange(range)
361364
}

0 commit comments

Comments
 (0)