mirror of
https://github.com/atom/atom.git
synced 2026-02-06 04:34:55 -05:00
Allow setting of invisibles on editor
This commit is contained in:
@@ -271,6 +271,9 @@ class Editor extends View
|
||||
@showInvisibles = showInvisibles
|
||||
@renderLines()
|
||||
|
||||
setInvisibles: (@invisibles={}) ->
|
||||
@renderLines()
|
||||
|
||||
setText: (text) -> @getBuffer().setText(text)
|
||||
getText: -> @getBuffer().getText()
|
||||
getPath: -> @getBuffer().getPath()
|
||||
@@ -365,6 +368,7 @@ class Editor extends View
|
||||
@calculateDimensions()
|
||||
@hiddenInput.width(@charWidth)
|
||||
@setSoftWrapColumn() if @activeEditSession.getSoftWrap()
|
||||
@invisibles = @rootView()?.getInvisibles()
|
||||
$(window).on "resize.editor#{@id}", =>
|
||||
@updateRenderedLines()
|
||||
@focus() if @isFocused
|
||||
@@ -871,6 +875,8 @@ class Editor extends View
|
||||
attributePairs.push "#{attributeName}=\"#{value}\"" for attributeName, value of lineAttributes
|
||||
line.push("<pre #{attributePairs.join(' ')}>")
|
||||
|
||||
invisibles = @invisibles if @showInvisibles
|
||||
|
||||
if screenLine.text == ''
|
||||
line.push(" ") unless @showInvisibles
|
||||
else
|
||||
@@ -880,8 +886,7 @@ class Editor extends View
|
||||
for token in screenLine.tokens
|
||||
updateScopeStack(token.scopes)
|
||||
line.push(token.getValueAsHtml(
|
||||
showInvisibles: @showInvisibles
|
||||
invisiblesMap: @rootView()?.getInvisiblesMap()
|
||||
invisibles: invisibles
|
||||
hasLeadingWhitespace: position < firstNonWhitespacePosition
|
||||
hasTrailingWhitespace: position + token.value.length > firstTrailingWhitespacePosition
|
||||
))
|
||||
@@ -889,8 +894,9 @@ class Editor extends View
|
||||
position += token.value.length
|
||||
|
||||
popScope() while scopeStack.length > 0
|
||||
eolChar = @rootView()?.getInvisiblesMap().eol
|
||||
line.push("<span class='invisible'>#{eolChar}</span>") if @showInvisibles
|
||||
if invisibles?.eol
|
||||
line.push("<span class='invisible'>#{invisibles.eol}</span>")
|
||||
|
||||
line.push('</pre>')
|
||||
line.join('')
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class RootView extends View
|
||||
extensionStates: null
|
||||
fontSize: 20
|
||||
showInvisibles: false
|
||||
invisiblesMap:
|
||||
invisibles:
|
||||
eol: "¬"
|
||||
space: "•"
|
||||
tab: "▸"
|
||||
@@ -234,8 +234,10 @@ class RootView extends View
|
||||
|
||||
getFontSize: -> @fontSize
|
||||
|
||||
setInvisiblesMap: (@invisiblesMap) ->
|
||||
getInvisiblesMap: -> @invisiblesMap
|
||||
setInvisibles: (@invisibles={}) ->
|
||||
editor.setInvisibles(@invisibles) for editor in @getEditors()
|
||||
|
||||
getInvisibles: -> @invisibles
|
||||
|
||||
loadUserConfiguration: ->
|
||||
try
|
||||
|
||||
@@ -40,7 +40,7 @@ class Token
|
||||
isTab: true
|
||||
)
|
||||
|
||||
getValueAsHtml: ({showInvisibles, invisiblesMap, hasLeadingWhitespace, hasTrailingWhitespace})->
|
||||
getValueAsHtml: ({invisibles, hasLeadingWhitespace, hasTrailingWhitespace})->
|
||||
html = @value
|
||||
.replace(/&/g, '&')
|
||||
.replace(/"/g, '"')
|
||||
@@ -48,17 +48,15 @@ class Token
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
|
||||
if showInvisibles
|
||||
if @isTab
|
||||
tabChar = invisiblesMap?.tab
|
||||
html = html.replace(/^./, "<span class='invisible'>#{tabChar}</span>")
|
||||
else
|
||||
spaceChar = invisiblesMap?.space
|
||||
if invisibles
|
||||
if @isTab and invisibles.tab
|
||||
html = html.replace(/^./, "<span class='invisible'>#{invisibles.tab}</span>")
|
||||
else if invisibles.space
|
||||
if hasLeadingWhitespace
|
||||
html = html.replace /^[ ]+/, (match) ->
|
||||
"<span class='invisible'>#{match.replace(/./g, spaceChar)}</span>"
|
||||
"<span class='invisible'>#{match.replace(/./g, invisibles.space)}</span>"
|
||||
if hasTrailingWhitespace
|
||||
html = html.replace /[ ]+$/, (match) ->
|
||||
"<span class='invisible'>#{match.replace(/./g, spaceChar)}</span>"
|
||||
"<span class='invisible'>#{match.replace(/./g, invisibles.space)}</span>"
|
||||
|
||||
html
|
||||
|
||||
Reference in New Issue
Block a user