mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Optimize highlighting of the current line in the gutter
This commit is contained in:
@@ -1683,14 +1683,14 @@ describe "Editor", ->
|
||||
|
||||
it "highlights the line where the initial cursor position is", ->
|
||||
expect(editor.getCursorBufferPosition().row).toBe 0
|
||||
expect(editor.find('.line-number.cursor-line-number.cursor-line-number-background').length).toBe 1
|
||||
expect(editor.find('.line-number.cursor-line-number.cursor-line-number-background').text()).toBe "1"
|
||||
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])
|
||||
expect(editor.getCursorBufferPosition().row).toBe 1
|
||||
expect(editor.find('.line-number.cursor-line-number.cursor-line-number-background').length).toBe 1
|
||||
expect(editor.find('.line-number.cursor-line-number.cursor-line-number-background').text()).toBe "2"
|
||||
expect(editor.find('.line-number.cursor-line-number').length).toBe 1
|
||||
expect(editor.find('.line-number.cursor-line-number').text()).toBe "2"
|
||||
|
||||
describe "when the selection spans multiple lines", ->
|
||||
beforeEach ->
|
||||
@@ -1700,15 +1700,12 @@ describe "Editor", ->
|
||||
editor.getSelection().setBufferRange(new Range([0,0],[2,0]))
|
||||
expect(editor.getSelection().isSingleScreenLine()).toBe false
|
||||
expect(editor.find('.line-number.cursor-line-number').length).toBe 0
|
||||
expect(editor.find('.line-number.cursor-line-number.cursor-line-number-background').length).toBe 0
|
||||
|
||||
it "when a newline is deleted with backspace, the line number of the new cursor position is highlighted", ->
|
||||
editor.setCursorScreenPosition([1,0])
|
||||
editor.backspace()
|
||||
expect(editor.find('.line-number.cursor-line-number').length).toBe 1
|
||||
expect(editor.find('.line-number.cursor-line-number').text()).toBe "1"
|
||||
expect(editor.find('.line-number.cursor-line-number-background').length).toBe 1
|
||||
expect(editor.find('.line-number.cursor-line-number-background').text()).toBe "1"
|
||||
|
||||
describe "line highlighting", ->
|
||||
beforeEach ->
|
||||
|
||||
@@ -59,14 +59,11 @@ class Gutter extends View
|
||||
@widthChanged?(@outerWidth())
|
||||
|
||||
highlightCursorLine: ->
|
||||
cursorScreenRow = @editor().getCursorScreenPosition().row
|
||||
screenRowIndex = cursorScreenRow - @firstScreenRow
|
||||
screenRowIndex = @editor().getCursorScreenPosition().row - @firstScreenRow
|
||||
@highlightedLineNumber?.classList.remove('cursor-line-number')
|
||||
|
||||
currentLineNumberRow = @find(".line-number.cursor-line-number")
|
||||
currentLineNumberRow.removeClass('cursor-line-number')
|
||||
currentLineNumberRow.removeClass('cursor-line-number-background')
|
||||
|
||||
if @editor().getSelection().isSingleScreenLine()
|
||||
newLineNumberRow = @find(".line-number:eq(#{screenRowIndex})")
|
||||
newLineNumberRow.addClass('cursor-line-number')
|
||||
newLineNumberRow.addClass('cursor-line-number-background')
|
||||
if screenRowIndex >= 0 and @editor().getSelection().isSingleScreenLine()
|
||||
@highlightedLineNumber = @lineNumbers[0].children[screenRowIndex]
|
||||
@highlightedLineNumber?.classList.add('cursor-line-number')
|
||||
else
|
||||
@highlightedLineNumber = null
|
||||
|
||||
@@ -31,9 +31,6 @@
|
||||
|
||||
.editor.focused .line-number.cursor-line-number {
|
||||
color: rgba(255, 255, 255, .6);
|
||||
}
|
||||
|
||||
.editor.focused .line.cursor-line, .editor.focused .line-number.cursor-line-number-background {
|
||||
background-color: rgba(255, 255, 255, .12);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user