Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/task-editor/keyboard.ts
1691 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/*
7
Keyboard shortcuts
8
*/
9
10
import { HEADINGS } from "./headings-info";
11
12
import { is_sortable as is_sortable_header } from "./headings-info";
13
14
function is_sortable(actions): boolean {
15
return is_sortable_header(
16
actions.store.getIn(["local_view_state", "sort", "column"]) ?? HEADINGS[0],
17
);
18
}
19
20
export function create_key_handler(actions): (any) => void {
21
return (evt) => {
22
if (actions.isEditing()) {
23
return;
24
}
25
const read_only = !!actions.store.get("read_only");
26
const mod = evt.ctrlKey || evt.metaKey || evt.altKey || evt.shiftKey;
27
28
if (evt.keyCode === 70) {
29
// f = global find, with our without modifiers...
30
actions.focus_find_box();
31
return false;
32
} else if (evt.which === 40 || evt.which === 74) {
33
// down
34
if (mod) {
35
if (is_sortable(actions)) {
36
actions.move_task_delta(1);
37
}
38
} else {
39
actions.set_current_task_delta(1);
40
}
41
return false;
42
} else if (evt.which === 38 || evt.which === 75) {
43
// up
44
if (mod) {
45
if (is_sortable(actions)) {
46
actions.move_task_delta(-1);
47
}
48
} else {
49
actions.set_current_task_delta(-1);
50
}
51
return false;
52
}
53
54
if (read_only) {
55
return;
56
}
57
58
// with or without modifier
59
if (evt.keyCode === 83) {
60
// s = save
61
actions.save();
62
return false;
63
} else if (evt.keyCode === 78) {
64
// n
65
actions.new_task();
66
return false;
67
}
68
69
if (mod && evt.which === 32) {
70
// space - need mod so user can space to scroll down.
71
actions.toggleHideBody();
72
return false;
73
}
74
if (!mod && (evt.which === 13 || evt.which === 73)) {
75
// return (or i, like vim) = edit selected
76
actions.edit_desc();
77
return false;
78
}
79
};
80
}
81
82