1- /* eslint-disable no-console */
21import React , { useCallback , useEffect , useMemo } from "react" ;
32import { useComboboxStore , Combobox } from "@ariakit/react" ;
43import { getAnchorRect , replaceRange } from "./utils" ;
@@ -38,7 +37,6 @@ export const ComboBox: React.FC<ComboBoxProps> = ({
3837 const ref = React . useRef < HTMLTextAreaElement > ( null ) ;
3938 const [ moveCursorTo , setMoveCursorTo ] = React . useState < number | null > ( null ) ;
4039 const [ lastPasteTimestamp , setLastPasteTimestamp ] = React . useState ( 0 ) ;
41- const [ lastValue , setLastValue ] = React . useState ( "" ) ;
4240 const shiftEnterToSubmit = useAppSelector ( selectSubmitOption ) ;
4341 const { escapeKeyPressed } = useEventsBusForIDE ( ) ;
4442
@@ -92,19 +90,6 @@ export const ComboBox: React.FC<ComboBoxProps> = ({
9290 const handleReplace = useCallback (
9391 ( input : string ) => {
9492 if ( ! ref . current ) return ;
95- console . log ( "[DEBUG] handleReplace called with:" , {
96- input,
97- currentValue : ref . current . value ,
98- replaceRange : commands . replace ,
99- timeSinceLastPaste : Date . now ( ) - lastPasteTimestamp ,
100- } ) ;
101-
102- // If this is happening right after a paste, skip it
103- if ( Date . now ( ) - lastPasteTimestamp < 100 ) {
104- console . log ( "[DEBUG] Skipping handleReplace due to recent paste" ) ;
105- return ;
106- }
107-
10893 const nextValue = replaceRange (
10994 ref . current . value ,
11095 commands . replace ,
@@ -115,13 +100,7 @@ export const ComboBox: React.FC<ComboBoxProps> = ({
115100 onChange ( nextValue ) ;
116101 setMoveCursorTo ( commands . replace [ 0 ] + input . length ) ;
117102 } ,
118- [
119- closeCombobox ,
120- commands . replace ,
121- onChange ,
122- requestCommandsCompletion ,
123- lastPasteTimestamp ,
124- ] ,
103+ [ closeCombobox , commands . replace , onChange , requestCommandsCompletion ] ,
125104 ) ;
126105
127106 const onKeyDown = useCallback (
@@ -220,59 +199,30 @@ export const ComboBox: React.FC<ComboBoxProps> = ({
220199
221200 const handleChange = useCallback (
222201 ( event : React . ChangeEvent < HTMLTextAreaElement > ) => {
223- const now = Date . now ( ) ;
224202 const newValue = event . target . value ;
203+ const nativeEvent = event . nativeEvent as InputEvent ;
204+ const currentEventTimestamp = nativeEvent . timeStamp ;
225205
226- const inputType = ( event . nativeEvent as InputEvent ) . inputType ;
206+ const inputType = nativeEvent . inputType ;
227207 const isPasteEvent = [
228208 "insertFromPaste" ,
229209 "insertFromDrop" ,
230210 "insertFromYank" ,
231211 "insertReplacementText" ,
232212 ] . includes ( inputType ) ;
233213
234- const timeSinceLastChange = now - lastPasteTimestamp ;
235-
236- console . log ( "[DEBUG] handleChange called with:" , {
237- value : newValue ,
238- inputType,
239- previousValue : lastValue ,
240- timeSinceLastChange,
241- } ) ;
242- console . log ( "[DEBUG] previous value was:" , lastValue ) ;
243- console . log ( "[DEBUG] time since last paste:" , timeSinceLastChange , "ms" ) ;
244- console . log ( "[DEBUG] combobox state:" , {
245- open : state . open ,
246- activeValue : state . activeValue ,
247- activeId : state . activeId ,
248- replace : commands . replace ,
249- } ) ;
250-
251- // Only apply paste throttling for large changes
252- if ( isPasteEvent && timeSinceLastChange < 100 ) {
253- console . log ( "[DEBUG] Skipping duplicate paste event" ) ;
254- return ;
255- }
214+ const timeSinceLastChange = currentEventTimestamp - lastPasteTimestamp ;
215+
216+ if ( isPasteEvent && timeSinceLastChange < 100 ) return ;
256217
257218 if ( isPasteEvent ) {
258- console . log ( "[DEBUG] Paste event detected, resetting combobox state" ) ;
259- setLastPasteTimestamp ( now ) ;
219+ setLastPasteTimestamp ( currentEventTimestamp ) ;
260220 closeCombobox ( ) ;
261221 requestCommandsCompletion . cancel ( ) ;
262222 }
263- setLastValue ( newValue ) ;
264223 onChange ( newValue ) ;
265224 } ,
266- [
267- onChange ,
268- closeCombobox ,
269- state ,
270- commands . replace ,
271- // value,
272- requestCommandsCompletion ,
273- lastPasteTimestamp ,
274- lastValue ,
275- ] ,
225+ [ onChange , closeCombobox , requestCommandsCompletion , lastPasteTimestamp ] ,
276226 ) ;
277227
278228 const onItemClick = useCallback (
0 commit comments