mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
🐎 Don’t blink cursors when editor isn’t focused
Signed-off-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
committed by
Max Brunsfeld
parent
cd310dbe58
commit
6a9abd1f66
@@ -794,6 +794,8 @@ describe "TextEditorComponent", ->
|
||||
it "blinks cursors when they aren't moving", ->
|
||||
cursorsNode = componentNode.querySelector('.cursors')
|
||||
|
||||
wrapperNode.focus()
|
||||
nextAnimationFrame()
|
||||
expect(cursorsNode.classList.contains('blink-off')).toBe false
|
||||
|
||||
advanceClock(component.cursorBlinkPeriod / 2)
|
||||
@@ -2481,8 +2483,7 @@ describe "TextEditorComponent", ->
|
||||
gutterWidth = componentNode.querySelector('.gutter').offsetWidth
|
||||
componentNode.style.width = gutterWidth + 14 * charWidth + editor.getVerticalScrollbarWidth() + 'px'
|
||||
advanceClock(atom.views.documentPollingInterval)
|
||||
nextAnimationFrame() # won't poll until cursor blinks
|
||||
nextAnimationFrame() # handle update requested by poll
|
||||
nextAnimationFrame()
|
||||
expect(componentNode.querySelector('.line').textContent).toBe "var quicksort "
|
||||
|
||||
it "accounts for the scroll view's padding when determining the wrap location", ->
|
||||
|
||||
@@ -1136,10 +1136,10 @@ describe "TextEditorPresenter", ->
|
||||
expect(stateForCursor(presenter, 0).width).toBe 10
|
||||
|
||||
describe ".cursorsVisible", ->
|
||||
it "alternates between true and false twice per ::cursorBlinkPeriod", ->
|
||||
it "alternates between true and false twice per ::cursorBlinkPeriod when the editor is focused", ->
|
||||
cursorBlinkPeriod = 100
|
||||
cursorBlinkResumeDelay = 200
|
||||
presenter = buildPresenter({cursorBlinkPeriod, cursorBlinkResumeDelay})
|
||||
presenter = buildPresenter({cursorBlinkPeriod, cursorBlinkResumeDelay, focused: true})
|
||||
|
||||
expect(presenter.state.content.cursorsVisible).toBe true
|
||||
expectStateUpdate presenter, -> advanceClock(cursorBlinkPeriod / 2)
|
||||
@@ -1148,11 +1148,25 @@ describe "TextEditorPresenter", ->
|
||||
expect(presenter.state.content.cursorsVisible).toBe true
|
||||
expectStateUpdate presenter, -> advanceClock(cursorBlinkPeriod / 2)
|
||||
expect(presenter.state.content.cursorsVisible).toBe false
|
||||
expectStateUpdate presenter, -> advanceClock(cursorBlinkPeriod / 2)
|
||||
expect(presenter.state.content.cursorsVisible).toBe true
|
||||
|
||||
expectStateUpdate presenter, -> presenter.setFocused(false)
|
||||
expect(presenter.state.content.cursorsVisible).toBe false
|
||||
advanceClock(cursorBlinkPeriod / 2)
|
||||
expect(presenter.state.content.cursorsVisible).toBe false
|
||||
advanceClock(cursorBlinkPeriod / 2)
|
||||
expect(presenter.state.content.cursorsVisible).toBe false
|
||||
|
||||
expectStateUpdate presenter, -> presenter.setFocused(true)
|
||||
expect(presenter.state.content.cursorsVisible).toBe true
|
||||
expectStateUpdate presenter, -> advanceClock(cursorBlinkPeriod / 2)
|
||||
expect(presenter.state.content.cursorsVisible).toBe false
|
||||
|
||||
it "stops alternating for ::cursorBlinkResumeDelay when a cursor moves or a cursor is added", ->
|
||||
cursorBlinkPeriod = 100
|
||||
cursorBlinkResumeDelay = 200
|
||||
presenter = buildPresenter({cursorBlinkPeriod, cursorBlinkResumeDelay})
|
||||
presenter = buildPresenter({cursorBlinkPeriod, cursorBlinkResumeDelay, focused: true})
|
||||
|
||||
expect(presenter.state.content.cursorsVisible).toBe true
|
||||
expectStateUpdate presenter, -> advanceClock(cursorBlinkPeriod / 2)
|
||||
|
||||
@@ -25,7 +25,7 @@ class TextEditorPresenter
|
||||
@observeModel()
|
||||
@observeConfig()
|
||||
@buildState()
|
||||
@startBlinkingCursors()
|
||||
@startBlinkingCursors() if @focused
|
||||
|
||||
destroy: ->
|
||||
@disposables.dispose()
|
||||
@@ -113,7 +113,7 @@ class TextEditorPresenter
|
||||
hiddenInput: {}
|
||||
content:
|
||||
scrollingVertically: false
|
||||
cursorsVisible: true
|
||||
cursorsVisible: false
|
||||
lines: {}
|
||||
highlights: {}
|
||||
overlays: {}
|
||||
@@ -507,6 +507,10 @@ class TextEditorPresenter
|
||||
setFocused: (focused) ->
|
||||
unless @focused is focused
|
||||
@focused = focused
|
||||
if @focused
|
||||
@startBlinkingCursors()
|
||||
else
|
||||
@stopBlinkingCursors(false)
|
||||
@updateFocusedState()
|
||||
@updateHiddenInputState()
|
||||
|
||||
@@ -977,18 +981,22 @@ class TextEditorPresenter
|
||||
@updateCursorState(cursor)
|
||||
|
||||
startBlinkingCursors: ->
|
||||
@toggleCursorBlinkHandle = setInterval(@toggleCursorBlink.bind(this), @getCursorBlinkPeriod() / 2)
|
||||
unless @toggleCursorBlinkHandle
|
||||
@state.content.cursorsVisible = true
|
||||
@toggleCursorBlinkHandle = setInterval(@toggleCursorBlink.bind(this), @getCursorBlinkPeriod() / 2)
|
||||
|
||||
stopBlinkingCursors: ->
|
||||
clearInterval(@toggleCursorBlinkHandle)
|
||||
stopBlinkingCursors: (visible) ->
|
||||
if @toggleCursorBlinkHandle
|
||||
@state.content.cursorsVisible = visible
|
||||
clearInterval(@toggleCursorBlinkHandle)
|
||||
@toggleCursorBlinkHandle = null
|
||||
|
||||
toggleCursorBlink: ->
|
||||
@state.content.cursorsVisible = not @state.content.cursorsVisible
|
||||
@emitter.emit 'did-update-state'
|
||||
|
||||
pauseCursorBlinking: ->
|
||||
@state.content.cursorsVisible = true
|
||||
@stopBlinkingCursors()
|
||||
@stopBlinkingCursors(true)
|
||||
@startBlinkingCursorsAfterDelay ?= _.debounce(@startBlinkingCursors, @getCursorBlinkResumeDelay())
|
||||
@startBlinkingCursorsAfterDelay()
|
||||
@emitter.emit 'did-update-state'
|
||||
|
||||
Reference in New Issue
Block a user