mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Add Editor.setShowInvisibles and remove showInvisibles from EditSession
This commit is contained in:
@@ -1472,15 +1472,16 @@ describe "Editor", ->
|
||||
expect(editor.renderedLines.find('.line:eq(14)').text()).toBe 'B'
|
||||
expect(editor.renderedLines.find('.line:eq(15)')).not.toExist()
|
||||
|
||||
describe "when editSession.showInvisibles is true", ->
|
||||
beforeEach ->
|
||||
project.setShowInvisibles(true)
|
||||
rootView.open()
|
||||
editor.attachToDom(5)
|
||||
|
||||
it "displays spaces as •, tabs as ▸ and newlines as ¬", ->
|
||||
describe "when editor.setShowInvisibles is called", ->
|
||||
it "displays spaces as •, tabs as ▸ and newlines as ¬ when true", ->
|
||||
editor.attachToDom()
|
||||
editor.setText " a line with tabs\tand spaces "
|
||||
expect(editor.showInvisibles).toBeFalsy()
|
||||
expect(editor.find('.line').text()).toBe " a line with tabs and spaces "
|
||||
editor.setShowInvisibles(true)
|
||||
expect(editor.find('.line').text()).toBe "•a line with tabs▸ and spaces•¬"
|
||||
editor.setShowInvisibles(false)
|
||||
expect(editor.find('.line').text()).toBe " a line with tabs and spaces "
|
||||
|
||||
describe "gutter rendering", ->
|
||||
beforeEach ->
|
||||
|
||||
@@ -38,9 +38,8 @@ class EditSession
|
||||
tabLength: null
|
||||
softTabs: true
|
||||
softWrap: false
|
||||
showInvisibles: false
|
||||
|
||||
constructor: ({@project, @buffer, @tabLength, @autoIndent, @softTabs, @softWrap, @showInvisibles}) ->
|
||||
constructor: ({@project, @buffer, @tabLength, @autoIndent, @softTabs, @softWrap }) ->
|
||||
@id = @constructor.idCounter++
|
||||
@softTabs ?= true
|
||||
@languageMode = new LanguageMode(this, @buffer.getExtension())
|
||||
|
||||
@@ -46,12 +46,12 @@ class Editor extends View
|
||||
|
||||
@deserialize: (state, rootView) ->
|
||||
editSessions = state.editSessions.map (state) -> EditSession.deserialize(state, rootView.project)
|
||||
editor = new Editor(editSession: editSessions[state.activeEditSessionIndex], mini: state.mini)
|
||||
editor = new Editor(editSession: editSessions[state.activeEditSessionIndex], mini: state.mini, showInvisibles: rootView.showInvisibles)
|
||||
editor.editSessions = editSessions
|
||||
editor.isFocused = state.isFocused
|
||||
editor
|
||||
|
||||
initialize: ({editSession, @mini} = {}) ->
|
||||
initialize: ({editSession, @mini, @showInvisibles} = {}) ->
|
||||
requireStylesheet 'editor.css'
|
||||
|
||||
@id = Editor.idCounter++
|
||||
@@ -265,6 +265,11 @@ class Editor extends View
|
||||
getPageRows: ->
|
||||
Math.max(1, Math.ceil(@scrollView[0].clientHeight / @lineHeight))
|
||||
|
||||
setShowInvisibles: (showInvisibles) ->
|
||||
return if showInvisibles == @showInvisibles
|
||||
@showInvisibles = showInvisibles
|
||||
@renderLines()
|
||||
|
||||
setText: (text) -> @getBuffer().setText(text)
|
||||
getText: -> @getBuffer().getText()
|
||||
getPath: -> @getBuffer().getPath()
|
||||
@@ -569,7 +574,7 @@ class Editor extends View
|
||||
@updateRenderedLines()
|
||||
|
||||
newSplitEditor: ->
|
||||
new Editor { editSession: @activeEditSession.copy() }
|
||||
new Editor { editSession: @activeEditSession.copy(), @showInvisibles }
|
||||
|
||||
splitLeft: ->
|
||||
@pane()?.splitLeft(@newSplitEditor()).wrappedView
|
||||
@@ -874,7 +879,7 @@ class Editor extends View
|
||||
line.push("<pre #{attributePairs.join(' ')}>")
|
||||
|
||||
if screenLine.text == ''
|
||||
line.push(" ") unless @activeEditSession.showInvisibles
|
||||
line.push(" ") unless @showInvisibles
|
||||
else
|
||||
firstNonWhitespacePosition = screenLine.text.search(/\S/)
|
||||
firstTrailingWhitespacePosition = screenLine.text.search(/\s*$/)
|
||||
@@ -882,14 +887,14 @@ class Editor extends View
|
||||
for token in screenLine.tokens
|
||||
updateScopeStack(token.scopes)
|
||||
line.push(token.getValueAsHtml(
|
||||
showInvisibles: @activeEditSession.showInvisibles
|
||||
showInvisibles: @showInvisibles
|
||||
hasLeadingWhitespace: position < firstNonWhitespacePosition
|
||||
hasTrailingWhitespace: position + token.value.length > firstTrailingWhitespacePosition
|
||||
))
|
||||
|
||||
position += token.value.length
|
||||
|
||||
line.push("<span class='invisible'>¬</span>") if @activeEditSession.showInvisibles
|
||||
line.push("<span class='invisible'>¬</span>") if @showInvisibles
|
||||
line.push('</pre>')
|
||||
line.join('')
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ class Project
|
||||
autoIndent: true
|
||||
softTabs: true
|
||||
softWrap: false
|
||||
showInvisibles: false
|
||||
rootDirectory: null
|
||||
editSessions: null
|
||||
ignoredPathRegexes: null
|
||||
@@ -111,9 +110,6 @@ class Project
|
||||
getSoftWrap: -> @softWrap
|
||||
setSoftWrap: (@softWrap) ->
|
||||
|
||||
getShowInvisibles: -> @showInvisibles
|
||||
setShowInvisibles: (@showInvisibles) ->
|
||||
|
||||
buildEditSessionForPath: (filePath, editSessionOptions={}) ->
|
||||
@buildEditSession(@bufferForPath(filePath), editSessionOptions)
|
||||
|
||||
@@ -131,7 +127,6 @@ class Project
|
||||
autoIndent: @getAutoIndent()
|
||||
softTabs: @getSoftTabs()
|
||||
softWrap: @getSoftWrap()
|
||||
showInvisibles: @getShowInvisibles()
|
||||
|
||||
getEditSessions: ->
|
||||
new Array(@editSessions...)
|
||||
|
||||
@@ -31,6 +31,7 @@ class RootView extends View
|
||||
extensions: null
|
||||
extensionStates: null
|
||||
fontSize: 20
|
||||
showInvisibles: false
|
||||
|
||||
initialize: (pathToOpen, { @extensionStates, suppressOpen } = {}) ->
|
||||
window.rootView = this
|
||||
@@ -117,7 +118,7 @@ class RootView extends View
|
||||
|
||||
unless editSession = @openInExistingEditor(path, allowActiveEditorChange, changeFocus)
|
||||
editSession = @project.buildEditSessionForPath(path)
|
||||
editor = new Editor({editSession})
|
||||
editor = new Editor({editSession, @showInvisibles})
|
||||
pane = new Pane(editor)
|
||||
@panes.append(pane)
|
||||
if changeFocus
|
||||
|
||||
Reference in New Issue
Block a user