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/options.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 { Space } from "antd";
7
8
import A from "components/misc/A";
9
import Loading from "components/share/loading";
10
import useEditTable from "lib/hooks/edit-table";
11
import register from "../register";
12
13
const desc = {
14
code_folding: `Enable the code folding plugin. When enabled, you can fold or unfold all
15
selected code by typing control+Q, or by clicking the triangle to the left of code.`,
16
smart_indent: `When you are editing code, smart indent automatically indents new lines based
17
on the editor's understanding of your code.`,
18
electric_chars: `When electric characters is enabled, typing certain characters, such
19
as { and } in C-like languages, cause the current line to be reindented.`,
20
match_brackets: "Highlight matching brackets near cursor",
21
auto_close_brackets:
22
"When you type a bracket character, for example ( or [, CoCalc will automatically insert the corresponding close character. Some people love how this saves them time, and other people find this extremely annoying; if this annoys you, disable it.",
23
match_xml_tags: "Automatically match XML tags",
24
auto_close_xml_tags:
25
"Automatically close XML tags. For example, if you are editing HTML and type <a> then </a> is automatically inserted.",
26
auto_close_latex:
27
"Automatically close LaTeX environments. For example, if you type \\begin{verbatim} and hit enter, then \\end{verbatim} is automatically inserted.",
28
strip_trailing_whitespace: `This open makes it so that whenever a file in the editor is saved to disk, whitespace from the ends of lines is removed, since it usually serves no purpose and can get accidentally inserted when editing. Note that markdown files are always exempt, since trailing whitespace is meaningful for them.`,
29
show_trailing_whitespace:
30
"Visibly display any trailing whitespace at the ends of lines. This is useful so that such whitespace isn't invisible.",
31
spaces_instead_of_tabs:
32
"Send spaces instead of a tab character when the tab key is pressed. Use this if you prefer, e.g., 4 spaces instead of a tab in your code. The number of spaces depends on the type of code you are editing.",
33
extra_button_bar:
34
"Show additional editing functionality (mainly in Sage worksheets)",
35
build_on_save: `Trigger a build of LaTex, Rmd, etc. files whenever they are saved to disk, instead of only building when you click the Build button. This is fine for small documents, but can be annoying for large documents, especially if you are a "compulsive saver".`,
36
show_exec_warning:
37
"Show a warning if you hit shift+enter (or other keys) when editing certain files, e.g., Python code, that is not directly executable. This is just to avoid confusion if you create a .py file and think it is a Jupyter notebook.",
38
show_my_other_cursors:
39
"Enable this if you want to see your own cursor when you are editing the same file in multiple browser tabs.",
40
} as const;
41
42
register({
43
path: "editor/options",
44
title: "Options",
45
icon: "check-square",
46
desc: "Configure general behavior of the editors in CoCalc.",
47
search: desc,
48
Component: () => {
49
const { edited, original, Save, EditBoolean } = useEditTable({
50
accounts: { editor_settings: null },
51
});
52
53
if (original == null || edited == null) {
54
return <Loading />;
55
}
56
57
return (
58
<Space direction="vertical" size="large">
59
<Save />
60
<EditBoolean
61
icon="caret-down"
62
path="editor_settings.code_folding"
63
desc={desc.code_folding}
64
/>
65
<EditBoolean
66
icon="indent"
67
path="editor_settings.smart_indent"
68
desc={desc.smart_indent}
69
/>
70
<EditBoolean
71
icon="indent"
72
path="editor_settings.electric_chars"
73
title={`"Electric" Character Indentation`}
74
label={"Electric characters"}
75
desc={desc.electric_chars}
76
/>
77
<EditBoolean
78
icon="tab"
79
path="editor_settings.match_brackets"
80
desc={desc.match_brackets}
81
/>
82
<EditBoolean
83
icon="code"
84
path="editor_settings.auto_close_brackets"
85
desc={desc.auto_close_brackets}
86
/>
87
<EditBoolean
88
icon="code"
89
path="editor_settings.match_xml_tags"
90
title="Match XML tags"
91
desc={desc.match_xml_tags}
92
label="Match XML tags"
93
/>
94
<EditBoolean
95
icon="code"
96
path="editor_settings.auto_close_xml_tags"
97
title="Automatically Close XML Tags"
98
desc={desc.auto_close_xml_tags}
99
label="Autoclose XML tags"
100
/>
101
<EditBoolean
102
icon="tex"
103
path="editor_settings.auto_close_latex"
104
title="Automatically close LaTeX environments"
105
desc={desc.auto_close_latex}
106
label="Autoclose LaTeX environments"
107
/>
108
<EditBoolean
109
icon="align-left"
110
path="editor_settings.strip_trailing_whitespace"
111
desc={
112
<>
113
{desc.strip_trailing_whitespace}{" "}
114
<A href="https://www.python.org/dev/peps/pep-0008/#other-recommendations">
115
Stripping trailing whitespace is officially recommended for
116
Python code.
117
</A>
118
</>
119
}
120
/>
121
<EditBoolean
122
icon="align-left"
123
path="editor_settings.show_trailing_whitespace"
124
desc={desc.show_trailing_whitespace}
125
/>
126
<EditBoolean
127
icon="tab"
128
path="editor_settings.spaces_instead_of_tabs"
129
title="Spaces Instead of Tabs"
130
desc={
131
<>
132
{desc.spaces_instead_of_tabs}{" "}
133
<A href="https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces">
134
Spaces instead of tabs are officially recommended for Python
135
code.
136
</A>
137
</>
138
}
139
/>
140
<EditBoolean
141
icon="bars"
142
path="editor_settings.extra_button_bar"
143
desc={desc.extra_button_bar}
144
/>
145
<EditBoolean
146
icon="play-circle"
147
path="editor_settings.build_on_save"
148
desc={desc.build_on_save}
149
/>
150
<EditBoolean
151
icon="step-forward"
152
title="Show Execution Warning"
153
path="editor_settings.show_exec_warning"
154
desc={desc.show_exec_warning}
155
/>
156
<br />
157
<Save />
158
</Space>
159
);
160
},
161
});
162
163