Use screen rows for line highlight

This commit is contained in:
Kevin Sawicki 2012-09-28 18:39:30 -07:00
parent 2de14a701f
commit d69e08a858
2 changed files with 38 additions and 14 deletions

View File

@ -1622,6 +1622,39 @@ describe "Editor", ->
expect(editor.find('.line-number.cursor-line-number').length).toBe 1
expect(editor.find('.line-number.cursor-line-number').text()).toBe "2"
describe "line highlighting", ->
describe "when there is no wrapping", ->
beforeEach ->
editor.attachToDom(30)
it "highlights the line where the initial cursor position is", ->
expect(editor.getCursorBufferPosition().row).toBe 0
expect(editor.find('.line.cursor-line').length).toBe 1
expect(editor.find('.line.cursor-line').text()).toBe buffer.lineForRow(0)
it "updates the highlighted line when the cursor position changes", ->
editor.setCursorBufferPosition([1,0])
expect(editor.getCursorBufferPosition().row).toBe 1
expect(editor.find('.line.cursor-line').length).toBe 1
expect(editor.find('.line.cursor-line').text()).toBe buffer.lineForRow(1)
describe "when there is wrapping", ->
beforeEach ->
editor.attachToDom(30)
editor.setSoftWrap(true)
setEditorWidthInChars(editor, 20)
it "highlights the line where the initial cursor position is", ->
expect(editor.getCursorBufferPosition().row).toBe 0
expect(editor.find('.line.cursor-line').length).toBe 1
expect(editor.find('.line.cursor-line').text()).toBe 'var quicksort = '
it "updates the highlighted line when the cursor position changes", ->
editor.setCursorBufferPosition([1,0])
expect(editor.getCursorBufferPosition().row).toBe 1
expect(editor.find('.line.cursor-line').length).toBe 1
expect(editor.find('.line.cursor-line').text()).toBe ' var sort = '
describe "folding", ->
beforeEach ->
editSession = rootView.project.buildEditSessionForPath('two-hundred.txt')

View File

@ -36,7 +36,6 @@ class Editor extends View
charWidth: null
charHeight: null
cursorViews: null
cursorRow: -1
selectionViews: null
lineCache: null
isFocused: false
@ -813,7 +812,7 @@ class Editor extends View
charHeight = @charHeight
lines = @activeEditSession.linesForScreenRows(startRow, endRow)
activeEditSession = @activeEditSession
cursorRow = @cursorRow
cursorScreenRow = @getCursorScreenPosition().row
buildLineHtml = (line) => @buildLineHtml(line)
$$ -> @raw(buildLineHtml(line)) for line in lines
@ -941,15 +940,7 @@ class Editor extends View
highlightCursorLine: ->
return if @mini
newCursorRow = @getCursorBufferPosition().row
emptySelection = @getSelection().isEmpty()
if emptySelection
if @cursorRow isnt newCursorRow
@cursorRow = newCursorRow
screenRow = newCursorRow - @firstRenderedScreenRow
@find('.line.cursor-line').removeClass('cursor-line')
@find(".line:eq(#{screenRow})").addClass('cursor-line')
else if @cursorRow isnt -1
@find('.line.cursor-line').removeClass('cursor-line')
@cursorRow = -1 if !emptySelection
@cursorScreenRow = @getCursorScreenPosition().row
screenRow = @cursorScreenRow - @firstRenderedScreenRow
@find('.line.cursor-line').removeClass('cursor-line')
@find(".line:eq(#{screenRow})").addClass('cursor-line')