mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Use screen position for gutter highlighting
This commit is contained in:
committed by
Kevin Sawicki
parent
83ddcde88a
commit
2863d92ce3
@@ -1589,18 +1589,38 @@ 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"
|
||||
describe "when there is no wrapping", ->
|
||||
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"
|
||||
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 "when there is wrapping", ->
|
||||
beforeEach ->
|
||||
editor.attachToDom(30)
|
||||
editor.setSoftWrap(true)
|
||||
setEditorWidthInChars(editor, 20)
|
||||
|
||||
fit "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", ->
|
||||
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 ->
|
||||
|
||||
@@ -9,7 +9,7 @@ class Gutter extends View
|
||||
@div class: 'gutter', =>
|
||||
@div outlet: 'lineNumbers', class: 'line-numbers'
|
||||
|
||||
cursorBufferRow: -1
|
||||
cursorScreenRow: -1
|
||||
firstScreenRow: -1
|
||||
|
||||
afterAttach: (onDom) ->
|
||||
@@ -21,13 +21,13 @@ class Gutter extends View
|
||||
renderLineNumbers: (startScreenRow, endScreenRow) ->
|
||||
@firstScreenRow = startScreenRow
|
||||
lastScreenRow = -1
|
||||
currentCursorBufferRow = @cursorBufferRow
|
||||
cursorScreenRow = @cursorScreenRow
|
||||
rows = @editor().bufferRowsForScreenRows(startScreenRow, endScreenRow)
|
||||
|
||||
@lineNumbers[0].innerHTML = $$$ ->
|
||||
for row in rows
|
||||
rowClass = null
|
||||
if row isnt currentCursorBufferRow
|
||||
if row isnt cursorScreenRow or row == lastScreenRow
|
||||
rowClass = 'line-number'
|
||||
else
|
||||
rowClass = 'line-number cursor-line-number'
|
||||
@@ -45,11 +45,9 @@ class Gutter extends View
|
||||
@widthChanged?(@outerWidth())
|
||||
|
||||
highlightCursorLine: ->
|
||||
return if @firstScreenRow < 0
|
||||
|
||||
newCursorBufferRow = @editor().getCursorBufferPosition().row
|
||||
if newCursorBufferRow isnt @cursorBufferRow
|
||||
@cursorBufferRow = newCursorBufferRow
|
||||
screenRow = @cursorBufferRow - @firstScreenRow
|
||||
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(#{screenRow})").addClass('cursor-line-number')
|
||||
@find(".line-number:eq(#{screenRowIndex})").addClass('cursor-line-number')
|
||||
|
||||
Reference in New Issue
Block a user