Install the LineFolder into the editor

LineWrapper now takes a LineFolder instead of a Highlighter. It's a
cascade of processing steps.
This commit is contained in:
Nathan Sobo 2012-02-23 22:19:42 -07:00
parent 8eed1a4c94
commit 0bdc45037f
3 changed files with 12 additions and 7 deletions

View File

@ -1,6 +1,7 @@
Buffer = require 'buffer'
LineWrapper = require 'line-wrapper'
Buffer = require 'buffer'
Highlighter = require 'highlighter'
LineFolder = require 'line-folder'
Range = require 'range'
ScreenLineFragment = require 'screen-line-fragment'
_ = require 'underscore'
@ -10,7 +11,9 @@ describe "LineWrapper", ->
beforeEach ->
buffer = new Buffer(require.resolve('fixtures/sample.js'))
wrapper = new LineWrapper(50, new Highlighter(buffer))
highlighter = new Highlighter(buffer)
folder = new LineFolder(highlighter)
wrapper = new LineWrapper(50, folder)
changeHandler = jasmine.createSpy('changeHandler')
wrapper.on 'change', changeHandler

View File

@ -4,6 +4,7 @@ Point = require 'point'
Cursor = require 'cursor'
Selection = require 'selection'
Highlighter = require 'highlighter'
LineFolder = require 'line-folder'
LineWrapper = require 'line-wrapper'
UndoManager = require 'undo-manager'
Range = require 'range'
@ -134,7 +135,8 @@ class Editor extends View
setBuffer: (@buffer) ->
@highlighter = new Highlighter(@buffer)
@lineWrapper = new LineWrapper(Infinity, @highlighter)
@lineFolder = new LineFolder(@highlighter)
@lineWrapper = new LineWrapper(Infinity, @lineFolder)
@undoManager = new UndoManager(@buffer)
@renderLines()
@setCursorPosition(row: 0, column: 0)

View File

@ -6,9 +6,9 @@ Range = require 'range'
module.exports =
class LineWrapper
constructor: (@maxLength, @highlighter) ->
constructor: (@maxLength, @lineFolder) ->
@buildLineMap()
@highlighter.on 'change', (e) => @handleChange(e)
@lineFolder.on 'change', (e) => @handleChange(e)
setMaxLength: (@maxLength) ->
oldRange = @rangeForAllLines()
@ -18,7 +18,7 @@ class LineWrapper
buildLineMap: ->
@lineMap = new LineMap
@lineMap.insertAtBufferRow 0, @buildScreenLinesForBufferRows(0, @highlighter.lastRow())
@lineMap.insertAtBufferRow 0, @buildScreenLinesForBufferRows(0, @lineFolder.lastRow())
handleChange: (e) ->
oldBufferRange = e.oldRange
@ -41,7 +41,7 @@ class LineWrapper
new Range([0, 0], [endRow, endColumn])
buildScreenLinesForBufferRows: (start, end) ->
_(@highlighter
_(@lineFolder
.linesForScreenRows(start, end)
.map((screenLine) => @wrapScreenLine(screenLine))).flatten()