Only render the entries that are visible in the text

This commit is contained in:
James Allen 2017-02-20 16:03:02 +01:00
parent b52e4a5d1c
commit 8c5800ceaf
3 changed files with 36 additions and 3 deletions

View file

@ -47,6 +47,7 @@
.rp-entry-list-inner .rp-entry-list-inner
.rp-entry-wrapper( .rp-entry-wrapper(
ng-repeat="(entry_id, entry) in reviewPanel.entries[editor.open_doc_id]" 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'") div(ng-if="entry.type === 'insert' || entry.type === 'delete'")
change-entry( change-entry(

View file

@ -60,6 +60,18 @@ define [
onChangeSession = (e) => onChangeSession = (e) =>
@clearAnnotations() @clearAnnotations()
@redrawAnnotations() @redrawAnnotations()
@editor.session.on "changeScrollTop", onChangeScroll
_scrollTimeout = null
onChangeScroll = () =>
if _scrollTimeout?
return
else
_scrollTimeout = setTimeout () =>
@recalculateVisibleEntries()
@$scope.$apply()
_scrollTimeout = null
, 200
bindToAce = () => bindToAce = () =>
@editor.on "changeSelection", onChangeSelection @editor.on "changeSelection", onChangeSelection
@ -282,6 +294,7 @@ define [
recalculateReviewEntriesScreenPositions: () -> recalculateReviewEntriesScreenPositions: () ->
session = @editor.getSession() session = @editor.getSession()
renderer = @editor.renderer renderer = @editor.renderer
{firstRow, lastRow} = renderer.layerConfig
entries = @_getCurrentDocEntries() entries = @_getCurrentDocEntries()
for entry_id, entry of entries or {} for entry_id, entry of entries or {}
doc_position = @_shareJsOffsetToAcePosition(entry.offset) doc_position = @_shareJsOffsetToAcePosition(entry.offset)
@ -290,9 +303,24 @@ define [
entry.screenPos ?= {} entry.screenPos ?= {}
entry.screenPos.y = y entry.screenPos.y = y
entry.docPos = doc_position entry.docPos = doc_position
@recalculateVisibleEntries()
@$scope.$apply() @$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: () -> _getCurrentDocEntries: () ->
doc_id = @$scope.docId doc_id = @$scope.docId
entries = @$scope.reviewPanel.entries[doc_id] ?= {} entries = @$scope.reviewPanel.entries[doc_id] ?= {}

View file

@ -267,6 +267,10 @@ 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:track-changes:visibility_changed", () ->
$timeout () ->
$scope.$broadcast "review-panel:layout", false
$scope.$on "editor:focus:changed", (e, selection_offset_start, selection_offset_end, 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)