Fix: Preventing frequent double-pastes from IDE in Combobox#344
Fix: Preventing frequent double-pastes from IDE in Combobox#344alashchev17 merged 7 commits intoalphafrom
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.
Odd, onPaste isn't passed to the child component :/
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.
some characters have a length of more than 1
"🍆".lengthThere was a problem hiding this comment.
We can compare in this case length of string itself, using Array.from(value).length
There was a problem hiding this comment.
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.
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