Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.getSelection() returns only previously selected elements. #157

Closed
jmbds opened this issue Jan 24, 2022 · 3 comments
Closed

.getSelection() returns only previously selected elements. #157

jmbds opened this issue Jan 24, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@jmbds
Copy link

jmbds commented Jan 24, 2022

What is the problem?

As you described in #136, the way to get the selected and stored elements on "stop" event is calling .getSelection(). However, it doesn't seem to work when the selection is made by click and drag (selection by click works as expected).

What is the current behavior?

<-- What happens in your situation -->

Calling .getSelection() on "stop" event after a drag selection returns only previously selected elements.

Please provide the steps to reproduce and create a CodeSandbox.

https://codesandbox.io/s/viselect-svg-example-forked-99zp2?file=/src/main.js

What is the expected behavior?

Calling .getSelection() on "stop" event should return both selected and stored elements.

Your environment:

Toolset (e.g. webpack, vite, vue-cli...):  webpack
Version (@viselect/<insert package>): @viselect/3.0.0-beta.13
Browser:  Chrome / Firefox
OS:  Windows 10
@jmbds jmbds added the unconfirmed Problem is not confirmed yet label Jan 24, 2022
@isepise
Copy link

isepise commented Mar 10, 2022

Strange. If i get the selection after a delay.. its ok - Here i output the selection count immediately and after delay:

.on("stop", () => {
    console.log("sel now: " + selection.getSelection().length);
    window.setTimeout(() => {
      console.log("sel delayed: " + selection.getSelection().length);
    }, 1000);
  }

output when i lasso select 4 items:
sel now: 0 
sel delayed: 4 

Fix: Maybe just move the "stop" event trigger to the end of _onTapStop:

_onTapStop(evt: MouseEvent | TouchEvent | null, silent: boolean): void {
  ...
  if (!_singleClick && !silent) {
    this._emitEvent('stop', evt);
  }
}

Im using @viselect/vanilla

@luckylooke
Copy link

It is reproducable even in official example.... where on stop event console.log returns not all selected but only selected in previous selections, without last selected group.
Screenshot 2022-05-06 at 06 47 56
https://codesandbox.io/s/viselectvanilla-kt332?file=/src/main.ts

@arleybls
Copy link

arleybls commented Jul 7, 2022

Looks like store.stored[] is filled by a promise which is resolved only after the event is emitted.

@simonwep simonwep added bug Something isn't working and removed unconfirmed Problem is not confirmed yet labels Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants