mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -191,6 +191,9 @@ EditorComponent = React.createClass
|
||||
@domPollingIntervalId = null
|
||||
@props.editor.destroy()
|
||||
|
||||
componentWillReceiveProps: (newProps) ->
|
||||
@props.editor.setMini(newProps.mini)
|
||||
|
||||
componentWillUpdate: ->
|
||||
wasVisible = @visible
|
||||
@visible = @isVisible()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user