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/next/components/account/config/editor/appearance.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Col, Row, Space } from "antd";67import { EDITOR_COLOR_SCHEMES } from "@cocalc/util/db-schema/accounts";8import CodeMirror from "components/share/codemirror";9import Loading from "components/share/loading";10import useEditTable from "lib/hooks/edit-table";11import register from "../register";12import { Title } from "components/misc";1314interface Data {15font_size: number;16editor_settings: {17theme: keyof typeof EDITOR_COLOR_SCHEMES;18line_numbers: boolean;19line_wrapping: boolean;20};21}2223const desc = {24font_size: `25Newly opened files will open with this font size in pixels by default. You can26change the font size for a particular file (or editor frame) at any time,27and the setting is saved in your browser.28`,29theme: `The editor theme determines the color scheme used by CodeMirror.30This impacts editing files and input cells of Jupyter notebooks.`,31line_wrapping: `Enable line or word wrapping so that when I line is longer than the width of the editor,32the line will get wrapped so it stays visible, and there is no horizontal scroll bar. Enabling33this can make it difficult to view the structure of some text involving longer lines, but avoids having34to scroll horizontally.`,35line_numbers: `Display line numbers to the left of the editor content.`,36};3738const EXAMPLE = `def is_prime_lucas_lehmer(p):39"""40Test primality of Mersenne number 2**p - 1. This is a long line hopefully illustrating line wrapping.4142>>> is_prime_lucas_lehmer(107)43True44"""45k = 2**p - 1; s = 446for i in range(3, p+1):47s = (s*s - 2) % k48return s == 0`;4950register({51path: "editor/appearance",52title: "Appearance",53icon: "font",54desc: "Editor default font size, color theme, etc.",55search: desc,56Component: () => {57const { edited, original, Save, EditBoolean, EditNumber, EditSelect } =58useEditTable<Data>({59accounts: { font_size: null, editor_settings: null },60});6162if (original == null || edited == null) {63return <Loading />;64}6566return (67<Row gutter={[20, 30]}>68<Col md={24}>69<Save />70</Col>71<Col md={14} sm={24}>72<Space direction="vertical" size="large">73<EditNumber74path="font_size"75icon="text-height"76title="Default Font Size"77desc={desc.font_size}78min={5}79max={32}80units="px"81/>82<EditSelect83path="editor_settings.theme"84icon="colors"85desc={desc.theme}86options={EDITOR_COLOR_SCHEMES}87style={{ width: "30ex" }}88/>89<EditBoolean90icon="align-left"91path="editor_settings.line_wrapping"92desc={desc.line_wrapping}93/>94<EditBoolean95icon="list-ol"96path="editor_settings.line_numbers"97desc={desc.line_numbers}98/>99</Space>100</Col>101<Col md={10} sm={24}>102<Title level={3}>Preview</Title>103<CodeMirror104content={EXAMPLE}105filename="a.py"106fontSize={edited.font_size}107options={{108// @ts-ignore109theme: edited.editor_settings.theme,110lineNumbers: edited.editor_settings.line_numbers,111lineWrapping: edited.editor_settings.line_wrapping,112}}113/>114</Col>115</Row>116);117},118});119120121