All tests passing. Editor gets lines from LineWrapper.

Line wrapping still not fully functional. Need to fix many aspects of the LineWrapper integration.
This commit is contained in:
Nathan Sobo
2012-02-10 10:50:01 -07:00
parent 5809a59e7a
commit 9fef75cb5f
3 changed files with 13 additions and 14 deletions

View File

@@ -57,6 +57,7 @@ describe "Editor", ->
editor.setSoftWrap(true)
it "wraps lines that are too long to fit within the editor's width, adjusting cursor positioning accordingly", ->
expect(editor.lines.find('.line').length).toBe 16
expect(editor.lines.find('pre:eq(3)').text()).toBe " var pivot = items.shift(), current, left = [], "
expect(editor.lines.find('pre:eq(4)').text()).toBe "right = [];"

View File

@@ -4,7 +4,7 @@ Highlighter = require 'highlighter'
Range = require 'range'
_ = require 'underscore'
fdescribe "LineWrapper", ->
describe "LineWrapper", ->
[wrapper, buffer] = []
beforeEach ->

View File

@@ -114,22 +114,20 @@ class Editor extends View
@on 'mousemove', moveHandler
$(document).one 'mouseup', => @off 'mousemove', moveHandler
buildLineElement: (row) ->
segments = @lineWrapper.segmentsForRow(row)
buildLineElement: (screenRow) ->
tokens = @lineWrapper.tokensForScreenRow(screenRow)
$$ ->
for segment in segments
@pre class: 'line', =>
if segment.length
for token in segment
@span { class: token.type.replace('.', ' ') }, token.value
else
@raw ' '
@pre class: 'line', =>
if tokens.length
for token in tokens
@span { class: token.type.replace('.', ' ') }, token.value
else
@raw ' '
renderLines: ->
@lines.empty()
for row in [0..@buffer.lastRow()]
line = @buildLineElement(row)
@lines.append line
for screenRow in [0...@lineWrapper.screenLineCount()]
@lines.append @buildLineElement(screenRow)
setBuffer: (@buffer) ->
@highlighter = new Highlighter(@buffer)
@@ -192,7 +190,7 @@ class Editor extends View
new Point(row, column)
pixelPositionFromPoint: (position) ->
{ row, column } = @lineWrapper.displayPositionFromBufferPosition(position)
{ row, column } = @lineWrapper.screenPositionFromBufferPosition(position)
{ top: row * @lineHeight, left: column * @charWidth }
pointFromPixelPosition: ({top, left}) ->