client/src/components/SlateEditor/AnnotationPlugin.js
changeset 172 4b780ebbedc6
parent 168 ea92f4fe783d
--- a/client/src/components/SlateEditor/AnnotationPlugin.js	Thu Nov 08 16:03:28 2018 +0100
+++ b/client/src/components/SlateEditor/AnnotationPlugin.js	Tue Nov 13 16:46:15 2018 +0100
@@ -3,18 +3,18 @@
   const { onChange } = options
 
   return {
-    onSelect(event, change) {
+    onSelect(event, editor, next) {
       event.preventDefault()
 
-      const { value } = change
+      const { value } = editor
       const { selection } = value
       const { start, end} = selection
 
       if (selection.isCollapsed) {
-        return;
+        return next();
       }
 
-      let nodes = [];
+      const nodes = [];
       let hasStarted = false;
       let hasEnded = false;
 
@@ -32,22 +32,19 @@
         }
       });
 
-      let text = '';
-
       // Concatenate the nodes text
-      if (nodes.length === 1) {
-        text = nodes[0].text.substring(start.offset, end.offset);
-      } else {
-        text = nodes.map((node) => {
-          if (start.isInNode(node)) return node.text.substring(start.offset);
-          if (end.isAtEndOfNode(node)) return node.text.substring(0, end.offset);
-          return node.text;
-        }).join('\n');
-      }
+      const text = nodes.map((node) => {
+        let textStart = start.isInNode(node) ? start.offset : 0;
+        let textEnd = end.isAtEndOfNode(node) ? end.offset : node.text.length;
+        return node.text.substring(textStart,textEnd);
+      }).join('\n');
 
       if (onChange) {
         onChange(text, start.offset, end.offset);
       }
+
+      return next();
+
     }
 
   };