Add TextEditorPresenter::state.content.blinkCursorsOff

This commit is contained in:
Nathan Sobo
2015-01-23 09:04:32 -07:00
parent 06b5eba17c
commit 3c6c385ec8
2 changed files with 77 additions and 2 deletions

View File

@@ -1,14 +1,19 @@
{CompositeDisposable} = require 'event-kit'
{Point} = require 'text-buffer'
_ = require 'underscore-plus'
module.exports =
class TextEditorPresenter
constructor: ({@model, @clientHeight, @clientWidth, @scrollTop, @scrollLeft, @lineHeight, @baseCharacterWidth, @lineOverdrawMargin}) ->
toggleCursorBlinkHandle: null
startBlinkingCursorsAfterDelay: null
constructor: ({@model, @clientHeight, @clientWidth, @scrollTop, @scrollLeft, @lineHeight, @baseCharacterWidth, @lineOverdrawMargin, @cursorBlinkPeriod, @cursorBlinkResumeDelay}) ->
@disposables = new CompositeDisposable
@charWidthsByScope = {}
@observeModel()
@observeConfig()
@buildState()
@startBlinkingCursors()
destroy: ->
@disposables.dispose()
@@ -41,6 +46,7 @@ class TextEditorPresenter
@updateLinesState()
buildCursorsState: ->
@state.content.blinkCursorsOff = false
@state.content.cursors = {}
@updateCursorsState()
@@ -145,6 +151,10 @@ class TextEditorPresenter
decorationClasses
getCursorBlinkPeriod: -> @cursorBlinkPeriod
getCursorBlinkResumeDelay: -> @cursorBlinkResumeDelay
setScrollTop: (@scrollTop) ->
@updateContentState()
@updateLinesState()
@@ -275,8 +285,12 @@ class TextEditorPresenter
@updateLinesState()
observeCursor: (cursor) ->
didChangePositionDisposable = cursor.onDidChangePosition(@updateCursorsState.bind(this))
didChangePositionDisposable = cursor.onDidChangePosition =>
@pauseCursorBlinking()
@updateCursorsState()
didChangeVisibilityDisposable = cursor.onDidChangeVisibility(@updateCursorsState.bind(this))
didDestroyDisposable = cursor.onDidDestroy =>
@disposables.remove(didChangePositionDisposable)
@disposables.remove(didChangeVisibilityDisposable)
@@ -289,4 +303,20 @@ class TextEditorPresenter
didAddCursor: (cursor) ->
@observeCursor(cursor)
@pauseCursorBlinking()
@updateCursorsState()
startBlinkingCursors: ->
@toggleCursorBlinkHandle = setInterval(@toggleCursorBlink.bind(this), @getCursorBlinkPeriod() / 2)
stopBlinkingCursors: ->
clearInterval(@toggleCursorBlinkHandle)
toggleCursorBlink: ->
@state.content.blinkCursorsOff = not @state.content.blinkCursorsOff
pauseCursorBlinking: ->
@state.content.blinkCursorsOff = false
@stopBlinkingCursors()
@startBlinkingCursorsAfterDelay ?= _.debounce(@startBlinkingCursors, @getCursorBlinkResumeDelay())
@startBlinkingCursorsAfterDelay()