mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Use TextEditorPresenter::state.content.indentGuidesVisible
This commit is contained in:
@@ -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 '<span class="indent-guide"><span class="invisible-character">C</span><span class="invisible-character">E</span></span>'
|
||||
@@ -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 ' '
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()'
|
||||
|
||||
Reference in New Issue
Block a user