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-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(

View file

@ -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] ?= {}

View file

@ -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)