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

[Bug]: core/helpers/getMarksBetween is off by one when selection is empty #5401

Closed
1 task done
benkroeger opened this issue Jul 27, 2024 · 2 comments
Closed
1 task done
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug

Comments

@benkroeger
Copy link
Contributor

Affected Packages

core

Version(s)

2.5.7

Bug Description

Given that the marked text (MarkRange) is at the very beginning of your document (I believe what matters here is that it is at the beginning of a block node):

  • When placing an empty selection at the beginning of a MarkRange (position 1), the getMarksBetween helper does not find the mark although editor.isActive will return true.
  • When placing an empty selection between the first and second character (positon 2) of the MarkRange, both helpers (isActive and getMarksBetween) will find the mark. The mark found by getMarksBetween will even tell you that it's range starts at position 1

This behavior I could somewhat understand, since marks (even when inclusive) are not active before the text node.

But, given that there is some unmarked text before the marked text (MarkRange), the getMarksBetween helper doesn't find that mark even at the mapped position 2 (between the first and second character of the marked text). That is because getMarksBetween attempts to resolve the mark's range at from - 1. In this scenario, I'd have to move the empty selection to the third position of the MarkRange (between character 2 and three) - and only then would getMarksBetween find that mark.

Browser Used

Firefox

Code Example URL

https://codesandbox.io/p/sandbox/sharp-elgamal-w2yc26

Expected Behavior

getMarksBetween should return all active marks even for empty selections. Results should also be consistent with the isActive helper's results

Additional Context (Optional)

I wasn't sure how to put this into the sandbox - and in order to visualize where the carret / empty selection is positioned, I am using a command chain that actually sets the focus into the editor... this is a little annoying when playing around with the various positionings - but I didn't find a better way to show the issue.

I believe, the from - 1 implementation for empty selections in getMarksBetween was added while working on the autoLink feature of the Linkextension... to support some sort of lookup at the end of the link mark. That is why I am using the Link mark in the sandbox... but the issue is the same for any mark type.

Dependency Updates

  • Yes, I've updated all my dependencies.
@benkroeger benkroeger added Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug labels Jul 27, 2024
@github-project-automation github-project-automation bot moved this to Triage open in Tiptap Jul 27, 2024
@nperez0111
Copy link

Very good sleuthing @benkroeger, it looks like this bug has been around since that original implementation. I'm looking into why that from-1 is even there & I can't think of a good reason for it at the moment.

@nperez0111
Copy link

This is now released with v2.5.9

@github-project-automation github-project-automation bot moved this from Triage open to Done in Tiptap Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug
Projects
No open projects
Archived in project
Development

No branches or pull requests

2 participants