Use 'blink-off' css class to blink the cursor when editor is focused

Rather than managing the visibility directly, a class makes it easy. The cursors will always be toggling this class on and off in the background, but only on the focused editor will it actually have an effect.
This commit is contained in:
Nathan Sobo
2012-11-14 21:43:06 -07:00
parent 0af952fc13
commit a1cff240b6
2 changed files with 7 additions and 13 deletions

View File

@@ -914,11 +914,11 @@ describe "Editor", ->
editor.setSelectedBufferRange([[0, 0], [3, 0]])
expect(editor.getSelection().isEmpty()).toBeFalsy()
expect(cursorView.css('visibility')).toBe 'hidden'
expect(cursorView).toBeHidden()
editor.setCursorBufferPosition([1, 3])
expect(editor.getSelection().isEmpty()).toBeTruthy()
expect(cursorView.css('visibility')).toBe 'visible'
expect(cursorView).toBeVisible()
describe "auto-scrolling", ->
it "only auto-scrolls when the last cursor is moved", ->
@@ -1773,10 +1773,10 @@ describe "Editor", ->
editor.setCursorScreenPosition([2,0])
expect(editor.lineElementForScreenRow(2)).toMatchSelector('.fold.selected')
expect(editor.find('.cursor').css('visibility')).toBe 'hidden'
expect(editor.find('.cursor')).toBeHidden()
editor.setCursorScreenPosition([3,0])
expect(editor.find('.cursor').css('visibility')).toBe 'visible'
expect(editor.find('.cursor')).toBeVisible()
describe "when a selected fold is scrolled into view (and the fold line was not previously rendered)", ->
it "renders the fold's line element with the 'selected' class", ->

View File

@@ -61,22 +61,16 @@ class CursorView extends View
setVisible: (visible) ->
unless @visible == visible
@visible = visible
if @visible
@css('visibility', '')
else
@css('visibility', 'hidden')
toggleVisible: ->
@setVisible(not @visible)
@toggle(@visible)
stopBlinking: ->
clearInterval(@blinkInterval) if @blinkInterval
@blinkInterval = null
@setVisible(@cursor.isVisible())
this[0].classList.remove('blink-off')
startBlinking: ->
return if @blinkInterval?
blink = => @toggleVisible() if @cursor.isVisible()
blink = => @toggleClass('blink-off')
@blinkInterval = setInterval(blink, @blinkPeriod / 2)
resetBlinking: ->