From 1f93cd5e5f7a63c76fd1c4a19d5ebf9f2087caa6 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Wed, 14 Oct 2020 19:51:18 +0300
Subject: [PATCH] fix for selection out of bounds

---
 .../src/document/DocumentHelpers.js           | 30 +++++++++----------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/wax-prosemirror-utilities/src/document/DocumentHelpers.js b/wax-prosemirror-utilities/src/document/DocumentHelpers.js
index 4c09afca6..b5b0f7b9e 100644
--- a/wax-prosemirror-utilities/src/document/DocumentHelpers.js
+++ b/wax-prosemirror-utilities/src/document/DocumentHelpers.js
@@ -38,9 +38,6 @@ const findFragmentedMark = (state, PMmark) => {
     selection: { $from, $to },
     doc,
   } = state;
-  const fromPos = [$from.pos - 1, $from.pos];
-  const toPos = [$to.pos, $to.pos + 1];
-  let markFound;
 
   // const type = state.config.schema.marks.comment;
   // const mark = empty
@@ -57,20 +54,21 @@ const findFragmentedMark = (state, PMmark) => {
   //
   // // return undefined;
 
-  for (let i = 0; i < fromPos.length; i++) {
-    doc.nodesBetween(fromPos[i], toPos[i], (node, from) => {
-      if (node.marks) {
-        const actualMark = node.marks.find(mark => mark.type === PMmark);
-        if (actualMark) {
-          markFound = {
-            from,
-            to: from + node.nodeSize,
-            attrs: actualMark.attrs,
-          };
-        }
+  let markFound;
+
+  doc.nodesBetween($from.pos - 1, $to.pos, (node, from) => {
+    if (node.marks) {
+      const actualMark = node.marks.find(mark => mark.type === PMmark);
+      if (actualMark) {
+        markFound = {
+          from,
+          to: from + node.nodeSize,
+          attrs: actualMark.attrs,
+        };
       }
-    });
-  }
+    }
+  });
+
   return markFound;
 };
 
-- 
GitLab