Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/account/keyboard-settings.tsx
5963 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
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 { KEYBOARD_ICON_NAME } from "./account-preferences-keyboard";
18
import { IS_MACOS } from "@cocalc/frontend/feature";
19
import { labels } from "@cocalc/frontend/i18n";
20
import keyboardShortcuts from "./keyboard-shortcuts";
21
import { set_account_table } from "./util";
22
23
const KEYBOARD_SHORTCUTS = keyboardShortcuts(IS_MACOS);
24
25
const EVALUATE_KEYS = {
26
"Shift-Enter": "shift+enter",
27
Enter: "enter (shift+enter for newline)",
28
} as const;
29
30
const LABEL_COLS = 8;
31
32
export const KeyboardSettings: React.FC = () => {
33
const intl = useIntl();
34
const evaluate_key = useTypedRedux("account", "evaluate_key");
35
36
function render_keyboard_shortcuts(): React.JSX.Element[] {
37
const v: React.JSX.Element[] = [];
38
for (const { command, shortcut } of KEYBOARD_SHORTCUTS) {
39
const key = command.id;
40
const label = intl.formatMessage(command);
41
v.push(
42
<LabeledRow key={key} label={label} label_cols={LABEL_COLS}>
43
{shortcut}
44
</LabeledRow>,
45
);
46
}
47
return v;
48
}
49
50
function eval_change(value): void {
51
set_account_table({ evaluate_key: value });
52
}
53
54
function render_eval_shortcut(): React.JSX.Element {
55
if (evaluate_key == null) {
56
return <Loading />;
57
}
58
const label = intl.formatMessage({
59
id: "account.keyboard-settings.sagews-eval-key",
60
defaultMessage: "Sage Worksheet evaluate key",
61
});
62
return (
63
<LabeledRow label={label} label_cols={LABEL_COLS}>
64
<SelectorInput
65
options={EVALUATE_KEYS}
66
selected={evaluate_key}
67
on_change={eval_change}
68
/>
69
</LabeledRow>
70
);
71
}
72
73
function render_intro() {
74
return (
75
<Paragraph type="secondary">
76
<FormattedMessage
77
id="account.keyboard-settings.intro"
78
defaultMessage={`These are mostly CoCalc-specific keyboard shortcuts for editing code.
79
Many of these are not standard functions provided by editor keyboards.
80
Unfortunately, keyboard shortcuts are not currently customizable.`}
81
/>
82
</Paragraph>
83
);
84
}
85
86
return (
87
<Panel
88
header={
89
<>
90
<Icon name={KEYBOARD_ICON_NAME} />{" "}
91
{intl.formatMessage(labels.keyboard_shortcuts)}
92
</>
93
}
94
>
95
{render_intro()}
96
{render_keyboard_shortcuts()}
97
{render_eval_shortcut()}
98
</Panel>
99
);
100
};
101
102