From 8c5800ceafd6abad920600f6a4d35e08a0e51692 Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 20 Feb 2017 16:03:02 +0100 Subject: [PATCH] Only render the entries that are visible in the text --- .../app/views/project/editor/review-panel.pug | 1 + .../track-changes/TrackChangesManager.coffee | 32 +++++++++++++++++-- .../controllers/ReviewPanelController.coffee | 6 +++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/services/web/app/views/project/editor/review-panel.pug b/services/web/app/views/project/editor/review-panel.pug index 93ff664eed..2ef5175cf2 100644 --- a/services/web/app/views/project/editor/review-panel.pug +++ b/services/web/app/views/project/editor/review-panel.pug @@ -47,6 +47,7 @@ .rp-entry-list-inner .rp-entry-wrapper( ng-repeat="(entry_id, entry) in reviewPanel.entries[editor.open_doc_id]" + ng-if="entry.visible" ) div(ng-if="entry.type === 'insert' || entry.type === 'delete'") change-entry( 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 b75cb07dba..1e06acd4d5 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 @@ -60,6 +60,18 @@ define [ onChangeSession = (e) => @clearAnnotations() @redrawAnnotations() + @editor.session.on "changeScrollTop", onChangeScroll + + _scrollTimeout = null + onChangeScroll = () => + if _scrollTimeout? + return + else + _scrollTimeout = setTimeout () => + @recalculateVisibleEntries() + @$scope.$apply() + _scrollTimeout = null + , 200 bindToAce = () => @editor.on "changeSelection", onChangeSelection @@ -282,6 +294,7 @@ define [ recalculateReviewEntriesScreenPositions: () -> session = @editor.getSession() renderer = @editor.renderer + {firstRow, lastRow} = renderer.layerConfig entries = @_getCurrentDocEntries() for entry_id, entry of entries or {} doc_position = @_shareJsOffsetToAcePosition(entry.offset) @@ -290,9 +303,24 @@ define [ entry.screenPos ?= {} entry.screenPos.y = y entry.docPos = doc_position - + @recalculateVisibleEntries() @$scope.$apply() - + + recalculateVisibleEntries: () -> + OFFSCREEN_ROWS = 5 + CULL_AFTER = 100 # With less than this number of entries, don't bother culling to avoid little UI jumps when scrolling. + {firstRow, lastRow} = @editor.renderer.layerConfig + entries = @_getCurrentDocEntries() or {} + entriesLength = Object.keys(entries).length + changed = false + for entry_id, entry of entries + old = entry.visible + entry.visible = (entriesLength < CULL_AFTER) or (firstRow - OFFSCREEN_ROWS <= entry.docPos.row <= lastRow + OFFSCREEN_ROWS) + if (entry.visible != old) + changed = true + if changed + @$scope.$emit "editor:track-changes:visibility_changed" + _getCurrentDocEntries: () -> doc_id = @$scope.docId entries = @$scope.reviewPanel.entries[doc_id] ?= {} 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 d0af889dda..33cfae0982 100644 --- a/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee +++ b/services/web/public/coffee/ide/review-panel/controllers/ReviewPanelController.coffee @@ -266,7 +266,11 @@ define [ updateEntries(doc_id) $scope.$broadcast "review-panel:recalculate-screen-positions" $scope.$broadcast "review-panel:layout" - + + $scope.$on "editor:track-changes:visibility_changed", () -> + $timeout () -> + $scope.$broadcast "review-panel:layout", false + $scope.$on "editor:focus:changed", (e, selection_offset_start, selection_offset_end, selection) -> doc_id = $scope.editor.open_doc_id entries = getDocEntries(doc_id)