Introduce LanguageMode wrapper for Ace modes as a foundation of our own modes

LanguageMode is the central point for all language-specific behavior associated with an EditSession. There is one LanguageMode instance per EditSession. LanguageMode has access to the EditSession and its TokenizedBuffer, and in reverse the EditSession, DisplayBuffer, and TokenizedBuffer also make use of LanguageMode. This is a bit incestuous, but I think it's okay because you can think of LanguageMode as a swappable strategy object that governs language-specific aspects of that constellation of objects.
This commit is contained in:
Nathan Sobo
2012-07-27 12:30:06 -06:00
parent 79893d96b6
commit 3516dea210
10 changed files with 192 additions and 166 deletions

View File

@@ -1,6 +1,7 @@
Point = require 'point'
Buffer = require 'buffer'
Anchor = require 'anchor'
LanguageMode = require 'language-mode'
DisplayBuffer = require 'display-buffer'
Cursor = require 'cursor'
Selection = require 'selection'
@@ -22,6 +23,7 @@ class EditSession
scrollTop: 0
scrollLeft: 0
languageMode: null
displayBuffer: null
anchors: null
anchorRanges: null
@@ -34,7 +36,8 @@ class EditSession
constructor: ({@project, @buffer, @tabText, @autoIndent, @softTabs, @softWrap}) ->
@id = @constructor.idCounter++
@softTabs ?= true
@displayBuffer = new DisplayBuffer(@buffer, { @tabText })
@languageMode = new LanguageMode(this, @buffer.getExtension())
@displayBuffer = new DisplayBuffer(@buffer, { @languageMode, @tabText })
@tokenizedBuffer = @displayBuffer.tokenizedBuffer
@anchors = []
@anchorRanges = []
@@ -242,17 +245,17 @@ class EditSession
@displayBuffer.largestFoldStartingAtScreenRow(screenRow)
indentationForRow: (row) ->
@tokenizedBuffer.indentationForRow(row)
@languageMode.indentationForRow(row)
autoIndentTextAfterBufferPosition: (text, bufferPosition) ->
return { text } unless @autoIndent
@tokenizedBuffer.autoIndentTextAfterBufferPosition(text, bufferPosition)
@languageMode.autoIndentTextAfterBufferPosition(text, bufferPosition)
autoOutdentBufferRow: (bufferRow) ->
@tokenizedBuffer.autoOutdentBufferRow(bufferRow)
@languageMode.autoOutdentBufferRow(bufferRow)
toggleLineCommentsInRange: (range) ->
@tokenizedBuffer.toggleLineCommentsInRange(range)
@languageMode.toggleLineCommentsInRange(range)
mutateSelectedText: (fn) ->
@transact => fn(selection) for selection in @getSelections()