[Bug]: core/helpers/getMarksBetween is off by one when selection is empty #5401
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
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):
getMarksBetween
helper does not find the mark althougheditor.isActive
will return true.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 becausegetMarksBetween
attempts to resolve the mark's range atfrom - 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 wouldgetMarksBetween
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 theisActive
helper's resultsAdditional 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 ingetMarksBetween
was added while working on theautoLink
feature of theLink
extension... to support some sort of lookup at the end of the link mark. That is why I am using theLink
mark in the sandbox... but the issue is the same for any mark type.Dependency Updates
The text was updated successfully, but these errors were encountered: