@@ -16,10 +16,6 @@ import {
1616 get_caret_position_from_div ,
1717 set_caret_position_for_div
1818} from './utils/caret'
19- import {
20- map_display_pos_to_raw_pos ,
21- map_raw_pos_to_display_pos
22- } from './utils/position-mapping'
2319import { Tooltip } from './components'
2420import { ApiPromptType , WebPromptType } from '@shared/types/prompt-types'
2521
@@ -85,7 +81,6 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
8581 useState ( false )
8682 const [ hovered_edit_format , set_hovered_edit_format ] =
8783 useState < EditFormat | null > ( null )
88-
8984 const [ prune_instructions , set_prune_instructions ] = useState (
9085 props . prune_context_instructions_prefix
9186 )
@@ -106,6 +101,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
106101 is_invocation_dropdown_open,
107102 on_toggle_invocation_dropdown : toggle_invocation_dropdown
108103 } )
104+
109105 const {
110106 is_dropdown_open,
111107 toggle_dropdown,
@@ -114,16 +110,18 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
114110 handle_copy_click,
115111 handle_select_click
116112 } = use_dropdown ( props )
113+
117114 const invocation_dropdown_ref = useRef < HTMLDivElement > ( null )
115+
118116 const { ghost_text, handle_accept_ghost_text } = use_ghost_text ( {
119117 value : props . value ,
120118 input_ref,
121119 is_focused : is_focused && should_show_ghost_text ,
122120 currently_open_file_text : props . currently_open_file_text ,
123121 caret_position
124122 } )
123+
125124 const {
126- handle_clear,
127125 handle_input_change,
128126 handle_submit,
129127 handle_key_down,
@@ -132,7 +130,14 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
132130 handle_cut,
133131 handle_paste,
134132 handle_input_click
135- } = use_handlers ( props , input_ref , ghost_text , handle_accept_ghost_text )
133+ } = use_handlers (
134+ props ,
135+ input_ref ,
136+ ghost_text ,
137+ handle_accept_ghost_text ,
138+ set_caret_position
139+ )
140+
136141 const { handle_drag_start, handle_drag_over, handle_drop, handle_drag_end } =
137142 use_drag_drop ( {
138143 input_ref,
@@ -199,28 +204,6 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
199204 }
200205 } , [ highlighted_html ] )
201206
202- useEffect ( ( ) => {
203- if ( input_ref . current ) {
204- if (
205- props . caret_position_to_set !== undefined &&
206- props . on_caret_position_set
207- ) {
208- const display_pos = map_raw_pos_to_display_pos (
209- props . caret_position_to_set ,
210- props . value ,
211- props . context_file_paths ?? [ ]
212- )
213- set_caret_position_for_div ( input_ref . current , display_pos )
214- props . on_caret_position_set ( )
215- }
216- }
217- } , [
218- props . caret_position_to_set ,
219- props . on_caret_position_set ,
220- props . value ,
221- props . context_file_paths
222- ] )
223-
224207 useEffect ( ( ) => {
225208 if ( input_ref . current ) {
226209 input_ref . current . focus ( )
@@ -247,37 +230,6 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
247230 }
248231 } , [ is_invocation_dropdown_open ] )
249232
250- useEffect ( ( ) => {
251- if ( input_ref . current ) {
252- input_ref . current . focus ( )
253- const selection = window . getSelection ( )
254- if ( selection ) {
255- const range = document . createRange ( )
256- range . selectNodeContents ( input_ref . current )
257- selection . removeAllRanges ( )
258- selection . addRange ( range )
259- }
260- }
261- } , [ props . focus_and_select_key ] )
262-
263- useEffect ( ( ) => {
264- const on_selection_change = ( ) => {
265- if ( document . activeElement === input_ref . current && input_ref . current ) {
266- const pos = get_caret_position_from_div ( input_ref . current )
267- set_caret_position ( pos )
268- const raw_pos = map_display_pos_to_raw_pos (
269- pos ,
270- props . value ,
271- props . context_file_paths ?? [ ]
272- )
273- props . on_caret_position_change ( raw_pos )
274- }
275- }
276- document . addEventListener ( 'selectionchange' , on_selection_change )
277- return ( ) =>
278- document . removeEventListener ( 'selectionchange' , on_selection_change )
279- } , [ props . on_caret_position_change , props . value , props . context_file_paths ] )
280-
281233 const placeholder = useMemo ( ( ) => {
282234 if ( props . prompt_type == 'code-at-cursor' ) {
283235 if ( props . chat_history . length > 0 && is_history_enabled ) {
0 commit comments