From 02fa815459605188a21cdec3e9923cb288cc47a1 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 28 Sep 2012 09:52:01 -0700 Subject: [PATCH] Highlight the line number of the current cursor row --- spec/app/editor-spec.coffee | 13 +++++++++++++ src/app/gutter.coffee | 16 ++++++++++++++++ static/editor.css | 4 ++++ 3 files changed, 33 insertions(+) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 1f25c5ab9..783f88c32 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -1576,6 +1576,19 @@ describe "Editor", -> expect(miniEditor.gutter).toBeHidden() expect(miniEditor.scrollView.css('left')).toBe '0px' + 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" + + it "updates the highlighted line when the cursor position changes", -> + editor.setCursorBufferPosition([1,0]) + { row, column } = editor.getCursorBufferPosition() + expect(row).toBe 1 + expect(editor.find('.line-number.cursor-line-number').length).toBe 1 + expect(editor.find('.line-number.cursor-line-number').text()).toBe "2" + describe "folding", -> beforeEach -> editSession = rootView.project.buildEditSessionForPath('two-hundred.txt') diff --git a/src/app/gutter.coffee b/src/app/gutter.coffee index daca70157..c9d827ec2 100644 --- a/src/app/gutter.coffee +++ b/src/app/gutter.coffee @@ -9,10 +9,16 @@ class Gutter extends View @div class: 'gutter', => @div outlet: 'lineNumbers', class: 'line-numbers' + cursorRow: -1 + + afterAttach: (onDom) -> + @editor()?.on 'cursor-move', => @highlightCursorLine() + editor: -> @parentView renderLineNumbers: (startScreenRow, endScreenRow) -> + @firstScreenRow = startScreenRow lastScreenRow = -1 rows = @editor().bufferRowsForScreenRows(startScreenRow, endScreenRow) @@ -22,6 +28,7 @@ class Gutter extends View lastScreenRow = row @calculateWidth() + @highlightCursorLine() calculateWidth: -> width = @editor().getLineCount().toString().length * @editor().charWidth @@ -29,3 +36,12 @@ class Gutter extends View @cachedWidth = width @lineNumbers.width(width) @widthChanged?(@outerWidth()) + + highlightCursorLine: -> + return if @firstScreenRow < 0 + + newCursorRow = @editor().getCursorBufferPosition().row - @firstScreenRow + if newCursorRow isnt cursorRow + cursorRow = newCursorRow + @find('.line-number.cursor-line-number').removeClass('cursor-line-number') + @find(".line-number:eq(#{cursorRow})").addClass('cursor-line-number') diff --git a/static/editor.css b/static/editor.css index 9d43e8c40..5323773da 100644 --- a/static/editor.css +++ b/static/editor.css @@ -26,6 +26,10 @@ position: relative; } +.line-number.cursor-line-number { + color: rgba(255, 255, 255, .6); +} + .editor.mini .gutter { display: none; }