-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeymap.js
78 lines (77 loc) · 2.16 KB
/
keymap.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
73
74
75
76
77
78
var query = require('query');
// the keys here are tied to settings variables
module.exports.makeKeyMap = function (settings, scope) {
return {
'nav.moveRight': function (e) {
if (!scope.parent) return;
scope.parent.move.right(scope);
},
'nav.moveLeft': function (e) {
if (!scope.parent || !scope.parent.parent) return;
scope.parent.parent.move.left(scope, scope.parent);
},
'nav.moveDown': function (e) {
if (!scope.parent) return;
if (settings.get('nav.movementStyle') == 'org') {
scope.parent.move.down(scope);
} else {
scope.parent.move.downWF(scope);
}
},
'nav.moveUp': function (e) {
if (!scope.parent) return;
if (settings.get('nav.movementStyle') == 'org') {
scope.parent.move.up(scope);
} else {
scope.parent.move.upWF(scope);
}
},
'nav.goDown': function (e) {
var child, el = scope.el;
if (!scope.note.children.length) {
while (!el.nextElementSibling && el.classList.contains('child')) {
el = el.parentNode.parentNode.parentNode;
}
child = query('.title', el.nextElementSibling);
} else {
child = query('.title', query('.body', el));
}
child.focus();
},
'nav.goUp': function (e, toend) {
var prevChild = scope.el.previousElementSibling
, child;
if (prevChild) {
child = query.all('.title', prevChild);
if (child) {
child = child[child.length - 1];
}
}
if (!child) {
var parent = scope.el.parentNode.parentNode;
child = query('.title', parent);
}
if (child) {
child.focus();
if (toend) {
var sel = window.getSelection();
sel.selectAllChildren(child);
sel.collapseToEnd();
}
}
},
'nav.editTags': function (e) {
query('.tags input', scope.el).focus();
},
'nav.newAfter': function (e) {
if (!scope.parent) return;
scope.parent.move.newAfter(scope);
},
'nav.newChild': function (e) {
scope.move.newChild();
},
'nav.newLine': function (e) {
return true;
}
};
};