Eliminate reference to TokenizedBuffer on EditSession

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-11-06 11:09:38 -08:00
parent 10090219cb
commit 874af0f2bc
5 changed files with 14 additions and 12 deletions

View File

@ -9,7 +9,8 @@ describe "TokenizedBuffer", ->
beforeEach ->
editSession = fixturesProject.buildEditSessionForPath('sample.js', autoIndent: false)
{ tokenizedBuffer, buffer } = editSession
buffer = editSession.buffer
tokenizedBuffer = editSession.displayBuffer.tokenizedBuffer
afterEach ->
editSession.destroy()
@ -157,7 +158,8 @@ describe "TokenizedBuffer", ->
beforeEach ->
tabLength = 2
editSession2 = fixturesProject.buildEditSessionForPath('sample-with-tabs.coffee', { tabLength })
{ buffer, tokenizedBuffer } = editSession2
buffer = editSession2.buffer
tokenizedBuffer = editSession2.displayBuffer.tokenizedBuffer
afterEach ->
editSession2.destroy()

View File

@ -178,6 +178,9 @@ class DisplayBuffer
stateForScreenRow: (screenRow) ->
@tokenizedBuffer.stackForRow(screenRow)
scopesForBufferPosition: (bufferPosition) ->
@tokenizedBuffer.scopesForPosition(bufferPosition)
clipScreenPosition: (position, options) ->
@lineMap.clipScreenPosition(position, options)

View File

@ -44,7 +44,6 @@ class EditSession
@softTabs = @buffer.usesSoftTabs() ? softTabs ? true
@languageMode = new LanguageMode(this, @buffer.getExtension())
@displayBuffer = new DisplayBuffer(@buffer, { @languageMode, @tabLength })
@tokenizedBuffer = @displayBuffer.tokenizedBuffer
@anchors = []
@anchorRanges = []
@cursors = []
@ -157,6 +156,7 @@ class EditSession
maxScreenLineLength: -> @displayBuffer.maxLineLength()
getLastScreenRow: -> @displayBuffer.getLastRow()
bufferRowsForScreenRows: (startRow, endRow) -> @displayBuffer.bufferRowsForScreenRows(startRow, endRow)
scopesForBufferPosition: (bufferPosition) -> @displayBuffer.scopesForBufferPosition(bufferPosition)
logScreenLines: (start, end) -> @displayBuffer.logLines(start, end)
insertText: (text, options) ->

View File

@ -253,7 +253,7 @@ class Editor extends View
stateForScreenRow: (row) -> @activeEditSession.stateForScreenRow(row)
logCursorScope: ->
console.log @activeEditSession.tokenizedBuffer.scopesForPosition(@getCursorBufferPosition())
console.log @activeEditSession.scopesForBufferPosition(@getCursorBufferPosition())
pageDown: ->
newScrollTop = @scrollTop() + @scrollView[0].clientHeight

View File

@ -48,9 +48,6 @@ class LanguageMode
@bracketAnchorRanges.push @editSession.addAnchorRange(range)
false
getTokenizedBuffer: ->
@editSession.tokenizedBuffer
isQuote: (string) ->
/'|"/.test(string)
@ -69,7 +66,7 @@ class LanguageMode
@invertedPairedCharacters
toggleLineCommentsForBufferRows: (start, end) ->
scopes = @getTokenizedBuffer().scopesForPosition([start, 0])
scopes = @editSession.scopesForBufferPosition([start, 0])
return unless commentString = TextMateBundle.lineCommentStringForScope(scopes[0])
commentRegexString = _.escapeRegExp(commentString)
@ -96,7 +93,7 @@ class LanguageMode
return null unless @doesBufferRowStartFold(bufferRow)
startIndentLevel = @editSession.indentationForBufferRow(bufferRow)
scopes = @getTokenizedBuffer().scopesForPosition([bufferRow, 0])
scopes = @editSession.scopesForBufferPosition([bufferRow, 0])
for row in [(bufferRow + 1)..@editSession.getLastBufferRow()]
continue if @editSession.isBufferRowBlank(row)
indentation = @editSession.indentationForBufferRow(row)
@ -111,7 +108,7 @@ class LanguageMode
suggestedIndentForBufferRow: (bufferRow) ->
currentIndentLevel = @editSession.indentationForBufferRow(bufferRow)
scopes = @getTokenizedBuffer().scopesForPosition([bufferRow, 0])
scopes = @editSession.scopesForBufferPosition([bufferRow, 0])
return currentIndentLevel unless increaseIndentPattern = TextMateBundle.indentRegexForScope(scopes[0])
currentLine = @buffer.lineForRow(bufferRow)
@ -140,7 +137,7 @@ class LanguageMode
return unless precedingRow?
precedingLine = @editSession.lineForBufferRow(precedingRow)
scopes = @getTokenizedBuffer().scopesForPosition([precedingRow, Infinity])
scopes = @editSession.scopesForBufferPosition([precedingRow, Infinity])
increaseIndentPattern = TextMateBundle.indentRegexForScope(scopes[0])
return unless increaseIndentPattern
@ -151,7 +148,7 @@ class LanguageMode
@editSession.setIndentationForBufferRow(bufferRow, desiredIndentLevel)
autoDecreaseIndentForBufferRow: (bufferRow) ->
scopes = @getTokenizedBuffer().scopesForPosition([bufferRow, 0])
scopes = @editSession.scopesForBufferPosition([bufferRow, 0])
increaseIndentPattern = TextMateBundle.indentRegexForScope(scopes[0])
decreaseIndentPattern = TextMateBundle.outdentRegexForScope(scopes[0])
return unless increaseIndentPattern and decreaseIndentPattern