mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04: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
@@ -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