Change tabText to tabLength

This commit is contained in:
Corey Johnson
2012-10-11 10:25:04 -07:00
committed by Corey Johnson & Nathan Sobo
parent 1d46b63977
commit e2a917fcf3
16 changed files with 72 additions and 73 deletions

View File

@@ -20,7 +20,6 @@ class DisplayBuffer
constructor: (@buffer, options={}) ->
@id = @constructor.idCounter++
options.tabText ?= ' '
@languageMode = options.languageMode
@tokenizedBuffer = new TokenizedBuffer(@buffer, options)
@softWrapColumn = options.softWrapColumn ? Infinity

View File

@@ -37,12 +37,13 @@ class EditSession
autoIndent: false # TODO: re-enabled auto-indent after fixing the rest of tokenization
softTabs: true
softWrap: false
tabLength: null
constructor: ({@project, @buffer, @tabText, @autoIndent, @softTabs, @softWrap}) ->
constructor: ({@project, @buffer, @tabLength, @autoIndent, @softTabs, @softWrap}) ->
@id = @constructor.idCounter++
@softTabs ?= true
@languageMode = new LanguageMode(this, @buffer.getExtension())
@displayBuffer = new DisplayBuffer(@buffer, { @languageMode, @tabText })
@displayBuffer = new DisplayBuffer(@buffer, { @languageMode, @tabLength })
@tokenizedBuffer = @displayBuffer.tokenizedBuffer
@anchors = []
@anchorRanges = []
@@ -106,6 +107,8 @@ class EditSession
getSoftWrap: -> @softWrap
setSoftWrap: (@softWrap) ->
getTabText: -> new Array(@tabLength + 1).join(" ")
clipBufferPosition: (bufferPosition) ->
@buffer.clipPosition(bufferPosition)
@@ -149,7 +152,7 @@ class EditSession
currentRow = @getCursorBufferPosition().row
if @getSelection().isEmpty()
if @softTabs
@insertText(@tabText)
@insertText(@getTabText())
else
@insertText('\t')
else

View File

@@ -69,7 +69,7 @@ class Editor extends View
editSession = new EditSession
buffer: new Buffer()
softWrap: false
tabText: " "
tabLength: 2
autoIndent: false
softTabs: true
@@ -878,16 +878,8 @@ class Editor extends View
else
for token in screenLine.tokens
updateScopeStack(token.scopes)
line.push(
token.value
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
)
line.push("</pre>")
line.push(token.escapeValue())
line.push('</pre>')
line.join('')
insertLineElements: (row, lineElements) ->

View File

@@ -104,7 +104,7 @@ class LanguageMode
currentIndentation = @buffer.indentationForRow(bufferRow)
desiredIndentation = @buffer.indentationForRow(precedingRow)
desiredIndentation += @editSession.tabText.length if increaseIndentPattern.test(precedingLine)
desiredIndentation += @editSession.tabLength if increaseIndentPattern.test(precedingLine)
if desiredIndentation > currentIndentation
@buffer.setIndentationForRow(bufferRow, desiredIndentation)
@@ -122,7 +122,7 @@ class LanguageMode
precedingLine = @buffer.lineForRow(precedingRow)
desiredIndentation = @buffer.indentationForRow(precedingRow)
desiredIndentation -= @editSession.tabText.length unless increaseIndentPattern.test(precedingLine)
desiredIndentation -= @editSession.tabLength unless increaseIndentPattern.test(precedingLine)
if desiredIndentation < currentIndentation
@buffer.setIndentationForRow(bufferRow, desiredIndentation)

View File

@@ -10,10 +10,11 @@ ChildProcess = require 'child-process'
module.exports =
class Project
tabText: ' '
tabLength: 2
autoIndent: true
softTabs: true
softWrap: false
showInvisibles: false
rootDirectory: null
editSessions: null
ignoredPathRegexes: null
@@ -101,9 +102,6 @@ class Project
relativize: (fullPath) ->
fullPath.replace(@getPath(), "").replace(/^\//, '')
getTabText: -> @tabText
setTabText: (@tabText) ->
getAutoIndent: -> @autoIndent
setAutoIndent: (@autoIndent) ->
@@ -113,6 +111,9 @@ class Project
getSoftWrap: -> @softWrap
setSoftWrap: (@softWrap) ->
getShowInvisibles: -> @showInvisibles
setShowInvisibles: (@showInvisibles) ->
buildEditSessionForPath: (filePath, editSessionOptions={}) ->
@buildEditSession(@bufferForPath(filePath), editSessionOptions)
@@ -126,10 +127,11 @@ class Project
editSession
defaultEditSessionOptions: ->
tabText: @getTabText()
tabLength: @tabLength
autoIndent: @getAutoIndent()
softTabs: @getSoftTabs()
softWrap: @getSoftWrap()
showInvisibles: @getShowInvisibles()
getEditSessions: ->
new Array(@editSessions...)

View File

@@ -208,15 +208,15 @@ class Selection
indentSelectedRows: ->
range = @getBufferRange()
for row in [range.start.row..range.end.row]
@editSession.buffer.insert([row, 0], @editSession.tabText) unless @editSession.buffer.lineLengthForRow(row) == 0
@editSession.buffer.insert([row, 0], @editSession.getTabText()) unless @editSession.buffer.lineLengthForRow(row) == 0
outdentSelectedRows: ->
range = @getBufferRange()
buffer = @editSession.buffer
leadingTabRegex = new RegExp("^#{@editSession.tabText}")
leadingTabRegex = new RegExp("^#{@editSession.getTabText()}")
for row in [range.start.row..range.end.row]
if leadingTabRegex.test buffer.lineForRow(row)
buffer.delete [[row, 0], [row, @editSession.tabText.length]]
buffer.delete [[row, 0], [row, @editSession.tabLength]]
toggleLineComments: ->
@modifySelection =>

View File

@@ -21,14 +21,23 @@ class Token
value2 = @value.substring(splitIndex)
[new Token(value: value1, scopes: @scopes), new Token(value: value2, scopes: @scopes)]
breakOutTabCharacters: (tabText) ->
breakOutTabCharacters: (tabLength) ->
return [this] unless /\t/.test(@value)
for substring in @value.match(/([^\t]+|\t)/g)
if substring == '\t'
@buildTabToken(tabText)
@buildTabToken(tabLength)
else
new Token(value: substring, scopes: @scopes)
buildTabToken: (tabText) ->
buildTabToken: (tabLength) ->
tabText = new Array(tabLength + 1).join(" ")
new Token(value: tabText, scopes: @scopes, bufferDelta: 1, isAtomic: true)
escapeValue: ->
@value
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')

View File

@@ -10,11 +10,13 @@ class TokenizedBuffer
@idCounter: 1
languageMode: null
tabLength: null
buffer: null
aceAdaptor: null
screenLines: null
constructor: (@buffer, { @languageMode, @tabText }) ->
constructor: (@buffer, { @languageMode, @tabLength }) ->
@tabLength ?= 2
@languageMode.tokenizedBuffer = this
@id = @constructor.idCounter++
@screenLines = @buildScreenLinesForRows(0, @buffer.getLastRow())
@@ -64,7 +66,7 @@ class TokenizedBuffer
tokenObjects = []
for tokenProperties in tokens
token = new Token(tokenProperties)
tokenObjects.push(token.breakOutTabCharacters(@tabText)...)
tokenObjects.push(token.breakOutTabCharacters(@tabLength)...)
text = _.pluck(tokenObjects, 'value').join('')
new ScreenLine(tokenObjects, text, [1, 0], [1, 0], { stack })