From 32a1854b7c817388ebaec1c977679df889e19563 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 21 Jan 2015 09:42:04 -0700 Subject: [PATCH] Use TextEditorPresenter::state.content.indentGuidesVisible --- spec/text-editor-component-spec.coffee | 12 +++++++++--- src/lines-component.coffee | 19 ++++++++++--------- src/text-editor-component.coffee | 8 ++++---- src/text-editor-view.coffee | 2 +- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/spec/text-editor-component-spec.coffee b/spec/text-editor-component-spec.coffee index bfdf2db0f..ad5a4e18c 100644 --- a/spec/text-editor-component-spec.coffee +++ b/spec/text-editor-component-spec.coffee @@ -301,7 +301,9 @@ describe "TextEditorComponent", -> expect(component.lineNodeForScreenRow(10).textContent).toBe nbsp it "interleaves invisible line-ending characters with indent guides on empty lines", -> - component.setShowIndentGuide(true) + atom.config.set "editor.showIndentGuide", true + nextAnimationFrame() + editor.setTextInBufferRange([[10, 0], [11, 0]], "\r\n", normalizeLineEndings: false) nextAnimationFrame() expect(component.lineNodeForScreenRow(10).innerHTML).toBe 'CE' @@ -334,7 +336,8 @@ describe "TextEditorComponent", -> describe "when indent guides are enabled", -> beforeEach -> - component.setShowIndentGuide(true) + atom.config.set "editor.showIndentGuide", true + nextAnimationFrame() it "adds an 'indent-guide' class to spans comprising the leading whitespace", -> line1LeafNodes = getLeafNodes(component.lineNodeForScreenRow(1)) @@ -410,7 +413,7 @@ describe "TextEditorComponent", -> describe "when indent guides are disabled", -> beforeEach -> - component.setShowIndentGuide(false) + expect(atom.config.get("editor.showIndentGuide")).toBe false it "does not render indent guides on lines containing only whitespace", -> editor.getBuffer().insert([1, Infinity], '\n ') @@ -2698,6 +2701,7 @@ describe "TextEditorComponent", -> beforeEach -> atom.config.set 'editor.showIndentGuide', true, scopeSelector: '.source.js' atom.config.set 'editor.showIndentGuide', false, scopeSelector: '.source.coffee' + nextAnimationFrame() it "has an 'indent-guide' class when scoped editor.showIndentGuide is true, but not when scoped editor.showIndentGuide is false", -> line1LeafNodes = getLeafNodes(component.lineNodeForScreenRow(1)) @@ -2706,6 +2710,7 @@ describe "TextEditorComponent", -> expect(line1LeafNodes[1].classList.contains('indent-guide')).toBe false editor.setGrammar(coffeeEditor.getGrammar()) + nextAnimationFrame() line1LeafNodes = getLeafNodes(component.lineNodeForScreenRow(1)) expect(line1LeafNodes[0].textContent).toBe ' ' @@ -2719,6 +2724,7 @@ describe "TextEditorComponent", -> expect(line1LeafNodes[1].classList.contains('indent-guide')).toBe false atom.config.set 'editor.showIndentGuide', false, scopeSelector: '.source.js' + nextAnimationFrame() line1LeafNodes = getLeafNodes(component.lineNodeForScreenRow(1)) expect(line1LeafNodes[0].textContent).toBe ' ' diff --git a/src/lines-component.coffee b/src/lines-component.coffee index 4fa864355..a1e0b42f2 100644 --- a/src/lines-component.coffee +++ b/src/lines-component.coffee @@ -75,8 +75,7 @@ LinesComponent = React.createClass {visible, scrollingVertically, performedInitialMeasurement} = @props return unless performedInitialMeasurement - unless isEqualForProperties(prevProps, @props, 'showIndentGuide') - @removeLineNodes() + @removeLineNodes() unless @oldState?.indentGuidesVisible is @newState?.indentGuidesVisible @updateLineNodes(@props.lineWidth isnt prevProps.lineWidth) @@ -84,6 +83,9 @@ LinesComponent = React.createClass @overlayManager?.render(@props) + @oldState.indentGuidesVisible = @newState.indentGuidesVisible + @oldState.scrollWidth = @newState.scrollWidth + clearScreenRowCaches: -> @screenRowsByLineId = {} @lineIdsByScreenRow = {} @@ -126,8 +128,6 @@ LinesComponent = React.createClass @renderedDecorationsByLineId[id] = lineDecorations[lineState.screenRow] - @oldState.scrollWidth = @newState.scrollWidth - return unless newLineIds? WrapperDiv.innerHTML = newLinesHTML @@ -139,7 +139,7 @@ LinesComponent = React.createClass node.appendChild(lineNode) buildLineHTML: (id) -> - {presenter, showIndentGuide, lineDecorations} = @props + {presenter, lineDecorations} = @props {scrollWidth} = @newState {screenRow, tokens, text, top, lineEnding, fold, isSoftWrapped, indentLevel} = @newState.lines[id] @@ -162,10 +162,10 @@ LinesComponent = React.createClass lineHTML buildEmptyLineInnerHTML: (id) -> - {showIndentGuide} = @props + {indentGuidesVisible} = @newState {indentLevel, tabLength, endOfLineInvisibles} = @newState.lines[id] - if showIndentGuide and indentLevel > 0 + if indentGuidesVisible and indentLevel > 0 invisibleIndex = 0 lineHTML = '' for i in [0...indentLevel] @@ -185,7 +185,8 @@ LinesComponent = React.createClass @buildEndOfLineHTML(id) or ' ' buildLineInnerHTML: (id) -> - {editor, showIndentGuide} = @props + {editor} = @props + {indentGuidesVisible} = @newState {tokens, text} = @newState.lines[id] innerHTML = "" @@ -194,7 +195,7 @@ LinesComponent = React.createClass lineIsWhitespaceOnly = firstTrailingWhitespacePosition is 0 for token in tokens innerHTML += @updateScopeStack(scopeStack, token.scopes) - hasIndentGuide = not editor.isMini() and showIndentGuide and (token.hasLeadingWhitespace() or (token.hasTrailingWhitespace() and lineIsWhitespaceOnly)) + hasIndentGuide = not editor.isMini() and indentGuidesVisible and (token.hasLeadingWhitespace() or (token.hasTrailingWhitespace() and lineIsWhitespaceOnly)) innerHTML += token.getValueAsHtml({hasIndentGuide}) innerHTML += @popScope(scopeStack) while scopeStack.length > 0 diff --git a/src/text-editor-component.coffee b/src/text-editor-component.coffee index b83603e57..e1d26fa70 100644 --- a/src/text-editor-component.coffee +++ b/src/text-editor-component.coffee @@ -48,7 +48,7 @@ TextEditorComponent = React.createClass remeasureCharacterWidthsWhenShown: false render: -> - {focused, showIndentGuide, showLineNumbers, visible} = @state + {focused, showLineNumbers, visible} = @state {editor, cursorBlinkPeriod, cursorBlinkResumeDelay, hostElement, useShadowDOM} = @props maxLineNumberDigits = editor.getLineCount().toString().length hasSelection = editor.getLastSelection()? and !editor.getLastSelection().isEmpty() @@ -115,7 +115,7 @@ TextEditorComponent = React.createClass ref: 'lines', editor, lineHeightInPixels, defaultCharWidth, tokenizedLines, lineDecorations, highlightDecorations, overlayDecorations, hostElement, - showIndentGuide, renderedRowRange, @pendingChanges, scrollTop, scrollLeft, + renderedRowRange, @pendingChanges, scrollTop, scrollLeft, @scrollingVertically, scrollHeight, scrollWidth, mouseWheelScreenRow, visible, scrollViewHeight, @scopedCharacterWidthsChangeCount, lineWidth, @useHardwareAcceleration, placeholderText, @performedInitialMeasurement, @backgroundColor, cursorPixelRects, @@ -470,7 +470,7 @@ TextEditorComponent = React.createClass scopeDescriptor = editor.getRootScopeDescriptor() - subscriptions.add atom.config.observe 'editor.showIndentGuide', scope: scopeDescriptor, @setShowIndentGuide + subscriptions.add atom.config.observe 'editor.showIndentGuide', scope: scopeDescriptor, @requestUpdate subscriptions.add atom.config.observe 'editor.showLineNumbers', scope: scopeDescriptor, @updateGutterVisible subscriptions.add atom.config.observe 'editor.scrollSensitivity', scope: scopeDescriptor, @setScrollSensitivity @@ -1014,7 +1014,7 @@ TextEditorComponent = React.createClass @sampleFontStyling() setShowIndentGuide: (showIndentGuide) -> - @setState({showIndentGuide}) + atom.config.set("editor.showIndentGuide", showIndentGuide) setMini: -> @updateGutterVisible() diff --git a/src/text-editor-view.coffee b/src/text-editor-view.coffee index bdba5bdfc..7fceb42a8 100644 --- a/src/text-editor-view.coffee +++ b/src/text-editor-view.coffee @@ -283,7 +283,7 @@ class TextEditorView extends View setShowIndentGuide: (showIndentGuide) -> deprecate 'This is going away. Use atom.config.set("editor.showIndentGuide", true|false) instead' - @component.setShowIndentGuide(showIndentGuide) + atom.config.set("editor.showIndentGuide", showIndentGuide) setSoftWrap: (softWrapped) -> deprecate 'Use TextEditor::setSoftWrapped instead. You can get the editor via editorView.getModel()'