From e15694bb41b7cddd948066b526c020ee2897123d Mon Sep 17 00:00:00 2001 From: Corey Johnson & Kevin Sawicki Date: Fri, 28 Sep 2012 15:18:33 -0700 Subject: [PATCH] No longer cache cursorScreenRow in gutter highlighting --- spec/app/editor-spec.coffee | 4 ++-- src/app/gutter.coffee | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 7a26e903a..e038264bb 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -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 diff --git a/src/app/gutter.coffee b/src/app/gutter.coffee index 30bd51c2b..d3d29b846 100644 --- a/src/app/gutter.coffee +++ b/src/app/gutter.coffee @@ -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')