1 ExState = require '../lib/ex-state'
2 GlobalExState = require '../lib/global-ex-state'
8 atom.workspace.open().then ->
9 atom.commands.dispatch(atom.views.getView(atom.workspace), 'ex-mode:open')
11 atom.workspace.getActivePane().destroyActiveItem()
14 getEditorElement = (callback) ->
18 atom.workspace.open().then (e) ->
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)
27 # element.addEventListener "keydown", (e) ->
28 # atom.keymaps.handleKeyboardEvent(e)
30 element = atom.views.getView(textEditor)
34 dispatchKeyboardEvent = (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
41 dispatchTextEvent = (target, eventArgs...) ->
42 e = document.createEvent('TextEvent')
43 e.initTextEvent(eventArgs...)
44 target.dispatchEvent e
46 keydown = (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
55 ctrl, alt, shift, meta
58 canceled = not dispatchKeyboardEvent(element, 'keydown', eventArgs...)
59 dispatchKeyboardEvent(element, 'keypress', eventArgs...)
61 if dispatchTextEvent(element, 'textInput', eventArgs...)
63 dispatchKeyboardEvent(element, 'keyup', eventArgs...)
65 module.exports = {keydown, getEditorElement, activateExMode}