Skip to content

Commit

Permalink
Add setting to disable autoclosing brackets in the editor (#2805)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeedleFake authored and jonatanklosko committed Oct 3, 2024
1 parent 836ade5 commit fe0f19d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion assets/js/hooks/cell_editor/live_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ export default class LiveEditor {
"&": { fontSize: `${settings.editor_font_size}px` },
});

const autoCloseBracketsEnabled = settings.editor_auto_close_brackets;

const ligaturesTheme = EditorView.theme({
"&": {
fontVariantLigatures: `${settings.editor_ligatures ? "normal" : "none"}`,
Expand Down Expand Up @@ -354,7 +356,7 @@ export default class LiveEditor {
crosshairCursor(),
EditorState.allowMultipleSelections.of(true),
bracketMatching(),
closeBrackets(),
autoCloseBracketsEnabled ? closeBrackets() : [],
indentOnInput(),
history(),
EditorState.readOnly.of(this.readOnly),
Expand Down
11 changes: 11 additions & 0 deletions assets/js/hooks/editor_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const EditorSettings = {
const editorAutoSignatureCheckbox = this.el.querySelector(
`[name="editor_auto_signature"][value="true"]`,
);
const editorAutoCloseBracketsCheckbox = this.el.querySelector(
`[name="editor_auto_close_brackets"][value="true"]`,
);
const editorFontSizeCheckbox = this.el.querySelector(
`[name="editor_font_size"][value="true"]`,
);
Expand All @@ -33,6 +36,8 @@ const EditorSettings = {

editorAutoCompletionCheckbox.checked = settings.editor_auto_completion;
editorAutoSignatureCheckbox.checked = settings.editor_auto_signature;
editorAutoCloseBracketsCheckbox.checked =
settings.editor_auto_close_brackets;
editorFontSizeCheckbox.checked =
settings.editor_font_size === EDITOR_FONT_SIZE.large ? true : false;
editorLigaturesCheckbox.checked = settings.editor_ligatures;
Expand All @@ -49,6 +54,12 @@ const EditorSettings = {
settingsStore.update({ editor_auto_signature: event.target.checked });
});

editorAutoCloseBracketsCheckbox.addEventListener("change", (event) => {
settingsStore.update({
editor_auto_close_brackets: event.target.checked,
});
});

editorFontSizeCheckbox.addEventListener("change", (event) => {
settingsStore.update({
editor_font_size: event.target.checked
Expand Down
1 change: 1 addition & 0 deletions assets/js/lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const EDITOR_THEME = {
const DEFAULTSETTINGS = {
editor_auto_completion: true,
editor_auto_signature: true,
editor_auto_close_brackets: true,
editor_font_size: EDITOR_FONT_SIZE.normal,
editor_theme: EDITOR_THEME.default,
editor_ligatures: false,
Expand Down
5 changes: 5 additions & 0 deletions lib/livebook_web/live/settings_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ defmodule LivebookWeb.SettingsLive do
label="Show function signature while typing"
value={false}
/>
<.switch_field
name="editor_auto_close_brackets"
label="Automatically close brackets"
value={false}
/>
<.switch_field name="editor_font_size" label="Increase font size" value={false} />
<.switch_field name="editor_ligatures" label="Render ligatures" value={false} />
<.switch_field name="editor_light_theme" label="Use light theme" value={false} />
Expand Down

0 comments on commit fe0f19d

Please sign in to comment.