Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/account/keyboard-settings.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { FormattedMessage, useIntl } from "react-intl";67import { Panel } from "@cocalc/frontend/antd-bootstrap";8import { useTypedRedux } from "@cocalc/frontend/app-framework";9import {10Icon,11LabeledRow,12Loading,13Paragraph,14SelectorInput,15} from "@cocalc/frontend/components";16import { IS_MACOS } from "@cocalc/frontend/feature";17import { labels } from "@cocalc/frontend/i18n";18import keyboardShortcuts from "./keyboard-shortcuts";19import { set_account_table } from "./util";2021const KEYBOARD_SHORTCUTS = keyboardShortcuts(IS_MACOS);2223const EVALUATE_KEYS = {24"Shift-Enter": "shift+enter",25Enter: "enter (shift+enter for newline)",26} as const;2728const LABEL_COLS = 8;2930export const KeyboardSettings: React.FC = () => {31const intl = useIntl();32const evaluate_key = useTypedRedux("account", "evaluate_key");3334function render_keyboard_shortcuts(): JSX.Element[] {35const v: JSX.Element[] = [];36for (const { command, shortcut } of KEYBOARD_SHORTCUTS) {37const key = command.id;38const label = intl.formatMessage(command);39v.push(40<LabeledRow key={key} label={label} label_cols={LABEL_COLS}>41{shortcut}42</LabeledRow>,43);44}45return v;46}4748function eval_change(value): void {49set_account_table({ evaluate_key: value });50}5152function render_eval_shortcut(): JSX.Element {53if (evaluate_key == null) {54return <Loading />;55}56const label = intl.formatMessage({57id: "account.keyboard-settings.sagews-eval-key",58defaultMessage: "Sage Worksheet evaluate key",59});60return (61<LabeledRow label={label} label_cols={LABEL_COLS}>62<SelectorInput63options={EVALUATE_KEYS}64selected={evaluate_key}65on_change={eval_change}66/>67</LabeledRow>68);69}7071function render_intro() {72return (73<Paragraph type="secondary">74<FormattedMessage75id="account.keyboard-settings.intro"76defaultMessage={`These are mostly CoCalc-specific keyboard shortcuts for editing code.77Many of these are not standard functions provided by editor keyboards.78Unfortunately, keyboard shortcuts are not currently customizable.`}79/>80</Paragraph>81);82}8384return (85<Panel86header={87<>88<Icon name="keyboard" />{" "}89{intl.formatMessage(labels.keyboard_shortcuts)}90</>91}92>93{render_intro()}94{render_keyboard_shortcuts()}95{render_eval_shortcut()}96</Panel>97);98};99100101