Cache line number gutter properties during a single frame

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.
This commit is contained in:
Nathan Sobo
2017-03-01 13:29:19 -07:00
committed by Antonio Scandurra
parent 38f51ce74d
commit 7196b05af7

View File

@@ -107,6 +107,7 @@ class TextEditorComponent {
etch.updateSync(this)
this.pendingAutoscroll = null
this.currentFramelineNumberGutterProps = null
}
render () {
@@ -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)
@@ -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(
{