diff --git a/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js b/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js index da3fcd32e86d0ce7ff24f5d52a5d7a74b4628f2d..688e7bfd6fe138309099ac15ec338bc221e72b91 100644 --- a/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js +++ b/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js @@ -161,10 +161,39 @@ class TrackChangesProvider { } } } else { - selection = this.getSelection() - this.createDeleteAnnotation(selection) - this.moveCursorTo(direction.cursorTo) - return + const notOnTrack = this.isNotOnTrackAnnotation() + + if (notOnTrack) { + selection = this.getSelection() + this.createDeleteAnnotation(selection) + this.moveCursorTo(direction.cursorTo) + return + } + + const onAdd = this.isOnAnnotation('add') + + if (onAdd) { + const annotation = this.getAnnotationByStatus('add') + const withinAnnotation = this.isSelectionContainedWithin(annotation) + + if (withinAnnotation) { + const point = annotation[direction.cursorTo + 'Offset'] + this.moveCursorTo(point) + return + } + + const annotationContainedInSelection = this.isAnnotationContainedWithinSelection(annotation) + if (annotationContainedInSelection) { + selection = this.getSelection() + this.createDeleteAnnotation(selection) + return + } + + selection = this.getSelection() + this.createDeleteAnnotation(selection) + this.separateAnnotations() + return + } } } @@ -460,6 +489,13 @@ class TrackChangesProvider { return selection } + isAnnotationContainedWithinSelection (annotation) { + const selection = this.getSelection() + const annotationSelection = annotation.getSelection() + + return selection.contains(annotationSelection) + } + isSelectionCollapsed () { const selection = this.getSelection() const isCollapsed = selection.isCollapsed()