Skip to content
Snippets Groups Projects
Commit 3ba766c9 authored by john's avatar john
Browse files

resolve choosing active comment logic

parent 4f06972a
No related branches found
No related tags found
No related merge requests found
......@@ -74,6 +74,7 @@ class CommentsProvider extends TocProvider {
}
const activeComment = this.getActiveComment()
if (!activeComment) return this.removeActiveEntry()
// current selection and previous selection both belong to the same comment
if (activeEntry === activeComment.id) return
......@@ -157,16 +158,46 @@ class CommentsProvider extends TocProvider {
}
getActiveComment () {
const commentAnnotations = this.getSelectionComments()
const commentState = this.getCommentState()
const comments = this.getSelectionComments()
const mode = this.getMode()
const selection = this.getSelection()
// we have a non-collapsed selection that contains multiple comments
if (mode === 'fuse') {
// only keep the comments that contain the whole selection
let annos = _.filter(comments, annotation => {
return annotation.getSelection().contains(selection)
})
if (annos.length === 0) return null
if (annos.length === 1) return annos[0]
// find comments that contain all other comments and remove them
// the focus of the active comment should be inwards
let remove = []
_.forEach(annos, anno => {
let removeIt = true
// TODO -- there's gotta be a better way to do this than a double loop
_.forEach(annos, innerAnno => {
if (anno === innerAnno) return
switch (commentState.mode) {
case 'fuse':
const count = commentAnnotations.length - 1
return commentAnnotations[count]
default:
return commentAnnotations[0]
const outerSelection = anno.getSelection()
const innerSelection = innerAnno.getSelection()
if (!outerSelection.contains(innerSelection)) removeIt = false
})
if (removeIt) remove.push(anno)
})
annos = _.difference(annos, remove)
// once you have all comments that do not contain each other wholly
// just choose the one on the left
return _.minBy(annos, 'startOffset')
}
return comments[0]
}
// returns an array of all comments in selection
......@@ -193,6 +224,11 @@ class CommentsProvider extends TocProvider {
return commandStates.comment
}
getMode () {
const commentState = this.getCommentState()
return commentState.mode
}
getNode (id) {
const doc = this.getDocument()
return doc.get(id)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment