Selections render correctly with wrapped lines.

This commit is contained in:
Nathan Sobo
2012-02-10 11:32:46 -07:00
parent ea4f122e19
commit 80d42ddb46
2 changed files with 10 additions and 2 deletions

View File

@@ -56,7 +56,7 @@ describe "Editor", ->
editor.width(editor.charWidth * 50)
editor.setSoftWrap(true)
it "wraps lines that are too long to fit within the editor's width, adjusting cursor positioning accordingly", ->
fit "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 = [];"
@@ -67,6 +67,11 @@ describe "Editor", ->
editor.cursor.setPosition([4, 0])
expect(editor.cursor.position()).toEqual(editor.lines.find('pre:eq(5)').position())
editor.selection.setRange(new Range([6, 30], [6, 55]))
[region1, region2] = editor.selection.regions
expect(region1.position().top).toBe(editor.lines.find('.line:eq(7)').position().top)
expect(region2.position().top).toBe(editor.lines.find('.line:eq(8)').position().top)
# Many more tests for change events in the LineWrapper spec
it "handles changes to wrapped lines correctly", ->
buffer.insert([6, 28], '1234567')

View File

@@ -27,7 +27,7 @@ class Selection extends View
updateAppearance: ->
@clearRegions()
range = @getRange()
range = @getScreenRange()
return if range.isEmpty()
rowSpan = range.end.row - range.start.row
@@ -70,6 +70,9 @@ class Selection extends View
@modifySelection =>
@cursor.setPosition(range.end)
getScreenRange: ->
@editor.lineWrapper.screenRangeFromBufferRange(@getRange())
getText: ->
@editor.buffer.getTextInRange @getRange()