client/src/components/SlateEditor.js
changeset 102 b0e36664f1f2
parent 80 b3a02ea6d097
child 103 dc906a578616
--- a/client/src/components/SlateEditor.js	Wed Jun 28 12:54:48 2017 +0200
+++ b/client/src/components/SlateEditor.js	Wed Jun 28 13:29:07 2017 +0200
@@ -69,8 +69,12 @@
     super(props);
 
     const annotationPlugin = AnnotationPlugin({
-      onChange: (text) => {
-        this.setState({ currentSelectionText: text });
+      onChange: (text, start, end) => {
+        this.setState({
+          currentSelectionText: text,
+          currentSelectionStart: start,
+          currentSelectionEnd: end
+        });
       }
     });
 
@@ -81,6 +85,8 @@
       startedAt: null,
       finishedAt: null,
       currentSelectionText: '',
+      currentSelectionStart: 0,
+      currentSelectionEnd: 0,
       hoveringMenu: null,
       isPortalOpen: false,
       categories: Immutable.List([]),
@@ -349,7 +355,7 @@
 
   onCategoryClick = (category) => {
 
-    const { state, currentSelectionText } = this.state;
+    const { state, currentSelectionText, currentSelectionStart, currentSelectionEnd } = this.state;
     let { categories } = this.state;
     const transform = state.transform();
 
@@ -360,6 +366,10 @@
       type: 'category',
       data: {
         text: currentSelectionText,
+        selection: {
+          start: currentSelectionStart,
+          end: currentSelectionEnd,
+        },
         color: category.color,
         key: category.key
       }