Blink cursors always. Still need to pause blinking when moving.

This commit is contained in:
Nathan Sobo 2014-04-07 13:51:25 -06:00
parent f60f9b9f4f
commit 2b0ef68255
4 changed files with 43 additions and 3 deletions

View File

@ -117,6 +117,24 @@ describe "EditorComponent", ->
expect(cursorRect.left).toBe rangeRect.left
expect(cursorRect.width).toBe rangeRect.width
it "blinks cursors", ->
editor.addCursorAtScreenPosition([1, 0])
[cursorNode1, cursorNode2] = node.querySelectorAll('.cursor')
expect(cursorNode1.classList.contains('blink-off')).toBe false
expect(cursorNode2.classList.contains('blink-off')).toBe false
advanceClock(component.props.cursorBlinkPeriod / 2)
expect(cursorNode1.classList.contains('blink-off')).toBe true
expect(cursorNode2.classList.contains('blink-off')).toBe true
advanceClock(component.props.cursorBlinkPeriod / 2)
expect(cursorNode1.classList.contains('blink-off')).toBe false
expect(cursorNode2.classList.contains('blink-off')).toBe false
advanceClock(component.props.cursorBlinkPeriod / 2)
expect(cursorNode1.classList.contains('blink-off')).toBe true
expect(cursorNode2.classList.contains('blink-off')).toBe true
describe "selection rendering", ->
it "renders 1 region for 1-line selections", ->
# 1-line selection

View File

@ -92,6 +92,8 @@ beforeEach ->
spyOn(WorkspaceView.prototype, 'setTitle').andCallFake (@title) ->
spyOn(window, "setTimeout").andCallFake window.fakeSetTimeout
spyOn(window, "clearTimeout").andCallFake window.fakeClearTimeout
spyOn(window, "setInterval").andCallFake window.fakeSetInterval
spyOn(window, "clearInterval").andCallFake window.fakeClearInterval
spyOn(pathwatcher.File.prototype, "detectResurrectionAfterDelay").andCallFake -> @detectResurrection()
spyOn(Editor.prototype, "shouldPromptToSave").andReturn false
@ -243,6 +245,15 @@ window.fakeSetTimeout = (callback, ms) ->
window.fakeClearTimeout = (idToClear) ->
window.timeouts = window.timeouts.filter ([id]) -> id != idToClear
window.fakeSetInterval = (callback, ms) ->
action = ->
callback()
window.fakeSetTimeout(action, ms)
window.fakeSetTimeout(action, ms)
window.fakeClearInterval = (idToClear) ->
window.fakeClearTimeout(idToClear)
window.advanceClock = (delta=1) ->
window.now += delta
callbacks = []

View File

@ -8,7 +8,10 @@ CursorComponent = React.createClass
render: ->
{top, left, height, width} = @props.cursor.getPixelRect()
div className: 'cursor', style: {top, left, height, width}
className = 'cursor'
className += ' blink-off' if @props.blinkOff
div className: className, style: {top, left, height, width}
componentDidMount: ->
@subscribe @props.cursor, 'moved', => @forceUpdate()

View File

@ -63,9 +63,10 @@ EditorCompont = React.createClass
renderCursors: ->
{editor} = @props
{blinkCursorsOff} = @state
for selection in editor.getSelections() when editor.selectionIntersectsVisibleRowRange(selection)
CursorComponent(cursor: selection.cursor)
CursorComponent(cursor: selection.cursor, blinkOff: blinkCursorsOff)
renderUnderlayer: ->
{editor} = @props
@ -83,7 +84,7 @@ EditorCompont = React.createClass
getInitialState: -> {}
getDefaultProps: -> updateSync: true
getDefaultProps: -> cursorBlinkPeriod: 800
componentDidMount: ->
@measuredLines = new WeakSet
@ -92,12 +93,14 @@ EditorCompont = React.createClass
@listenForCustomEvents()
@observeEditor()
@observeConfig()
@blinkCursors()
@updateAllDimensions()
@props.editor.setVisible(true)
componentWillUnmount: ->
@getDOMNode().removeEventListener 'mousewheel', @onMouseWheel
clearInterval(@cursorBlinkIntervalHandle)
componentDidUpdate: ->
@updateVerticalScrollbar()
@ -233,6 +236,11 @@ EditorCompont = React.createClass
observeConfig: ->
@subscribe atom.config.observe 'editor.fontFamily', @setFontFamily
blinkCursors: ->
@cursorBlinkIntervalHandle = setInterval(@toggleCursorBlink, @props.cursorBlinkPeriod / 2)
toggleCursorBlink: -> @setState(blinkCursorsOff: not @state.blinkCursorsOff)
setFontSize: (fontSize) ->
@clearScopedCharWidths()
@setState({fontSize})