From 6c49b955386ced925a5a2843e3415a0177c1a5b5 Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 13 Jan 2017 14:17:47 +0100 Subject: [PATCH] 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 --- .../track-changes/TrackChangesManager.coffee | 7 +++-- .../controllers/ReviewPanelController.coffee | 30 +++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/TrackChangesManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/TrackChangesManager.coffee index 422e1978a6..5de7e3be2d 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/TrackChangesManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/track-changes/TrackChangesManager.coffee @@ -245,10 +245,11 @@ define [ updateFocus: () -> selection = @editor.getSelectionRange() - cursor_offset = @_aceRangeToShareJs(selection.start) + selection_start = @_aceRangeToShareJs(selection.start) + selection_end = @_aceRangeToShareJs(selection.end) entries = @_getCurrentDocEntries() - selection = !(selection.start.column == selection.end.column and selection.start.row == selection.end.row) - @$scope.$emit "editor:focus:changed", cursor_offset, selection + is_selection = (selection_start != selection_end) + @$scope.$emit "editor:focus:changed", selection_start, selection_end, is_selection broadcastChange: () -> @$scope.$emit "editor:track-changes:changed", @$scope.docId diff --git a/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee b/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee index ddedda525b..6dae528436 100644 --- a/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee +++ b/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee @@ -216,25 +216,31 @@ define [ $scope.$broadcast "review-panel:recalculate-screen-positions" $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 entries = getDocEntries(doc_id) - if !selection - delete entries["add-comment"] - else - entries["add-comment"] = { - type: "add-comment" - offset: cursor_offset - } + delete entries["add-comment"] + if selection + # Only show add comment if we're not already overlapping one + overlapping_comment = false + for id, entry of entries + 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 - if entry.type == "comment" and not entry.resolved - entry.focused = (entry.offset <= cursor_offset <= entry.offset + entry.content.length) + if entry.type == "comment" and not $scope.reviewPanel.resolvedThreadIds[entry.thread_id] + entry.focused = (entry.offset <= selection_offset_start <= entry.offset + entry.content.length) 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" - entry.focused = (entry.offset == cursor_offset) + entry.focused = (entry.offset == selection_offset_start) else if entry.type == "add-comment" and selection entry.focused = true