mirror of
https://github.com/atom/atom.git
synced 2026-02-08 13:45:09 -05:00
63 lines
1.6 KiB
CoffeeScript
63 lines
1.6 KiB
CoffeeScript
{View} = require 'space-pen'
|
|
Anchor = require 'anchor'
|
|
Point = require 'point'
|
|
Range = require 'range'
|
|
_ = require 'underscore'
|
|
|
|
module.exports =
|
|
class CursorView extends View
|
|
@content: ->
|
|
@pre class: 'cursor idle', => @raw ' '
|
|
|
|
editor: null
|
|
hidden: false
|
|
|
|
initialize: (@cursor, @editor) ->
|
|
@cursor.on 'change-screen-position.cursor-view', (screenPosition, { bufferChange }) =>
|
|
@updateAppearance()
|
|
@removeIdleClassTemporarily() unless bufferChange
|
|
@trigger 'cursor-move', {bufferChange}
|
|
|
|
@cursor.on 'destroy.cursor-view', => @remove()
|
|
|
|
afterAttach: (onDom) ->
|
|
return unless onDom
|
|
@updateAppearance()
|
|
@editor.syncCursorAnimations()
|
|
|
|
remove: ->
|
|
@editor.removeCursorView(this)
|
|
@cursor.off('.cursor-view')
|
|
super
|
|
|
|
updateAppearance: ->
|
|
screenPosition = @getScreenPosition()
|
|
pixelPosition = @editor.pixelPositionForScreenPosition(screenPosition)
|
|
@css(pixelPosition)
|
|
|
|
if @cursor == @editor.getLastCursor()
|
|
@editor.scrollTo(pixelPosition)
|
|
|
|
if @editor.isFoldedAtScreenRow(screenPosition.row)
|
|
@hide() unless @hidden
|
|
@hidden = true
|
|
else
|
|
@show() if @hidden
|
|
@hidden = false
|
|
|
|
getBufferPosition: ->
|
|
@cursor.getBufferPosition()
|
|
|
|
getScreenPosition: ->
|
|
@cursor.getScreenPosition()
|
|
|
|
removeIdleClassTemporarily: ->
|
|
@removeClass 'idle'
|
|
window.clearTimeout(@idleTimeout) if @idleTimeout
|
|
@idleTimeout = window.setTimeout (=> @addClass 'idle'), 200
|
|
|
|
resetCursorAnimation: ->
|
|
window.clearTimeout(@idleTimeout) if @idleTimeout
|
|
@removeClass 'idle'
|
|
_.defer => @addClass 'idle'
|