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

Conversation

@alashchev17
Copy link
Member

Fix: Preventing frequent double-pastes from IDE in Combobox

Description

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (no functional changes, only code improvements)
  • Documentation update

How to Test

  • Step 1: Type @file+Space
  • Step 2: Paste path to file
  • Step 3: Path should be inserted once

Checklist

  • My code follows the code style of this project.
  • I have performed a self-review of my code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • Any dependent changes have been merged and published in downstream modules.
  • I have updated the documentation where necessary.

@alashchev17 alashchev17 self-assigned this Feb 13, 2025
@alashchev17 alashchev17 force-pushed the fix/duplicative-paths branch from 999bedb to ae5a0d5 Compare February 13, 2025 12:43
@alashchev17 alashchev17 marked this pull request as ready for review February 13, 2025 12:48
onKeyUp: onKeyUp,
onKeyDown: onKeyDown,
onSubmit: onSubmit,
onPaste: handlePaste,
Copy link
Contributor

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 :/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

activeId: state.activeId,
replace: commands.replace,
});
const isPaste = event.target.value.length > value.length + 1;
Copy link
Contributor

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

"🍆".length

Copy link
Member Author

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

Copy link
Member Author

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)

Copy link
Contributor

@MarcMcIntosh MarcMcIntosh left a 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

@alashchev17 alashchev17 merged commit fd15fd0 into alpha Feb 18, 2025
2 checks passed
@alashchev17 alashchev17 deleted the fix/duplicative-paths branch February 18, 2025 12:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants