mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Highlight the line number of the current cursor row
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -26,6 +26,10 @@
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.line-number.cursor-line-number {
|
||||
color: rgba(255, 255, 255, .6);
|
||||
}
|
||||
|
||||
.editor.mini .gutter {
|
||||
display: none;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user