Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Cache line number gutter properties during a single frame
Browse files Browse the repository at this point in the history
These properties are somewhat expensive to compute. Since we need to
perform 2 updates per frame to perform horizontal measurement, it's good
to avoid computing the gutter properties twice since they aren't
affected by horizontal measurements in any way.
  • Loading branch information
Nathan Sobo committed Mar 2, 2017
1 parent 9a10461 commit a52a495
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/text-editor-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class TextEditorComponent {
etch.updateSync(this)

this.pendingAutoscroll = null
this.currentFramelineNumberGutterProps = null
}

render () {
Expand Down Expand Up @@ -158,6 +159,10 @@ class TextEditorComponent {
}

renderLineNumberGutter () {
if (this.currentFramelineNumberGutterProps) {
return $(LineNumberGutterComponent, this.currentFramelineNumberGutterProps)
}

const model = this.getModel()
const maxLineNumberDigits = Math.max(2, model.getLineCount().toString().length)

Expand All @@ -181,13 +186,15 @@ class TextEditorComponent {

const rowsPerTile = this.getRowsPerTile()

return $(LineNumberGutterComponent, {
this.currentFramelineNumberGutterProps = {
height: this.getScrollHeight(),
width: this.measurements.lineNumberGutterWidth,
lineHeight: this.measurements.lineHeight,
startRow, endRow, rowsPerTile, maxLineNumberDigits,
bufferRows, softWrappedFlags, foldableFlags
})
}

return $(LineNumberGutterComponent, this.currentFramelineNumberGutterProps)
} else {
return $.div(
{
Expand Down

0 comments on commit a52a495

Please sign in to comment.