Path: blob/master/src/packages/frontend/editors/task-editor/keyboard.ts
1691 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Keyboard shortcuts7*/89import { HEADINGS } from "./headings-info";1011import { is_sortable as is_sortable_header } from "./headings-info";1213function is_sortable(actions): boolean {14return is_sortable_header(15actions.store.getIn(["local_view_state", "sort", "column"]) ?? HEADINGS[0],16);17}1819export function create_key_handler(actions): (any) => void {20return (evt) => {21if (actions.isEditing()) {22return;23}24const read_only = !!actions.store.get("read_only");25const mod = evt.ctrlKey || evt.metaKey || evt.altKey || evt.shiftKey;2627if (evt.keyCode === 70) {28// f = global find, with our without modifiers...29actions.focus_find_box();30return false;31} else if (evt.which === 40 || evt.which === 74) {32// down33if (mod) {34if (is_sortable(actions)) {35actions.move_task_delta(1);36}37} else {38actions.set_current_task_delta(1);39}40return false;41} else if (evt.which === 38 || evt.which === 75) {42// up43if (mod) {44if (is_sortable(actions)) {45actions.move_task_delta(-1);46}47} else {48actions.set_current_task_delta(-1);49}50return false;51}5253if (read_only) {54return;55}5657// with or without modifier58if (evt.keyCode === 83) {59// s = save60actions.save();61return false;62} else if (evt.keyCode === 78) {63// n64actions.new_task();65return false;66}6768if (mod && evt.which === 32) {69// space - need mod so user can space to scroll down.70actions.toggleHideBody();71return false;72}73if (!mod && (evt.which === 13 || evt.which === 73)) {74// return (or i, like vim) = edit selected75actions.edit_desc();76return false;77}78};79}808182