diff --git a/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js b/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js index 210bc087b92aa6bc98c71715cd99bcf104016eba..4e8c817439720720fd3e5d87533b8821967c3acf 100644 --- a/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js +++ b/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js @@ -27,17 +27,35 @@ class TrackChangesProvider { if (status !== 'add') return const isSelectionCollapsed = this.isSelectionCollapsed() - const mode = this.getMode() + // const mode = this.getMode() let selection if (isSelectionCollapsed) { this.insertText(event) - if (mode) return - selection = this.setSelectionPlusOne('left') - this.createAddAnnotation(selection) - this.moveCursorTo('end') - return + + const notOnTrack = this.isNotOnTrackAnnotation() + + if (notOnTrack) { + selection = this.setSelectionPlusOne('left') + this.createAddAnnotation(selection) + this.moveCursorTo('end') + return + } else { + const isOnAdd = this.isOnAnnotation('add') + + if (isOnAdd) { + const annotation = this.getAnnotationByStatus('add') + const isOnLeftEdge = this.isOnLeftEdge(annotation) + + if (isOnLeftEdge) { + selection = this.setSelectionPlusOne('left') + this.expandTrackAnnotation(selection, annotation) + this.moveCursorTo('end') + return + } + } + } } else { selection = this.getSelection() this.createDeleteAnnotation(selection) @@ -98,8 +116,9 @@ class TrackChangesProvider { createTrackAnnotation (selection, status) { const surface = this.getSurface() + const info = this.getInfo() - surface.transaction((tx, args) => { + const transformation = (tx, args) => { const newNode = { selection: selection, node: { @@ -108,18 +127,23 @@ class TrackChangesProvider { } } createAnnotation(tx, newNode) - }) + } + + surface.transaction(transformation, info) } expandTrackAnnotation (selection, annotation) { const surface = this.getSurface() + const info = this.getInfo() - surface.transaction((tx, args) => { + const transformation = (tx, args) => { args.selection = selection args.anno = annotation expandAnnotation(tx, args) - }) + } + + surface.transaction(transformation, info) } separateAnnotations () { @@ -177,6 +201,12 @@ class TrackChangesProvider { return annotations } + // prevent substance from running getBoundingRectangle, + // as we will unset the selection manually + getInfo () { + return { skipSelection: true } + } + // returns whether the selection is on an add / delete tracked change isOnAnnotation (status) { const annotations = this.getAllExistingTrackAnnotations() @@ -188,6 +218,16 @@ class TrackChangesProvider { return true } + isOnLeftEdge (annotation) { + const selection = this.getSelection() + return (selection.startOffset === annotation.startOffset) + } + + isNotOnTrackAnnotation () { + const mode = this.getMode() + return (mode === null) + } + /** HISTORY HANDLERS