Don't allow overlapping comments

Note that this is only a 'soft' don't allow. You could resolve a comment, comment in the same area,
and get them to overlap. It's not a problem if they overlap, just a bit ugly UI wise
This commit is contained in:
James Allen 2017-01-13 14:17:47 +01:00
parent aab4dea8ae
commit 6c49b95538
2 changed files with 22 additions and 15 deletions

View file

@ -245,10 +245,11 @@ define [
updateFocus: () -> updateFocus: () ->
selection = @editor.getSelectionRange() selection = @editor.getSelectionRange()
cursor_offset = @_aceRangeToShareJs(selection.start) selection_start = @_aceRangeToShareJs(selection.start)
selection_end = @_aceRangeToShareJs(selection.end)
entries = @_getCurrentDocEntries() entries = @_getCurrentDocEntries()
selection = !(selection.start.column == selection.end.column and selection.start.row == selection.end.row) is_selection = (selection_start != selection_end)
@$scope.$emit "editor:focus:changed", cursor_offset, selection @$scope.$emit "editor:focus:changed", selection_start, selection_end, is_selection
broadcastChange: () -> broadcastChange: () ->
@$scope.$emit "editor:track-changes:changed", @$scope.docId @$scope.$emit "editor:track-changes:changed", @$scope.docId

View file

@ -216,25 +216,31 @@ define [
$scope.$broadcast "review-panel:recalculate-screen-positions" $scope.$broadcast "review-panel:recalculate-screen-positions"
$scope.$broadcast "review-panel:layout" $scope.$broadcast "review-panel:layout"
$scope.$on "editor:focus:changed", (e, cursor_offset, selection) -> $scope.$on "editor:focus:changed", (e, selection_offset_start, selection_offset_end, selection) ->
doc_id = $scope.editor.open_doc_id doc_id = $scope.editor.open_doc_id
entries = getDocEntries(doc_id) entries = getDocEntries(doc_id)
if !selection delete entries["add-comment"]
delete entries["add-comment"] if selection
else # Only show add comment if we're not already overlapping one
entries["add-comment"] = { overlapping_comment = false
type: "add-comment" for id, entry of entries
offset: cursor_offset if entry.type == "comment" and not $scope.reviewPanel.resolvedThreadIds[entry.thread_id]
} unless entry.offset >= selection_offset_end or entry.offset + entry.content.length <= selection_offset_start
overlapping_comment = true
if !overlapping_comment
entries["add-comment"] = {
type: "add-comment"
offset: selection_offset_start
}
for id, entry of entries for id, entry of entries
if entry.type == "comment" and not entry.resolved if entry.type == "comment" and not $scope.reviewPanel.resolvedThreadIds[entry.thread_id]
entry.focused = (entry.offset <= cursor_offset <= entry.offset + entry.content.length) entry.focused = (entry.offset <= selection_offset_start <= entry.offset + entry.content.length)
else if entry.type == "insert" else if entry.type == "insert"
entry.focused = (entry.offset <= cursor_offset <= entry.offset + entry.content.length) entry.focused = (entry.offset <= selection_offset_start <= entry.offset + entry.content.length)
else if entry.type == "delete" else if entry.type == "delete"
entry.focused = (entry.offset == cursor_offset) entry.focused = (entry.offset == selection_offset_start)
else if entry.type == "add-comment" and selection else if entry.type == "add-comment" and selection
entry.focused = true entry.focused = true