`:tabedit` now works as an alias to `:edit` with a path and as an alias to `:tabnew` without. `:tabnew` is a new command that opens a new tab with a new file if used without a path and works as an alias to `:tabedit` with one. `:tabclose` now works as a proper alias to `:quit` (i.e. passes the arguments) `:edit` now works more like before - it opens a given path in a new tab. It also doesn't do anything if the file was modified since the last commit, unless forced by using `:edit!` `:write` works properly again and doesn't overwrite files, unless forced by using `:write!` `:xit` is now called `:xit` and not just `:x` `:substitute` now properly replaces multiple groups (`:s/(a)b(c)/X\1\2X\0`)
65 lines
1.9 KiB
CoffeeScript
65 lines
1.9 KiB
CoffeeScript
ExState = require '../lib/ex-state'
|
|
GlobalExState = require '../lib/global-ex-state'
|
|
|
|
beforeEach ->
|
|
atom.workspace ||= {}
|
|
|
|
activateExMode = ->
|
|
atom.workspace.open().then ->
|
|
atom.commands.dispatch(atom.views.getView(atom.workspace), 'ex-mode:open')
|
|
keydown('escape')
|
|
atom.workspace.getActivePane().destroyActiveItem()
|
|
|
|
|
|
getEditorElement = (callback) ->
|
|
textEditor = null
|
|
|
|
waitsForPromise ->
|
|
atom.workspace.open().then (e) ->
|
|
textEditor = e
|
|
|
|
runs ->
|
|
# element = document.createElement("atom-text-editor")
|
|
# element.setModel(textEditor)
|
|
# element.classList.add('vim-mode')
|
|
# element.exState = new ExState(element, new GlobalExState)
|
|
#
|
|
# element.addEventListener "keydown", (e) ->
|
|
# atom.keymaps.handleKeyboardEvent(e)
|
|
|
|
element = atom.views.getView(textEditor)
|
|
|
|
callback(element)
|
|
|
|
dispatchKeyboardEvent = (target, eventArgs...) ->
|
|
e = document.createEvent('KeyboardEvent')
|
|
e.initKeyboardEvent(eventArgs...)
|
|
# 0 is the default, and it's valid ASCII, but it's wrong.
|
|
Object.defineProperty(e, 'keyCode', get: -> undefined) if e.keyCode is 0
|
|
target.dispatchEvent e
|
|
|
|
dispatchTextEvent = (target, eventArgs...) ->
|
|
e = document.createEvent('TextEvent')
|
|
e.initTextEvent(eventArgs...)
|
|
target.dispatchEvent e
|
|
|
|
keydown = (key, {element, ctrl, shift, alt, meta, raw}={}) ->
|
|
key = "U+#{key.charCodeAt(0).toString(16)}" unless key is 'escape' or raw?
|
|
element ||= document.activeElement
|
|
eventArgs = [
|
|
true, # bubbles
|
|
true, # cancelable
|
|
null, # view
|
|
key, # key
|
|
0, # location
|
|
ctrl, alt, shift, meta
|
|
]
|
|
|
|
canceled = not dispatchKeyboardEvent(element, 'keydown', eventArgs...)
|
|
dispatchKeyboardEvent(element, 'keypress', eventArgs...)
|
|
if not canceled
|
|
if dispatchTextEvent(element, 'textInput', eventArgs...)
|
|
element.value += key
|
|
dispatchKeyboardEvent(element, 'keyup', eventArgs...)
|
|
|
|
module.exports = {keydown, getEditorElement, activateExMode}
|