diff --git a/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js b/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js index d5e1e3c4672f6d527bd73b31eb7181e3e858eae4..63a90635f47cb290c7834b0c13587d114e973fd5 100644 --- a/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js +++ b/app/components/SimpleEditor/elements/track_change/TrackChangesProvider.js @@ -141,8 +141,11 @@ class TrackChangesProvider { // after deleting all own additions, there is still text selected // mark it as deleted and add new addition annotation at the end + // TODO -- use selection.isCollapsed() if (selection.endOffset > selection.startOffset) { - return this.deleteSelectedAndCreateAddition(options) + this.deleteOrMergeAllOwnDeletions(selection) + this.deleteSelectedAndCreateAddition(options) + return } // if you got here, deleting all own additions left a collapsed selection @@ -285,19 +288,22 @@ class TrackChangesProvider { } deleteAllOwnAdditions (selection) { - // TODO -- for same user - const additions = this.getAllAnnotationsByStatus('add') const originalSelection = selection || this.getSelection() - let shortenBy = 0 - each(additions, (annotation) => { + const additions = this.getAllAnnotationsByStatus('add') + const ownAdditions = filter(additions, annotation => { + return this.isAnnotationFromTheSameUser(annotation) + }) + + each(ownAdditions, (annotation) => { const selection = annotation.getSelection() - // make sure only part of annotation that is selected is deleted + // make sure only the part of the annotation that is selected is deleted if (annotation.startOffset < originalSelection.startOffset) { selection.startOffset = originalSelection.startOffset } + if (annotation.endOffset > originalSelection.endOffset) { selection.endOffset = originalSelection.endOffset } @@ -311,20 +317,20 @@ class TrackChangesProvider { deleteOrMergeAllOwnDeletions (selection) { const deletions = clone(this.getAllAnnotationsByStatus('delete')) - // filter by own deletions - console.log(selection, deletions) + const ownDeletions = filter(deletions, annotation => { + return this.isAnnotationFromTheSameUser(annotation) + }) - // const originalSelection = clone(selection) const selectionArray = [selection] - each(deletions, (annotation) => { + each(ownDeletions, (annotation) => { const annotationSelection = annotation.getSelection() const contained = selection.contains(annotationSelection) if (!contained) { selectionArray.push(annotationSelection) } - console.log('fkdjsjf') + this.removeTrackAnnotation(annotation) }) @@ -540,6 +546,10 @@ class TrackChangesProvider { return annotations } + getAnnotationUser (annotation) { + return annotation.user.id + } + // getDistinctAnnotationsForSelection () { // const selection = this.getSelection() // const annotations = this.getAllExistingTrackAnnotations() @@ -560,8 +570,8 @@ class TrackChangesProvider { } isAnnotationFromTheSameUser (annotation) { - const annotationUser = annotation.user.id - const currentUser = this.config.user.id + const annotationUser = this.getAnnotationUser(annotation) + const currentUser = this.getCurrentUser() if (annotationUser === currentUser) return true return false @@ -716,6 +726,10 @@ class TrackChangesProvider { return this.config.commandManager } + getCurrentUser () { + return this.config.user.id + } + getDocumentSession () { return this.config.documentSession }