Don't show invisibles in mini editors

This moves observation of the config keys to Editor, which assigns the
invisibles hash or null on the TokenizedBuffer via the DisplayBuffer to
control whether we render invisibles or not.
This commit is contained in:
Nathan Sobo
2014-08-13 16:18:38 -06:00
parent 8c11c4a4c6
commit 20daed176b
7 changed files with 48 additions and 32 deletions

View File

@@ -2116,8 +2116,9 @@ describe "EditorComponent", ->
expect(component.refs.lines.getDOMNode().getAttribute('style')).not.toContain 'background-color'
it "does not render invisible characters", ->
component.setInvisibles(eol: 'E')
component.setShowInvisibles(true)
atom.config.set('editor.invisibles', eol: 'E')
atom.config.set('editor.showInvisibles', true)
nextAnimationFrame()
expect(component.lineNodeForScreenRow(0).textContent).toBe 'var quicksort = function () {'
it "does not assign an explicit line-height on the editor contents", ->

View File

@@ -588,7 +588,7 @@ describe "TokenizedBuffer", ->
atom.config.set('editor.tabLength', 0)
expect(tokenizedBuffer.tokenForPosition([0,0]).value).toBe ' '
describe "when the editor.showInvisibles and editor.invisibles config values change", ->
describe "when the invisibles value changes", ->
beforeEach ->
it "updates the tokens with the appropriate invisible characters", ->
@@ -596,8 +596,7 @@ describe "TokenizedBuffer", ->
tokenizedBuffer = new TokenizedBuffer({buffer})
fullyTokenize(tokenizedBuffer)
atom.config.set('editor.invisibles', space: 'S', tab: 'T')
atom.config.set('editor.showInvisibles', true)
tokenizedBuffer.setInvisibles(space: 'S', tab: 'T')
fullyTokenize(tokenizedBuffer)
expect(tokenizedBuffer.lineForScreenRow(0).text).toBe "SST Sa line with tabsTand T spacesSTS"
@@ -609,7 +608,7 @@ describe "TokenizedBuffer", ->
tokenizedBuffer = new TokenizedBuffer({buffer})
atom.config.set('editor.showInvisibles', true)
atom.config.set('editor.invisibles', cr: 'R', eol: 'N')
tokenizedBuffer.setInvisibles(cr: 'R', eol: 'N')
fullyTokenize(tokenizedBuffer)
expect(tokenizedBuffer.lineForScreenRow(0).endOfLineInvisibles).toEqual ['R', 'N']
@@ -620,7 +619,7 @@ describe "TokenizedBuffer", ->
expect(left.endOfLineInvisibles).toBe null
expect(right.endOfLineInvisibles).toEqual ['R', 'N']
atom.config.set('editor.invisibles', cr: 'R', eol: false)
tokenizedBuffer.setInvisibles(cr: 'R', eol: false)
expect(tokenizedBuffer.lineForScreenRow(0).endOfLineInvisibles).toEqual ['R']
expect(tokenizedBuffer.lineForScreenRow(1).endOfLineInvisibles).toEqual []
@@ -692,8 +691,8 @@ describe "TokenizedBuffer", ->
it "sets leading and trailing whitespace correctly on a line with invisible characters that is copied", ->
buffer.setText(" \t a line with tabs\tand \tspaces \t ")
atom.config.set('editor.invisibles', space: 'S', tab: 'T')
atom.config.set('editor.showInvisibles', true)
tokenizedBuffer.setInvisibles(space: 'S', tab: 'T')
fullyTokenize(tokenizedBuffer)
line = tokenizedBuffer.lineForScreenRow(0).copy()

View File

@@ -38,10 +38,10 @@ class DisplayBuffer extends Model
verticalScrollbarWidth: 15
scopedCharacterWidthsChangeCount: 0
constructor: ({tabLength, @editorWidthInChars, @tokenizedBuffer, buffer}={}) ->
constructor: ({tabLength, @editorWidthInChars, @tokenizedBuffer, buffer, @invisibles}={}) ->
super
@softWrap ?= atom.config.get('editor.softWrap') ? false
@tokenizedBuffer ?= new TokenizedBuffer({tabLength, buffer})
@tokenizedBuffer ?= new TokenizedBuffer({tabLength, buffer, @invisibles})
@buffer = @tokenizedBuffer.buffer
@charWidthsByScope = {}
@markers = {}
@@ -81,7 +81,7 @@ class DisplayBuffer extends Model
params
copy: ->
newDisplayBuffer = new DisplayBuffer({@buffer, tabLength: @getTabLength()})
newDisplayBuffer = new DisplayBuffer({@buffer, tabLength: @getTabLength(), @invisibles})
newDisplayBuffer.setScrollTop(@getScrollTop())
newDisplayBuffer.setScrollLeft(@getScrollLeft())
@@ -340,6 +340,9 @@ class DisplayBuffer extends Model
setTabLength: (tabLength) ->
@tokenizedBuffer.setTabLength(tabLength)
setInvisibles: (@invisibles) ->
@tokenizedBuffer.setInvisibles(@invisibles)
# Deprecated: Use the softWrap property directly
setSoftWrap: (@softWrap) -> @softWrap

View File

@@ -191,6 +191,9 @@ EditorComponent = React.createClass
@domPollingIntervalId = null
@props.editor.destroy()
componentWillReceiveProps: (newProps) ->
@props.editor.setMini(newProps.mini)
componentWillUpdate: ->
wasVisible = @visible
@visible = @isVisible()

View File

