This repository has been archived by the owner on Feb 9, 2022. It is now read-only.
forked from sjas/vimflowy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimflowy.js
72 lines (54 loc) · 1.87 KB
/
vimflowy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// TODO: support search functionality -- '/', type query, esc, n/N move you
// between search terms?
// TODO: add 'e', 'dd', others?
//
var normalKeybindings = {
"j": commands.moveDown,
"k": commands.moveUp,
"h": commands.moveLeft,
"l": commands.moveRight,
"w": commands.moveWordForward,
"b": commands.moveWordBackward,
"x": commands.doBackspace,
"shift+o": commands.createNewBefore,
"o": commands.createNewAfter,
"shift+i": commands.insertBeginning,
"shift+a": commands.insertEnd,
"u": commands.doUndo,
"ctrl+r": commands.doRedo,
"i": enterInsertMode,
"a": enterInsertMode
};
var insertKeybindings = {
"esc": enterNormalMode,
// TODO: this breaks tab closing (even more)!
"ctrl+w": commands.deleteWordBack,
"ctrl+u": commands.deleteItemBack
};
var alwaysKeybindings = {
"alt+l": commands.zoomInFold,
"alt+h": commands.zoomOutFold,
"alt+shift+l": commands.doIndent,
"alt+shift+h": commands.doDedent,
"alt+shift+k": commands.doProjectUp,
"alt+shift+j": commands.doProjectDown
};
// unbind and rebind so we can get esc key back
$(".editor > textarea").unbind("keydown");
$(".editor > textarea").addTextAreaEventHandlers();
// add some "vimflowy" movement keybindings
$(".editor > textarea").addModalKeyboardShortcuts(alwaysKeybindings);
var blockAll = function (e) { e.preventDefault(); }
function enterNormalMode () {
console.log('entering normal mode');
$(".editor > textarea").bind("keydown", blockAll);
$(".editor > textarea").addModalKeyboardShortcuts(normalKeybindings, insertKeybindings);
};
function enterInsertMode (e) {
e.preventDefault();
console.log('entering insert mode');
$(".editor > textarea").unbind("keydown", blockAll);
$(".editor > textarea").addModalKeyboardShortcuts(insertKeybindings, normalKeybindings);
}
// start 'er up
enterNormalMode();