Path: blob/master/src/packages/frontend/account/keyboard-settings.tsx
5963 views
/*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 { KEYBOARD_ICON_NAME } from "./account-preferences-keyboard";17import { IS_MACOS } from "@cocalc/frontend/feature";18import { labels } from "@cocalc/frontend/i18n";19import keyboardShortcuts from "./keyboard-shortcuts";20import { set_account_table } from "./util";2122const KEYBOARD_SHORTCUTS = keyboardShortcuts(IS_MACOS);2324const EVALUATE_KEYS = {25"Shift-Enter": "shift+enter",26Enter: "enter (shift+enter for newline)",27} as const;2829const LABEL_COLS = 8;3031export const KeyboardSettings: React.FC = () => {32const intl = useIntl();33const evaluate_key = useTypedRedux("account", "evaluate_key");3435function render_keyboard_shortcuts(): React.JSX.Element[] {36const v: React.JSX.Element[] = [];37for (const { command, shortcut } of KEYBOARD_SHORTCUTS) {38const key = command.id;39const label = intl.formatMessage(command);40v.push(41<LabeledRow key={key} label={label} label_cols={LABEL_COLS}>42{shortcut}43</LabeledRow>,44);45}46return v;47}4849function eval_change(value): void {50set_account_table({ evaluate_key: value });51}5253function render_eval_shortcut(): React.JSX.Element {54if (evaluate_key == null) {55return <Loading />;56}57const label = intl.formatMessage({58id: "account.keyboard-settings.sagews-eval-key",59defaultMessage: "Sage Worksheet evaluate key",60});61return (62<LabeledRow label={label} label_cols={LABEL_COLS}>63<SelectorInput64options={EVALUATE_KEYS}65selected={evaluate_key}66on_change={eval_change}67/>68</LabeledRow>69);70}7172function render_intro() {73return (74<Paragraph type="secondary">75<FormattedMessage76id="account.keyboard-settings.intro"77defaultMessage={`These are mostly CoCalc-specific keyboard shortcuts for editing code.78Many of these are not standard functions provided by editor keyboards.79Unfortunately, keyboard shortcuts are not currently customizable.`}80/>81</Paragraph>82);83}8485return (86<Panel87header={88<>89<Icon name={KEYBOARD_ICON_NAME} />{" "}90{intl.formatMessage(labels.keyboard_shortcuts)}91</>92}93>94{render_intro()}95{render_keyboard_shortcuts()}96{render_eval_shortcut()}97</Panel>98);99};100101102