--- a/client/src/AnnotationPlugin.js Wed Sep 05 13:48:10 2018 +0200
+++ b/client/src/AnnotationPlugin.js Tue Sep 25 02:02:13 2018 +0200
@@ -3,13 +3,12 @@
const { onChange } = options
return {
- onSelect(event, data, state, editor) {
+ onSelect(event, change) {
event.preventDefault()
- const selection = data.selection;
-
- const startOffset = selection.startOffset;
- const endOffset = selection.endOffset;
+ const { value } = change
+ const { selection } = value
+ const { start, end} = selection
if (selection.isCollapsed) {
return;
@@ -21,14 +20,14 @@
// Keep only the relevant nodes,
// i.e. nodes which are contained within selection
- state.document.nodes.forEach((node) => {
- if (selection.hasStartIn(node)) {
+ value.document.nodes.forEach((node) => {
+ if (start.isInNode(node)) {
hasStarted = true;
}
if (hasStarted && !hasEnded) {
nodes.push(node);
}
- if (selection.hasEndIn(node)) {
+ if (end.isAtEndOfNode(node)) {
hasEnded = true;
}
});
@@ -37,17 +36,17 @@
// Concatenate the nodes text
if (nodes.length === 1) {
- text = nodes[0].text.substring(startOffset, endOffset);
+ text = nodes[0].text.substring(start.offset, end.offset);
} else {
text = nodes.map((node) => {
- if (selection.hasStartIn(node)) return node.text.substring(startOffset);
- if (selection.hasEndIn(node)) return node.text.substring(0, endOffset);
+ 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');
}
if (onChange) {
- onChange(text, startOffset, endOffset);
+ onChange(text, start.offset, end.offset);
}
}