2018-03-27 11:25:54 +08:00
|
|
|
import noteDetailService from "./note_detail.js";
|
|
|
|
import utils from "./utils.js";
|
2018-04-02 08:33:10 +08:00
|
|
|
import treeChangesService from "./branches.js";
|
2018-09-03 05:02:01 +08:00
|
|
|
import contextMenuService from "./tree_context_menu.js";
|
2018-03-27 11:25:54 +08:00
|
|
|
import treeService from "./tree.js";
|
2018-04-02 08:50:58 +08:00
|
|
|
import editBranchPrefixDialog from "../dialogs/branch_prefix.js";
|
2018-12-13 03:54:58 +08:00
|
|
|
import hoistedNoteService from "./hoisted_note.js";
|
2018-03-27 11:25:54 +08:00
|
|
|
|
|
|
|
const keyBindings = {
|
|
|
|
"del": node => {
|
2018-04-01 11:08:22 +08:00
|
|
|
treeChangesService.deleteNodes(treeService.getSelectedNodes(true));
|
2018-03-27 11:25:54 +08:00
|
|
|
},
|
|
|
|
"ctrl+up": node => {
|
|
|
|
const beforeNode = node.getPrevSibling();
|
|
|
|
|
|
|
|
if (beforeNode !== null) {
|
|
|
|
treeChangesService.moveBeforeNode([node], beforeNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"ctrl+down": node => {
|
2019-03-19 04:59:53 +08:00
|
|
|
const afterNode = node.getNextSibling();
|
2018-03-27 11:25:54 +08:00
|
|
|
if (afterNode !== null) {
|
|
|
|
treeChangesService.moveAfterNode([node], afterNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"ctrl+left": node => {
|
|
|
|
treeChangesService.moveNodeUpInHierarchy(node);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"ctrl+right": node => {
|
2019-03-19 04:59:53 +08:00
|
|
|
const toNode = node.getPrevSibling();
|
2018-03-27 11:25:54 +08:00
|
|
|
|
|
|
|
if (toNode !== null) {
|
|
|
|
treeChangesService.moveToNode([node], toNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
2018-11-01 06:55:14 +08:00
|
|
|
"shift+up": () => {
|
|
|
|
const node = treeService.getFocusedNode();
|
|
|
|
|
|
|
|
node.navigate($.ui.keyCode.UP, false).then(() => {
|
|
|
|
const currentNode = treeService.getFocusedNode();
|
2018-03-27 11:25:54 +08:00
|
|
|
|
|
|
|
if (currentNode.isSelected()) {
|
|
|
|
node.setSelected(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
currentNode.setSelected(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
2018-11-01 06:55:14 +08:00
|
|
|
"shift+down": () => {
|
|
|
|
const node = treeService.getFocusedNode();
|
|
|
|
|
|
|
|
node.navigate($.ui.keyCode.DOWN, false).then(() => {
|
|
|
|
const currentNode = treeService.getFocusedNode();
|
2018-03-27 11:25:54 +08:00
|
|
|
|
|
|
|
if (currentNode.isSelected()) {
|
|
|
|
node.setSelected(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
currentNode.setSelected(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"f2": node => {
|
2018-04-02 08:50:58 +08:00
|
|
|
editBranchPrefixDialog.showDialog(node);
|
2018-03-27 11:25:54 +08:00
|
|
|
},
|
|
|
|
"alt+-": node => {
|
|
|
|
treeService.collapseTree(node);
|
|
|
|
},
|
|
|
|
"alt+s": node => {
|
|
|
|
treeService.sortAlphabetically(node.data.noteId);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"ctrl+a": node => {
|
|
|
|
for (const child of node.getParent().getChildren()) {
|
|
|
|
child.setSelected(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"ctrl+c": () => {
|
|
|
|
contextMenuService.copy(treeService.getSelectedNodes());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"ctrl+x": () => {
|
|
|
|
contextMenuService.cut(treeService.getSelectedNodes());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"ctrl+v": node => {
|
|
|
|
contextMenuService.pasteInto(node);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"return": node => {
|
2018-09-07 16:50:05 +08:00
|
|
|
noteDetailService.focusOnTitle();
|
2018-03-27 11:25:54 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"backspace": node => {
|
2018-10-22 04:42:20 +08:00
|
|
|
if (!utils.isRootNode(node)) {
|
2018-03-27 11:25:54 +08:00
|
|
|
node.getParent().setActive().then(treeService.clearSelectedNodes);
|
|
|
|
}
|
|
|
|
},
|
2018-12-13 03:54:58 +08:00
|
|
|
"ctrl+h": node => {
|
|
|
|
hoistedNoteService.getHoistedNoteId().then(hoistedNoteId => {
|
|
|
|
if (node.data.noteId === hoistedNoteId) {
|
2018-12-16 03:29:08 +08:00
|
|
|
hoistedNoteService.unhoist();
|
2018-12-13 03:54:58 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
hoistedNoteService.setHoistedNoteId(node.data.noteId);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
2018-03-27 11:25:54 +08:00
|
|
|
// code below shouldn't be necessary normally, however there's some problem with interaction with context menu plugin
|
|
|
|
// after opening context menu, standard shortcuts don't work, but they are detected here
|
|
|
|
// so we essentially takeover the standard handling with our implementation.
|
|
|
|
"left": node => {
|
|
|
|
node.navigate($.ui.keyCode.LEFT, true).then(treeService.clearSelectedNodes);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"right": node => {
|
|
|
|
node.navigate($.ui.keyCode.RIGHT, true).then(treeService.clearSelectedNodes);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"up": node => {
|
|
|
|
node.navigate($.ui.keyCode.UP, true).then(treeService.clearSelectedNodes);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"down": node => {
|
|
|
|
node.navigate($.ui.keyCode.DOWN, true).then(treeService.clearSelectedNodes);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default keyBindings;
|