CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/account/keyboard-settings.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { FormattedMessage, useIntl } from "react-intl";
7
8
import { Panel } from "@cocalc/frontend/antd-bootstrap";
9
import { useTypedRedux } from "@cocalc/frontend/app-framework";
10
import {
11
Icon,
12
LabeledRow,
13
Loading,
14
Paragraph,
15
SelectorInput,
16
} from "@cocalc/frontend/components";
17
import { IS_MACOS } from "@cocalc/frontend/feature";
18
import { labels } from "@cocalc/frontend/i18n";
19
import keyboardShortcuts from "./keyboard-shortcuts";
20
import { set_account_table } from "./util";
21
22
const KEYBOARD_SHORTCUTS = keyboardShortcuts(IS_MACOS);
23
24
const EVALUATE_KEYS = {
25
"Shift-Enter": "shift+enter",
26
Enter: "enter (shift+enter for newline)",
27
} as const;
28
29
const LABEL_COLS = 8;
30
31
export const KeyboardSettings: React.FC = () => {
32
const intl = useIntl();
33
const evaluate_key = useTypedRedux("account", "evaluate_key");
34
35
function render_keyboard_shortcuts(): JSX.Element[] {
36
const v: JSX.Element[] = [];
37
for (const { command, shortcut } of KEYBOARD_SHORTCUTS) {
38
const key = command.id;
39
const label = intl.formatMessage(command);
40
v.push(
41
<LabeledRow key={key} label={label} label_cols={LABEL_COLS}>
42
{shortcut}
43
</LabeledRow>,
44
);
45
}
46
return v;
47
}
48
49
function eval_change(value): void {
50
set_account_table({ evaluate_key: value });
51
}
52
53
function render_eval_shortcut(): JSX.Element {
54
if (evaluate_key == null) {
55
return <Loading />;
56
}
57
const label = intl.formatMessage({
58
id: "account.keyboard-settings.sagews-eval-key",
59
defaultMessage: "Sage Worksheet evaluate key",
60
});
61
return (
62
<LabeledRow label={label} label_cols={LABEL_COLS}>
63
<SelectorInput
64
options={EVALUATE_KEYS}
65
selected={evaluate_key}
66
on_change={eval_change}
67
/>
68
</LabeledRow>
69
);
70
}
71
72
function render_intro() {
73
return (
74
<Paragraph type="secondary">
75
<FormattedMessage
76
id="account.keyboard-settings.intro"
77
defaultMessage={`These are mostly CoCalc-specific keyboard shortcuts for editing code.
78
Many of these are not standard functions provided by editor keyboards.
79
Unfortunately, keyboard shortcuts are not currently customizable.`}
80
/>
81
</Paragraph>
82
);
83
}
84
85
return (
86
<Panel
87
header={
88
<>
89
<Icon name="keyboard" />{" "}
90
{intl.formatMessage(labels.keyboard_shortcuts)}
91
</>
92
}
93
>
94
{render_intro()}
95
{render_keyboard_shortcuts()}
96
{render_eval_shortcut()}
97
</Panel>
98
);
99
};
100
101