From 392f8a20b3fa08e3875053719683dc885cb138e0 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Fri, 3 May 2019 19:06:18 +0200 Subject: [PATCH 1/3] Revert "fix eslint warning" This reverts commit c4e0bbeaf41ce8bb8f56ef1e4060c6a551982c21. --- packages/tiptap-utils/src/utils/getMarkRange.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tiptap-utils/src/utils/getMarkRange.js b/packages/tiptap-utils/src/utils/getMarkRange.js index ce563ab7..b7026156 100644 --- a/packages/tiptap-utils/src/utils/getMarkRange.js +++ b/packages/tiptap-utils/src/utils/getMarkRange.js @@ -22,7 +22,7 @@ export default function ($pos = null, type = null) { startPos -= $pos.parent.child(startIndex).nodeSize } - // const endIndex = $pos.indexAfter() + const endIndex = $pos.indexAfter() const endPos = startPos + start.node.nodeSize // disable for now. see #156 From d057d5d7d9490b41220fdbf703c57eb7e4b89833 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Fri, 3 May 2019 19:06:19 +0200 Subject: [PATCH 2/3] Revert "fix a bug for getting mark range, fix #156" This reverts commit 0cf905abb9f9546fb379b7f539428d9ff655fa02. --- packages/tiptap-utils/src/utils/getMarkRange.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/tiptap-utils/src/utils/getMarkRange.js b/packages/tiptap-utils/src/utils/getMarkRange.js index b7026156..115f8b6b 100644 --- a/packages/tiptap-utils/src/utils/getMarkRange.js +++ b/packages/tiptap-utils/src/utils/getMarkRange.js @@ -22,14 +22,12 @@ export default function ($pos = null, type = null) { startPos -= $pos.parent.child(startIndex).nodeSize } - const endIndex = $pos.indexAfter() - const endPos = startPos + start.node.nodeSize - - // disable for now. see #156 - // while (endIndex < $pos.parent.childCount && link.isInSet($pos.parent.child(endIndex).marks)) { - // endPos += $pos.parent.child(endIndex).nodeSize - // endIndex += 1 - // } + let endIndex = $pos.indexAfter() + let endPos = startPos + start.node.nodeSize + while (endIndex < $pos.parent.childCount && link.isInSet($pos.parent.child(endIndex).marks)) { + endPos += $pos.parent.child(endIndex).nodeSize + endIndex += 1 + } return { from: startPos, to: endPos } From 9787b876fe270d66ff6c3080bb2a800167309189 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Fri, 3 May 2019 19:08:50 +0200 Subject: [PATCH 3/3] fix endPosition in getMarkRange getMarkRange() will not return the actual end position of the current mark. might reintroduce bug from #156 (i cannot reproduce #156 so i cannot check) fixes in this commit: A) work around a possible bug in indexAfter()?: $pos.indexAfter() seems to return the same index as $pos.index() at some point -> fixed by increasing startIndex by 1 instead of using indexAfter() B) endPos needs to be initialized with initial startPos + nodeSize and not with resulting startPos: -> moved initialization right after setting startPos --- packages/tiptap-utils/src/utils/getMarkRange.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/tiptap-utils/src/utils/getMarkRange.js b/packages/tiptap-utils/src/utils/getMarkRange.js index 115f8b6b..b3b02977 100644 --- a/packages/tiptap-utils/src/utils/getMarkRange.js +++ b/packages/tiptap-utils/src/utils/getMarkRange.js @@ -17,13 +17,14 @@ export default function ($pos = null, type = null) { let startIndex = $pos.index() let startPos = $pos.start() + start.offset + let endIndex = startIndex + 1 + let endPos = startPos + start.node.nodeSize + while (startIndex > 0 && link.isInSet($pos.parent.child(startIndex - 1).marks)) { startIndex -= 1 startPos -= $pos.parent.child(startIndex).nodeSize } - let endIndex = $pos.indexAfter() - let endPos = startPos + start.node.nodeSize while (endIndex < $pos.parent.childCount && link.isInSet($pos.parent.child(endIndex).marks)) { endPos += $pos.parent.child(endIndex).nodeSize endIndex += 1