No longer cache cursorScreenRow in gutter highlighting

This commit is contained in:
Corey Johnson & Kevin Sawicki
2012-09-28 15:18:33 -07:00
committed by Kevin Sawicki
parent 2863d92ce3
commit e15694bb41
2 changed files with 15 additions and 14 deletions

View File

@@ -1609,13 +1609,13 @@ describe "Editor", ->
editor.setSoftWrap(true)
setEditorWidthInChars(editor, 20)
fit "highlights the line where the initial cursor position is", ->
it "highlights the line where the initial cursor position is", ->
{ row, column } = editor.getCursorBufferPosition()
expect(row).toBe 0
expect(editor.find('.line-number.cursor-line-number').length).toBe 1
expect(editor.find('.line-number.cursor-line-number').text()).toBe "1"
fit "updates the highlighted line when the cursor position changes", ->
it "updates the highlighted line when the cursor position changes", ->
editor.setCursorBufferPosition([1,0])
{ row, column } = editor.getCursorBufferPosition()
expect(row).toBe 1

View File

@@ -9,7 +9,6 @@ class Gutter extends View
@div class: 'gutter', =>
@div outlet: 'lineNumbers', class: 'line-numbers'
cursorScreenRow: -1
firstScreenRow: -1
afterAttach: (onDom) ->
@@ -21,17 +20,21 @@ class Gutter extends View
renderLineNumbers: (startScreenRow, endScreenRow) ->
@firstScreenRow = startScreenRow
lastScreenRow = -1
cursorScreenRow = @cursorScreenRow
rows = @editor().bufferRowsForScreenRows(startScreenRow, endScreenRow)
cursorScreenRow = @editor().getCursorScreenPosition().row
@lineNumbers[0].innerHTML = $$$ ->
for row in rows
rowClass = null
if row isnt cursorScreenRow or row == lastScreenRow
rowClass = 'line-number'
rowClass = 'line-number'
rowValue = null
if row == lastScreenRow
rowValue = ''
else
rowClass = 'line-number cursor-line-number'
@div {class: rowClass}, if row == lastScreenRow then '' else row + 1
rowValue = row + 1
rowClass += ' cursor-line-number' if row == cursorScreenRow
@div {class: rowClass}, rowValue
lastScreenRow = row
@calculateWidth()
@@ -46,8 +49,6 @@ class Gutter extends View
highlightCursorLine: ->
cursorScreenRow = @editor().getCursorScreenPosition().row
if cursorScreenRow isnt @cursorScreenRow
@cursorScreenRow = cursorScreenRow
screenRowIndex = @cursorScreenRow - @firstScreenRow
@find('.line-number.cursor-line-number').removeClass('cursor-line-number')
@find(".line-number:eq(#{screenRowIndex})").addClass('cursor-line-number')
screenRowIndex = cursorScreenRow - @firstScreenRow
@find('.line-number.cursor-line-number').removeClass('cursor-line-number')
@find(".line-number:eq(#{screenRowIndex})").addClass('cursor-line-number')