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

selection event should trigger when the element changes node type #1156

Closed
oodavid opened this issue Jan 28, 2021 · 2 comments
Closed

selection event should trigger when the element changes node type #1156

oodavid opened this issue Jan 28, 2021 · 2 comments

Comments

@oodavid
Copy link

oodavid commented Jan 28, 2021

What happens?
I expect the selection event to be triggered when the focussed element changes type. It doesn't

How can others reproduce the issue?

  1. Add a selection listener to the document
  2. Analyse the focussed node (ie: paragraph)
  3. Change the node-type (ie: heading) editor.chain().focus().toggleHeading({ level: 1 }).run()
  4. The selection event does not fire, even though we've now focussed a different element
const onSelection = () => {
    var resolvedPos = editor.state.selection.$head;
    console.log(resolvedPos.node(resolvedPos.depth).type.name);
}
editor.on('selection', onSelection);

What behavior did you expect?
Since the node changes, I expected the selection event to trigger.

Do you have a screenshot?
tiptap-onselection

What’s your environment?

  • MacOS
  • Chrome
  • Mobile

What else?
I can use the update event instead, but that feels like overkill for my requirement.

@oodavid oodavid changed the title onSelect should trigger when the element changes node type selection event should trigger when the element changes node type Jan 28, 2021
@hanspagel
Copy link
Contributor

Thanks, but that’s still the same selection, so I won’t expect the event to be triggered. As you said, you'd probably use the onUpdate event to listen for updates. ✌️

@oodavid
Copy link
Author

oodavid commented Jan 28, 2021

True... ish?

IMO - the selection has changed in that editor.state.selection is different, especially WRT $head.

If I tap an arrow key to move my cursor, the event fires, which makes sense since the resolvedPos changes. I think the same is true here.

I guess this is an upstream issue anyhow...

@hanspagel hanspagel transferred this issue from ueberdosis/tiptap-next Apr 21, 2021
BrianHung added a commit to BrianHung/tiptap that referenced this issue Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants