diff --git a/services/web/app/views/project/editor/track-changes.jade b/services/web/app/views/project/editor/track-changes.jade index c1a96d72d4..df83442bbf 100644 --- a/services/web/app/views/project/editor/track-changes.jade +++ b/services/web/app/views/project/editor/track-changes.jade @@ -98,7 +98,8 @@ div#trackChanges(ng-show="ui.view == 'track-changes'") text="trackChanges.diff.text", highlights="trackChanges.diff.highlights", read-only="true", - resize-on="layout:main:resize" + resize-on="layout:main:resize", + navigate-highlights="true" ) .diff-deleted.text-centered( ng-show="trackChanges.diff.deleted" diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index 4edeb5aae6..c2c79b862d 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -27,6 +27,7 @@ define [ readOnly: "=" gotoLine: "=" annotations: "=" + navigateHighlights: "=" } link: (scope, element, attrs) -> # Don't freak out if we're already in an apply callback @@ -112,7 +113,7 @@ define [ scope.$watch "annotations", (annotations) -> if annotations? - session = editor.getSession() + session = editor.getSession() session.setAnnotations annotations scope.$watch "readOnly", (value) -> @@ -124,11 +125,11 @@ define [ session.setMode("ace/mode/latex") session.setAnnotations scope.annotations - emitChange = () -> + emitChange = () -> scope.$emit "#{scope.name}:change" attachToAce = (sharejs_doc) -> - lines = sharejs_doc.getSnapshot().split("\n") + lines = sharejs_doc.getSnapshot().split("\n") editor.setSession(new EditSession(lines)) resetSession() session = editor.getSession() @@ -166,7 +167,7 @@ define [ >Dismiss
- + + + + {{ updateLabels.highlightsBefore }} more update{{ updateLabels.highlightsBefore > 1 && "" || "s" }} above + + + + + {{ updateLabels.highlightsAfter }} more update{{ updateLabels.highlightsAfter > 1 && "" || "s" }} below + + """ } diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/highlights/HighlightsManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/highlights/HighlightsManager.coffee index 7ec1f247f3..f7d0dc1397 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/highlights/HighlightsManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/highlights/HighlightsManager.coffee @@ -18,6 +18,11 @@ define [ text: "" } + @$scope.updateLabels = { + updatesAbove: 0 + updatesBelow: 0 + } + @$scope.$watch "highlights", (value) => @redrawAnnotations() @@ -29,9 +34,30 @@ define [ e.position = position @showAnnotationLabels(position) - @editor.on "changeSession", () => + onChangeScrollTop = () => + @updateShowMoreLabels() + + @editor.getSession().on "changeScrollTop", onChangeScrollTop + + @$scope.$watch "text", () => + if @$scope.navigateHighlights + setTimeout () => + @scrollToFirstHighlight() + , 0 + + @editor.on "changeSession", (e) => + e.oldSession?.off "changeScrollTop", onChangeScrollTop + e.session.on "changeScrollTop", onChangeScrollTop @redrawAnnotations() + @$scope.gotoHighlightBelow = () => + return if !@firstHiddenHighlightAfter? + @editor.scrollToLine(@firstHiddenHighlightAfter.end.row, true, false) + + @$scope.gotoHighlightAbove = () => + return if !@lastHiddenHighlightBefore? + @editor.scrollToLine(@lastHiddenHighlightBefore.start.row, true, false) + redrawAnnotations: () -> @_clearMarkers() @_clearLabels() @@ -71,6 +97,8 @@ define [ } @_drawStrikeThrough(annotation, colorScheme) + @updateShowMoreLabels() + showAnnotationLabels: (position) -> labelToShow = null for label in @labels or [] @@ -127,6 +155,39 @@ define [ text: labelToShow.text } + updateShowMoreLabels: () -> + return if !@$scope.navigateHighlights + setTimeout () => + firstRow = @editor.getFirstVisibleRow() + lastRow = @editor.getLastVisibleRow() + highlightsBefore = 0 + highlightsAfter = 0 + @lastHiddenHighlightBefore = null + @firstHiddenHighlightAfter = null + for annotation in @$scope.highlights or [] + range = annotation.highlight or annotation.strikeThrough + continue if !range? + if range.start.row < firstRow + highlightsBefore += 1 + @lastHiddenHighlightBefore = range + if range.end.row > lastRow + highlightsAfter += 1 + @firstHiddenHighlightAfter ||= range + + @$scope.$apply => + @$scope.updateLabels = { + highlightsBefore: highlightsBefore + highlightsAfter: highlightsAfter + } + , 100 + + scrollToFirstHighlight: () -> + for annotation in @$scope.highlights or [] + range = annotation.highlight or annotation.strikeThrough + continue if !range? + @editor.scrollToLine(range.start.row, true, false) + break + _clearMarkers: () -> for marker_id in @markerIds @editor.getSession().removeMarker(marker_id) @@ -177,9 +238,9 @@ define [ new Range( annotation.strikeThrough.start.row, annotation.strikeThrough.start.column, annotation.strikeThrough.end.row, annotation.strikeThrough.end.column + 1 - ), + ), "annotation strike-through-foreground", - true, + true, """ height: #{Math.round(lineHeight/2) + 2}px; border-bottom: 2px solid #{colorScheme.strikeThroughForegroundColor}; @@ -223,4 +284,4 @@ define [ r = parseInt(r, 10) g = parseInt(g, 10) b = parseInt(b, 10) - return r + g + b < 3 * 128 \ No newline at end of file + return r + g + b < 3 * 128 diff --git a/services/web/public/stylesheets/app/editor.less b/services/web/public/stylesheets/app/editor.less index c7f49124ab..9e9f5e380b 100644 --- a/services/web/public/stylesheets/app/editor.less +++ b/services/web/public/stylesheets/app/editor.less @@ -153,6 +153,16 @@ position: absolute; z-index: 2; } + .highlights-before-label { + position: absolute; + top: @line-height-computed / 2; + right: @line-height-computed; + } + .highlights-after-label { + position: absolute; + bottom: @line-height-computed / 2; + right: @line-height-computed; + } } .ui-layout-resizer { @@ -198,4 +208,3 @@ position: fixed; z-index: 100; } -