Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit 86f36c1

Browse files
committed
fix: defining isPasteEvent by inputType, not by length of characters
1 parent ea3b55e commit 86f36c1

1 file changed

Lines changed: 30 additions & 22 deletions

File tree

src/components/ComboBox/ComboBox.tsx

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -221,46 +221,54 @@ export const ComboBox: React.FC<ComboBoxProps> = ({
221221
const handleChange = useCallback(
222222
(event: React.ChangeEvent<HTMLTextAreaElement>) => {
223223
const now = Date.now();
224-
console.log(
225-
"[DEBUG] handleChange called with value:",
226-
event.target.value,
227-
);
224+
const newValue = event.target.value;
225+
226+
const inputType = (event.nativeEvent as InputEvent).inputType;
227+
const isPasteEvent = [
228+
"insertFromPaste",
229+
"insertFromDrop",
230+
"insertFromYank",
231+
"insertReplacementText",
232+
].includes(inputType);
233+
234+
const timeSinceLastChange = now - lastPasteTimestamp;
235+
236+
console.log("[DEBUG] handleChange called with:", {
237+
value: newValue,
238+
inputType,
239+
previousValue: lastValue,
240+
timeSinceLastChange,
241+
});
228242
console.log("[DEBUG] previous value was:", lastValue);
229-
console.log(
230-
"[DEBUG] time since last paste:",
231-
now - lastPasteTimestamp,
232-
"ms",
233-
);
243+
console.log("[DEBUG] time since last paste:", timeSinceLastChange, "ms");
234244
console.log("[DEBUG] combobox state:", {
235245
open: state.open,
236246
activeValue: state.activeValue,
237247
activeId: state.activeId,
238248
replace: commands.replace,
239249
});
240-
const isPaste = event.target.value.length > value.length + 1;
241250

242-
if (isPaste) {
243-
if (now - lastPasteTimestamp < 100) {
244-
console.log("[DEBUG] Skipping duplicate paste event");
245-
return;
246-
}
247-
console.log(
248-
"[DEBUG] paste detected, closing combobox and canceling completion",
249-
);
251+
// Only apply paste throttling for large changes
252+
if (isPasteEvent && timeSinceLastChange < 100) {
253+
console.log("[DEBUG] Skipping duplicate paste event");
254+
return;
255+
}
256+
257+
if (isPasteEvent) {
258+
console.log("[DEBUG] Paste event detected, resetting combobox state");
250259
setLastPasteTimestamp(now);
251260
closeCombobox();
252261
requestCommandsCompletion.cancel();
253262
}
254-
255-
setLastValue(event.target.value);
256-
onChange(event.target.value);
263+
setLastValue(newValue);
264+
onChange(newValue);
257265
},
258266
[
259267
onChange,
260268
closeCombobox,
261269
state,
262270
commands.replace,
263-
value.length,
271+
// value,
264272
requestCommandsCompletion,
265273
lastPasteTimestamp,
266274
lastValue,

0 commit comments

Comments
 (0)