mirror of
https://github.com/atom/atom.git
synced 2026-02-04 19:54:59 -05:00
Make cursor blink by changing CSS visibility with setInterval
This is actually more efficient than the CSS animation we were doing previously, because it doesn't force the cursor to be sampled at 60 FPS for something that changes around twice a second.
This commit is contained in:
@@ -9,16 +9,19 @@ class CursorView extends View
|
||||
@content: ->
|
||||
@pre class: 'cursor idle', => @raw ' '
|
||||
|
||||
blinkPeriod: 800
|
||||
editor: null
|
||||
visible: true
|
||||
|
||||
needsUpdate: true
|
||||
needsAutoscroll: true
|
||||
needsRemoval: false
|
||||
shouldPauseBlinking: false
|
||||
|
||||
initialize: (@cursor, @editor) ->
|
||||
@cursor.on 'change-screen-position.cursor-view', (screenPosition, { bufferChange, autoscroll }) =>
|
||||
@cursor.on 'change-screen-position.cursor-view', (screenPosition, { autoscroll }) =>
|
||||
@needsUpdate = true
|
||||
@shouldPauseBlinking = true
|
||||
@needsAutoscroll = (autoscroll ? true) and @cursor?.isLastCursor()
|
||||
@editor.requestDisplayUpdate()
|
||||
|
||||
@@ -43,9 +46,13 @@ class CursorView extends View
|
||||
unless _.isEqual(@lastPixelPosition, pixelPosition)
|
||||
changedPosition = true
|
||||
@css(pixelPosition)
|
||||
# @removeIdleClassTemporarily() unless bufferChange
|
||||
@trigger 'cursor-move'
|
||||
|
||||
if @shouldPauseBlinking
|
||||
@resetBlinking()
|
||||
else if !@startBlinkingTimeout
|
||||
@startBlinking()
|
||||
|
||||
@setVisible(@cursor.isVisible() and not @editor.isFoldedAtScreenRow(screenPosition.row))
|
||||
|
||||
getPixelPosition: ->
|
||||
@@ -54,7 +61,27 @@ class CursorView extends View
|
||||
setVisible: (visible) ->
|
||||
unless @visible == visible
|
||||
@visible = visible
|
||||
@toggle(@visible)
|
||||
if @visible
|
||||
@css('visibility', '')
|
||||
else
|
||||
@css('visibility', 'hidden')
|
||||
|
||||
toggleVisible: ->
|
||||
@setVisible(not @visible) if @cursor.isVisible
|
||||
|
||||
stopBlinking: ->
|
||||
clearInterval(@blinkInterval) if @blinkInterval
|
||||
@blinkInterval = null
|
||||
@setVisible(true) if @cursor.isVisible
|
||||
|
||||
startBlinking: ->
|
||||
return if @blinkInterval?
|
||||
blink = => @toggleVisible()
|
||||
@blinkInterval = setInterval(blink, @blinkPeriod / 2)
|
||||
|
||||
resetBlinking: ->
|
||||
@stopBlinking()
|
||||
@startBlinking()
|
||||
|
||||
getBufferPosition: ->
|
||||
@cursor.getBufferPosition()
|
||||
|
||||
@@ -768,7 +768,7 @@ class Editor extends View
|
||||
|
||||
syncCursorAnimations: ->
|
||||
for cursorView in @getCursorViews()
|
||||
do (cursorView) -> cursorView.resetCursorAnimation()
|
||||
do (cursorView) -> cursorView.resetBlinking()
|
||||
|
||||
autoscroll: (options={}) ->
|
||||
for cursorView in @getCursorViews() when cursorView.needsAutoscroll
|
||||
|
||||
Reference in New Issue
Block a user