Skip to content

Commit 0f27b03

Browse files
committed
Refactor ghost text logic to correctly utilize the is_focused state to prevent ghost text from appearing when the input field is not focused
1 parent 1d93379 commit 0f27b03

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
8383
const [show_at_sign_tooltip, set_show_at_sign_tooltip] = useState(false)
8484
const [show_submit_tooltip, set_show_submit_tooltip] = useState(false)
8585
const [is_text_selecting, set_is_text_selecting] = useState(false)
86+
const [is_focused, set_is_focused] = useState(false)
8687
const is_narrow_viewport = use_is_narrow_viewport(268)
8788
const {
8889
is_dropdown_open,
@@ -233,7 +234,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
233234
}, [props.currently_open_file_text])
234235

235236
useEffect(() => {
236-
if (!input_ref.current) {
237+
if (!input_ref.current || !is_focused) {
237238
set_ghost_text('')
238239
return
239240
}
@@ -294,7 +295,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
294295
}
295296

296297
set_ghost_text('')
297-
}, [props.value, caret_position, identifiers])
298+
}, [props.value, caret_position, identifiers, is_focused])
298299

299300
useEffect(() => {
300301
if (input_ref.current && input_ref.current.innerHTML !== highlighted_html) {
@@ -489,6 +490,8 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
489490
onDrop={handle_drop}
490491
onDragOver={handle_drag_over}
491492
onDragEnd={handle_drag_end}
493+
onFocus={() => set_is_focused(true)}
494+
onBlur={() => set_is_focused(false)}
492495
className={cn(styles.input, {
493496
[styles['input-with-file-match-hint']]: show_file_match_hint,
494497
[styles['input--empty']]: !props.value

0 commit comments

Comments
 (0)