Create method getTokenizedBuffer() on language mode

Instead of assigning a tokenizedBuffer property on LanguageMode instances from the TokenizedBuffer constructor.
This commit is contained in:
Corey Johnson
2012-10-29 11:54:04 -07:00
parent 82e0a458fa
commit 1924e92727
2 changed files with 12 additions and 7 deletions

View File

@@ -5,6 +5,9 @@ require 'underscore-extensions'
module.exports =
class LanguageMode
buffer = null
grammar = null
editSession = null
pairedCharacters:
'(': ')'
'[': ']'
@@ -24,7 +27,7 @@ class LanguageMode
nextCharachter = @editSession.getTextInBufferRange([cursorBufferPosition, cursorBufferPosition.add([0,1])])
hasWordAfterCursor = /\w/.test(nextCharachter)
cursorInsideString = @tokenizedBuffer.isBufferPositionInsideString(cursorBufferPosition)
cursorInsideString = @getTokenizedBuffer().isBufferPositionInsideString(cursorBufferPosition)
autoCompleteOpeningBracket = @isOpeningBracket(text) and not hasWordAfterCursor and not cursorInsideString
skipOverExistingClosingBracket = false
@@ -44,6 +47,9 @@ class LanguageMode
@bracketAnchorRanges.push @editSession.addAnchorRange(range)
false
getTokenizedBuffer: ->
@editSession.tokenizedBuffer
isOpeningBracket: (string) ->
@pairedCharacters[string]?
@@ -60,7 +66,7 @@ class LanguageMode
toggleLineCommentsInRange: (range) ->
range = Range.fromObject(range)
scopes = @tokenizedBuffer.scopesForPosition(range.start)
scopes = @getTokenizedBuffer().scopesForPosition(range.start)
return unless commentString = TextMateBundle.lineCommentStringForScope(scopes[0])
commentRegexString = _.escapeRegExp(commentString)
@@ -87,7 +93,7 @@ class LanguageMode
return null unless @doesBufferRowStartFold(bufferRow)
startIndentLevel = @editSession.indentationForBufferRow(bufferRow)
scopes = @tokenizedBuffer.scopesForPosition([bufferRow, 0])
scopes = @getTokenizedBuffer().scopesForPosition([bufferRow, 0])
for row in [(bufferRow + 1)..@editSession.getLastBufferRow()]
continue if @editSession.isBufferRowBlank(row)
indentation = @editSession.indentationForBufferRow(row)
@@ -102,7 +108,7 @@ class LanguageMode
suggestedIndentForBufferRow: (bufferRow) ->
currentIndentLevel = @editSession.indentationForBufferRow(bufferRow)
scopes = @tokenizedBuffer.scopesForPosition([bufferRow, 0])
scopes = @getTokenizedBuffer().scopesForPosition([bufferRow, 0])
return currentIndentLevel unless increaseIndentPattern = TextMateBundle.indentRegexForScope(scopes[0])
currentLine = @buffer.lineForRow(bufferRow)
@@ -131,7 +137,7 @@ class LanguageMode
return unless precedingRow?
precedingLine = @editSession.lineForBufferRow(precedingRow)
scopes = @tokenizedBuffer.scopesForPosition([precedingRow, Infinity])
scopes = @getTokenizedBuffer().scopesForPosition([precedingRow, Infinity])
increaseIndentPattern = TextMateBundle.indentRegexForScope(scopes[0])
return unless increaseIndentPattern
@@ -142,7 +148,7 @@ class LanguageMode
@editSession.setIndentationForBufferRow(bufferRow, desiredIndentLevel)
autoDecreaseIndentForBufferRow: (bufferRow) ->
scopes = @tokenizedBuffer.scopesForPosition([bufferRow, 0])
scopes = @getTokenizedBuffer().scopesForPosition([bufferRow, 0])
increaseIndentPattern = TextMateBundle.indentRegexForScope(scopes[0])
decreaseIndentPattern = TextMateBundle.outdentRegexForScope(scopes[0])
return unless increaseIndentPattern and decreaseIndentPattern

View File

@@ -17,7 +17,6 @@ class TokenizedBuffer
constructor: (@buffer, { @languageMode, @tabLength }) ->
@tabLength ?= 2
@languageMode.tokenizedBuffer = this
@id = @constructor.idCounter++
@screenLines = @buildScreenLinesForRows(0, @buffer.getLastRow())
@buffer.on "change.tokenized-buffer#{@id}", (e) => @handleBufferChange(e)