mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Create method getTokenizedBuffer() on language mode
Instead of assigning a tokenizedBuffer property on LanguageMode instances from the TokenizedBuffer constructor.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user