From 8cd04b51784f150d0f16bf465358dfc9f66caec0 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 1 Oct 2013 16:47:23 -0700 Subject: [PATCH] Override isHidden for the Editor We know it's visible if it is on the dom and doesn't have display == none set. This is an order of magnitude faster than the default implementation which calls getComputedStyle() --- src/editor.coffee | 69 +++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/src/editor.coffee b/src/editor.coffee index 5c8ab8631..f45d7d541 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -1139,6 +1139,14 @@ class Editor extends View @layerMinWidth = minWidth @trigger 'editor:min-width-changed' + # Override for speed. The base function checks computedStyle, unnecessary here. + isHidden: -> + style = this[0].style + if style.display == 'none' or not @isOnDom() + true + else + false + clearRenderedLines: -> @renderedLines.empty() @firstRenderedScreenRow = null @@ -1440,11 +1448,11 @@ class Editor extends View new Array(div.children...) htmlForScreenRows: (startRow, endRow) -> - htmlLines = [] + htmlLines = '' screenRow = startRow for line in @activeEditSession.linesForScreenRows(startRow, endRow) - htmlLines.push(@htmlForScreenLine(line, screenRow++)) - htmlLines.join('\n\n') + htmlLines += @htmlForScreenLine(line, screenRow++) + htmlLines htmlForScreenLine: (screenLine, screenRow) -> { tokens, text, lineEnding, fold, isSoftWrapped } = screenLine @@ -1629,30 +1637,9 @@ class Editor extends View scopeStack = [] line = [] - updateScopeStack = (desiredScopes) -> - excessScopes = scopeStack.length - desiredScopes.length - _.times(excessScopes, popScope) if excessScopes > 0 - - # pop until common prefix - for i in [scopeStack.length..0] - break if _.isEqual(scopeStack[0...i], desiredScopes[0...i]) - popScope() - - # push on top of common prefix until scopeStack == desiredScopes - for j in [i...desiredScopes.length] - pushScope(desiredScopes[j]) - - pushScope = (scope) -> - scopeStack.push(scope) - line.push("") - - popScope = -> - scopeStack.pop() - line.push("") - - attributePairs = [] - attributePairs.push "#{attributeName}=\"#{value}\"" for attributeName, value of attributes - line.push("
") + attributePairs = '' + attributePairs += " #{attributeName}=\"#{value}\"" for attributeName, value of attributes + line.push("
") if text == '' html = Editor.buildEmptyLineHtml(showIndentGuide, eolInvisibles, htmlEolInvisibles, indentation, activeEditSession, mini) @@ -1663,20 +1650,44 @@ class Editor extends View lineIsWhitespaceOnly = firstTrailingWhitespacePosition is 0 position = 0 for token in tokens - updateScopeStack(token.scopes) + @updateScopeStack(line, scopeStack, token.scopes) hasLeadingWhitespace = position < firstNonWhitespacePosition hasTrailingWhitespace = position + token.value.length > firstTrailingWhitespacePosition hasIndentGuide = not mini and showIndentGuide and (hasLeadingWhitespace or lineIsWhitespaceOnly) line.push(token.getValueAsHtml({invisibles, hasLeadingWhitespace, hasTrailingWhitespace, hasIndentGuide})) position += token.value.length - popScope() while scopeStack.length > 0 + @popScope(line, scopeStack) while scopeStack.length > 0 line.push(htmlEolInvisibles) unless text == '' line.push("") if fold line.push('
') line.join('') + @updateScopeStack: (line, scopeStack, desiredScopes) -> + excessScopes = scopeStack.length - desiredScopes.length + if excessScopes > 0 + @popScope(line, scopeStack) while excessScopes-- + + # pop until common prefix + for i in [scopeStack.length..0] + break if _.isEqual(scopeStack[0...i], desiredScopes[0...i]) + @popScope(line, scopeStack) + + # push on top of common prefix until scopeStack == desiredScopes + for j in [i...desiredScopes.length] + @pushScope(line, scopeStack, desiredScopes[j]) + + null + + @pushScope: (line, scopeStack, scope) -> + scopeStack.push(scope) + line.push("") + + @popScope: (line, scopeStack)-> + scopeStack.pop() + line.push("") + @buildEmptyLineHtml: (showIndentGuide, eolInvisibles, htmlEolInvisibles, indentation, activeEditSession, mini) -> if not mini and showIndentGuide if indentation > 0