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

Bubble Menus should appear even with empty selections #3633

Closed
2 tasks done
dhovart opened this issue Jan 16, 2023 · 2 comments
Closed
2 tasks done

Bubble Menus should appear even with empty selections #3633

dhovart opened this issue Jan 16, 2023 · 2 comments
Labels
Info: Stale The issue or pullrequest has not been updated in a while and might be stale Type: Bug The issue or pullrequest is related to a bug

Comments

@dhovart
Copy link

dhovart commented Jan 16, 2023

What’s the bug you are facing?

My use case: I want to display a full link (with an edit button) in a bubble menu even when the selection is empty, that is, when I simply clicked on the link.

Which browser was this experienced in? Are any special extensions installed?

any

How can we reproduce the bug on our side?

Click on an item that triggers a bubble menu and see that it doesn't work with empty selections.

Can you provide a CodeSandbox?

No response

What did you expect to happen?

The bubble menu should show up.

Anything to add? (optional)

This was working before upgrading to beta.201 but this change broke it: cd5fd60#diff-30fdbcf134f53a22876c93ec1e76674f6afef97f9b6162c7eb39b00bb7eef953R167

Maybe this should actually be parametrizable?

Did you update your dependencies?

  • Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • Yes, I’m a sponsor. 💖
    Note; I'm not a sponsor but my company is.
@rumbcam
Copy link
Contributor

rumbcam commented Jan 31, 2023

This was partially fixed in commit e9d9d88

However it still didn't work as I would have expected while using @tiptap/vue-3.

After looking into it all today I figured out what's happening. I'm using Vue 3 and using the useEditor composition from @tiptap/vue-3.

The instance of Editor I get back from that is build on top of the Editor instance from @tiptap/core. One big difference though is that it returns a "reactiveState" object when trying to get editor.state. This object however only updates when the 'transaction' event is emitted, which happens after the bubble menu has its update function called.

the transaction event gets emitted in @tiptap/core in the dispatchTransaction, but it does so right after calling this.view.updateState(state). While prosemirror is running the update state it calls all of it's plugins update function and thus we get into bubble menu's update function which during that calls the shouldShow function. So when using useEditor and bubble menu at the time that you get into the shouldShow function there is a mismatch on state. editor.state !== editor.view.state. Thus calling editor.isActive('link') will not return the correct response because editor has not had it's state updated yet.

The work around I found is to import the function isActive directly from @tiptap/core instead of using the isActive method on editor. Then pass view.state as the first parameter and link as the second

import { isActive } from '@tiptap/core';

function shouldShow({ view }) {
    return isActive(view.state, 'link');
}

@github-actions
Copy link
Contributor

github-actions bot commented May 2, 2023

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the Info: Stale The issue or pullrequest has not been updated in a while and might be stale label May 2, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Info: Stale The issue or pullrequest has not been updated in a while and might be stale Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

No branches or pull requests

2 participants