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