-
Notifications
You must be signed in to change notification settings - Fork 2
Fix: Preventing frequent double-pastes from IDE in Combobox #344
Conversation
999bedb to
ae5a0d5
Compare
src/components/ComboBox/ComboBox.tsx
Outdated
| onKeyUp: onKeyUp, | ||
| onKeyDown: onKeyDown, | ||
| onSubmit: onSubmit, | ||
| onPaste: handlePaste, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Odd, onPaste isn't passed to the child component :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved
src/components/ComboBox/ComboBox.tsx
Outdated
| activeId: state.activeId, | ||
| replace: commands.replace, | ||
| }); | ||
| const isPaste = event.target.value.length > value.length + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some characters have a length of more than 1
"🍆".lengthThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can compare in this case length of string itself, using Array.from(value).length
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made a fix by getting nativeEvent.inputType of event object in onChange handler, so then I can simply define if the event was insertFromPaste, or any of other input types which should be treated as paste event:
const isPasteEvent = [
"insertFromPaste",
"insertFromDrop ",
"insertFromYank",
"insertReplacementText"
].includes(inputType)
MarcMcIntosh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work, I think this is re-occuring issue with vsode/
I think it would be easier to save event.nativeEvent.timeStamp on the paste events then use the difference between the timeStamp in the state and the event handleChange to decide to return early :)
Also remove console.log
…sole.log statements
Fix: Preventing frequent double-pastes from IDE in Combobox
Description
Type of change
How to Test
Checklist