Просмотр исходного кода

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
James Allen 9 лет назад
Родитель
Сommit
6c49b95538

+ 4 - 3
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

+ 18 - 12
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