]> git.r.bdr.sh - rbdr/dotfiles/blame_incremental - atom/packages/ex-mode/spec/spec-helper.coffee
Update prompt to show ruby & node envs
[rbdr/dotfiles] / atom / packages / ex-mode / spec / spec-helper.coffee
... / ...
CommitLineData
1ExState = require '../lib/ex-state'
2GlobalExState = require '../lib/global-ex-state'
3
4beforeEach ->
5 atom.workspace ||= {}
6
7activateExMode = ->
8 atom.workspace.open().then ->
9 atom.commands.dispatch(atom.views.getView(atom.workspace), 'ex-mode:open')
10 keydown('escape')
11 atom.workspace.getActivePane().destroyActiveItem()
12
13
14getEditorElement = (callback) ->
15 textEditor = null
16
17 waitsForPromise ->
18 atom.workspace.open().then (e) ->
19 textEditor = e
20
21 runs ->
22 # element = document.createElement("atom-text-editor")
23 # element.setModel(textEditor)
24 # element.classList.add('vim-mode')
25 # element.exState = new ExState(element, new GlobalExState)
26 #
27 # element.addEventListener "keydown", (e) ->
28 # atom.keymaps.handleKeyboardEvent(e)
29
30 element = atom.views.getView(textEditor)
31
32 callback(element)
33
34dispatchKeyboardEvent = (target, eventArgs...) ->
35 e = document.createEvent('KeyboardEvent')
36 e.initKeyboardEvent(eventArgs...)
37 # 0 is the default, and it's valid ASCII, but it's wrong.
38 Object.defineProperty(e, 'keyCode', get: -> undefined) if e.keyCode is 0
39 target.dispatchEvent e
40
41dispatchTextEvent = (target, eventArgs...) ->
42 e = document.createEvent('TextEvent')
43 e.initTextEvent(eventArgs...)
44 target.dispatchEvent e
45
46keydown = (key, {element, ctrl, shift, alt, meta, raw}={}) ->
47 key = "U+#{key.charCodeAt(0).toString(16)}" unless key is 'escape' or raw?
48 element ||= document.activeElement
49 eventArgs = [
50 true, # bubbles
51 true, # cancelable
52 null, # view
53 key, # key
54 0, # location
55 ctrl, alt, shift, meta
56 ]
57
58 canceled = not dispatchKeyboardEvent(element, 'keydown', eventArgs...)
59 dispatchKeyboardEvent(element, 'keypress', eventArgs...)
60 if not canceled
61 if dispatchTextEvent(element, 'textInput', eventArgs...)
62 element.value += key
63 dispatchKeyboardEvent(element, 'keyup', eventArgs...)
64
65module.exports = {keydown, getEditorElement, activateExMode}