Cursor blinks

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-01-27 17:33:02 -08:00
parent 900f745b65
commit dea99216d4
4 changed files with 66 additions and 5 deletions

View File

@ -5,14 +5,33 @@ _ = require 'underscore'
fs = require 'fs'
describe "Cursor", ->
buffer = null
editor = null
[buffer, editor, cursor] = []
beforeEach ->
buffer = new Buffer(require.resolve('fixtures/sample.js'))
editor = Editor.build()
editor.enableKeymap()
editor.setBuffer(buffer)
cursor = editor.cursor
describe "adding and removing of the idle class", ->
it "removes the idle class while moving, then adds it back when it stops", ->
advanceClock(200)
expect(cursor).toHaveClass 'idle'
cursor.setPosition([1, 2])
expect(cursor).not.toHaveClass 'idle'
window.advanceClock(200)
expect(cursor).toHaveClass 'idle'
cursor.setPosition([1, 3])
advanceClock(100)
cursor.setPosition([1, 4])
advanceClock(100)
expect(cursor).not.toHaveClass 'idle'
advanceClock(100)
expect(cursor).toHaveClass 'idle'

View File

@ -4,6 +4,10 @@ _ = require 'underscore'
Native = require 'native'
BindingSet = require 'binding-set'
require 'window'
window.showConsole()
beforeEach ->
window.resetTimeouts()
afterEach ->
(new Native).resetMainMenu()
@ -28,6 +32,28 @@ window.waitsForPromise = (fn) ->
window.waitsFor (moveOn) ->
fn().done(moveOn)
window.resetTimeouts = ->
window.now = 0
window.timeoutCount = 0
window.timeouts = []
window.setTimeout = (callback, ms) ->
id = ++window.timeoutCount
window.timeouts.push([id, window.now + ms, callback])
id
window.clearTimeout = (idToClear) ->
window.timeouts = window.timeouts.filter ([id]) -> id != idToClear
window.advanceClock = (delta) ->
window.now += delta
window.timeouts = window.timeouts.filter ([id, strikeTime, callback]) ->
if strikeTime <= window.now
callback()
false
else
true
$.fn.resultOfTrigger = (type) ->
event = $.Event(type)
this.trigger(event)

View File

@ -5,7 +5,7 @@ _ = require 'underscore'
module.exports =
class Cursor extends Template
content: ->
@pre class: 'cursor', style: 'position: absolute;', => @raw '&nbsp;'
@pre class: 'cursor idle', style: 'position: absolute;', => @raw '&nbsp;'
viewProperties:
editor: null
@ -23,6 +23,10 @@ class Cursor extends Template
@updateAppearance()
@trigger 'cursor:position-changed'
@removeClass 'idle'
window.clearTimeout(@idleTimeout) if @idleTimeout
@idleTimeout = window.setTimeout (=> @addClass 'idle'), 200
getPosition: -> _.clone(@point)
setColumn: (column) ->

View File

@ -13,9 +13,21 @@
z-index: 1;
}
@-webkit-keyframes blink {
0% { opacity: .7; }
49% { opacity: .7; }
51% { opacity: 0; }
100% { opacity: 0; }
}
.editor .cursor {
background: #9dff9d;
opacity: .3;
border-left: 3px solid #9dff9d;
opacity: 0.7;
}
.editor .cursor.idle {
-webkit-animation: blink 0.6s;
-webkit-animation-iteration-count: infinite;
}
.editor .hidden-input {