From a1cff240b6ea86d7992b899b0ae5103867c76142 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 14 Nov 2012 21:43:06 -0700 Subject: [PATCH] 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. --- spec/app/editor-spec.coffee | 8 ++++---- src/app/cursor-view.coffee | 12 +++--------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index b190e4f54..458366d1d 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -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", -> diff --git a/src/app/cursor-view.coffee b/src/app/cursor-view.coffee index 9495144ae..26d6c7759 100644 --- a/src/app/cursor-view.coffee +++ b/src/app/cursor-view.coffee @@ -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: ->