Highlight the line number of the current cursor row

This commit is contained in:
Kevin Sawicki
2012-09-28 09:52:01 -07:00
parent 2722fe7d72
commit 02fa815459
3 changed files with 33 additions and 0 deletions

View File

@@ -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')

View File

@@ -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')

View File

@@ -26,6 +26,10 @@
position: relative;
}
.line-number.cursor-line-number {
color: rgba(255, 255, 255, .6);
}
.editor.mini .gutter {
display: none;
}