@@ -159,13 +159,16 @@ class Editor extends Model
@delegatesProperties '$lineHeightInPixels', '$defaultCharWidth', '$height', '$width',
'$scrollTop', '$scrollLeft', 'manageScrollPosition', toProperty: 'displayBuffer'
constructor: ({@softTabs, initialLine, initialColumn, tabLength, softWrap, @displayBuffer, buffer, registerEditor, suppressCursorCreation}) ->
constructor: ({@softTabs, initialLine, initialColumn, tabLength, softWrap, @displayBuffer, buffer, registerEditor, suppressCursorCreation, @mini}) ->
super
@cursors = []
@selections = []
@displayBuffer ?= new DisplayBuffer({buffer, tabLength, softWrap})
if @shouldShowInvisibles()
invisibles = atom.config.get('editor.invisibles')
@displayBuffer ?= new DisplayBuffer({buffer, tabLength, softWrap, invisibles})
@buffer = @displayBuffer.buffer
@softTabs = @usesSoftTabs() ? @softTabs ? atom.config.get('editor.softTabs') ? true
@@ -186,6 +189,9 @@ class Editor extends Model
@subscribe @$scrollTop, (scrollTop) => @emit 'scroll-top-changed', scrollTop
@subscribe @$scrollLeft, (scrollLeft) => @emit 'scroll-left-changed', scrollLeft
@subscribe atom.config.observe 'editor.showInvisibles', callNow: false, (show) => @updateInvisibles()
@subscribe atom.config.observe 'editor.invisibles', callNow: false, => @updateInvisibles()
atom.workspace?.editorAdded(this) if registerEditor
serializeParams: ->
@@ -281,6 +287,11 @@ class Editor extends Model
# Controls visibility based on the given {Boolean}.
setVisible: (visible) -> @displayBuffer.setVisible(visible)
setMini: (mini) ->
if mini isnt @mini
@mini = mini
@updateInvisibles()
# Set the number of characters that can be displayed horizontally in the
# editor.
#
@@ -1966,6 +1977,15 @@ class Editor extends Model
shouldAutoIndent: ->
atom.config.get("editor.autoIndent")
shouldShowInvisibles: ->
not @mini and atom.config.get('editor.showInvisibles')
updateInvisibles: ->
if @shouldShowInvisibles()
@displayBuffer.setInvisibles(atom.config.get('editor.invisibles'))
else
@displayBuffer.setInvisibles(null)
# Public: Batch multiple operations as a single undo/redo step.
#
# Any group of operations that are logically grouped from the perspective of

View File

@@ -30,6 +30,7 @@ class ReactEditorView extends View
softWrap: false
tabLength: 2
softTabs: true
mini: mini
props = defaults({@editor, parentView: this}, props)
@component = React.renderComponent(EditorComponent(props), @element)

View File

@@ -19,10 +19,8 @@ class TokenizedBuffer extends Model
invalidRows: null
visible: false
constructor: ({@buffer, @tabLength}) ->
constructor: ({@buffer, @tabLength, @invisibles}) ->
@tabLength ?= atom.config.getPositiveInt('editor.tabLength', 2)
@setShowInvisibles(atom.config.get('editor.showInvisibles'))
@setInvisibles(atom.config.get('editor.invisibles'))
@subscribe atom.syntax, 'grammar-added grammar-updated', (grammar) =>
if grammar.injectionSelector?
@@ -42,14 +40,6 @@ class TokenizedBuffer extends Model
@subscribe atom.config.observe 'editor.tabLength', callNow: false, =>
@setTabLength(atom.config.getPositiveInt('editor.tabLength', 2))
@subscribe atom.config.observe 'editor.showInvisibles', callNow: false, (showInvisibles) =>
@setShowInvisibles(showInvisibles)
@retokenizeLines()
@subscribe atom.config.observe 'editor.invisibles', callNow: false, (invisibles) =>
@setInvisibles(invisibles)
@retokenizeLines()
@reloadGrammar()
serializeParams: ->
@@ -102,9 +92,10 @@ class TokenizedBuffer extends Model
# tabLength - A {Number} that defines the new tab length.
setTabLength: (@tabLength) ->
setShowInvisibles: (@showInvisibles) ->
setInvisibles: (@invisibles={}) ->
setInvisibles: (invisibles) ->
if invisibles isnt @invisibles
@invisibles = invisibles
@retokenizeLines()
tokenizeInBackground: ->
return if not @visible or @pendingChunk or not @isAlive()
@@ -219,17 +210,15 @@ class TokenizedBuffer extends Model
tabLength = @getTabLength()
indentLevel = @indentLevelForRow(row)
lineEnding = @buffer.lineEndingForRow(row)
invisibles = @invisibles if @showInvisibles
new TokenizedLine({tokens, tabLength, indentLevel, invisibles, lineEnding})
new TokenizedLine({tokens, tabLength, indentLevel, @invisibles, lineEnding})
buildTokenizedTokenizedLineForRow: (row, ruleStack) ->
line = @buffer.lineForRow(row)
lineEnding = @buffer.lineEndingForRow(row)
tabLength = @getTabLength()
indentLevel = @indentLevelForRow(row)
invisibles = @invisibles if @showInvisibles
{tokens, ruleStack} = @grammar.tokenizeLine(line, ruleStack, row is 0)
new TokenizedLine({tokens, ruleStack, tabLength, lineEnding, indentLevel, invisibles})
new TokenizedLine({tokens, ruleStack, tabLength, lineEnding, indentLevel, @invisibles})
# FIXME: benogle says: These are actually buffer rows as all buffer rows are
# accounted for in @tokenizedLines