Add Editor.setShowInvisibles and remove showInvisibles from EditSession

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-10-18 14:10:36 -07:00
parent ae0a60f4a9
commit a72d0399f7
5 changed files with 22 additions and 21 deletions

View File

@@ -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 ->

View File

@@ -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())

View File

@@ -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("&nbsp;") unless @activeEditSession.showInvisibles
line.push("&nbsp;") 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('')

View File

@@ -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...)

View File

@@ -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