Add user setting for the editor minimap (#321)

This commit is contained in:
Evan Simkowitz 2024-09-04 14:00:29 -07:00 committed by GitHub
parent 2cc0fdc999
commit 74612c7e62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 26 additions and 4 deletions

View File

@ -359,7 +359,9 @@ function handleWSEventMessage(msg: WSEventType) {
return;
}
if (msg.eventtype == "config") {
globalStore.set(atoms.fullConfigAtom, (msg.data as WatcherUpdate).fullconfig);
const fullConfig = (msg.data as WatcherUpdate).fullconfig;
console.log("fullConfig", fullConfig);
globalStore.set(atoms.fullConfigAtom, fullConfig);
return;
}
if (msg.eventtype == "userinput") {

View File

@ -1,10 +1,12 @@
// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
import { atoms } from "@/app/store/global";
import loader from "@monaco-editor/loader";
import { Editor, Monaco } from "@monaco-editor/react";
import { atom, useAtomValue } from "jotai";
import type * as MonacoTypes from "monaco-editor/esm/vs/editor/editor.api";
import React, { useRef } from "react";
import React, { useMemo, useRef } from "react";
import "./codeeditor.less";
// there is a global monaco variable (TODO get the correct TS type)
@ -71,9 +73,16 @@ interface CodeEditorProps {
onMount?: (monacoPtr: MonacoTypes.editor.IStandaloneCodeEditor, monaco: Monaco) => () => void;
}
const minimapEnabledAtom = atom((get) => {
const settings = get(atoms.settingsAtom);
console.log("settings", settings);
return settings["editor:minimapenabled"] ?? false;
});
export function CodeEditor({ text, language, filename, onChange, onMount }: CodeEditorProps) {
const divRef = useRef<HTMLDivElement>(null);
const unmountRef = useRef<() => void>(null);
const minimapEnabled = useAtomValue(minimapEnabledAtom);
const theme = "wave-theme-dark";
React.useEffect(() => {
@ -97,7 +106,12 @@ export function CodeEditor({ text, language, filename, onChange, onMount }: Code
}
}
const editorOpts = defaultEditorOptions();
const editorOpts = useMemo(() => {
const opts = defaultEditorOptions();
console.log("minimapEnabled", minimapEnabled);
opts.minimap.enabled = minimapEnabled;
return opts;
}, [minimapEnabled]);
return (
<div className="code-editor-wrapper">

View File

@ -395,6 +395,7 @@ declare global {
"term:fontsize"?: number;
"term:fontfamily"?: string;
"term:disablewebgl"?: boolean;
"editor:minimapenabled"?: boolean;
"web:*"?: boolean;
"web:openlinksinternally"?: boolean;
"blockheader:*"?: boolean;

View File

@ -4,5 +4,6 @@
"ai:timeoutms": 10000,
"autoupdate:enabled": true,
"autoupdate:installonquit": true,
"autoupdate:intervalms": 3600000
"autoupdate:intervalms": 3600000,
"editor:minimapenabled": true
}

View File

@ -19,6 +19,8 @@ const (
ConfigKey_TermFontFamily = "term:fontfamily"
ConfigKey_TermDisableWebGl = "term:disablewebgl"
ConfigKey_EditorMinimapEnabled = "editor:minimapenabled"
ConfigKey_WebClear = "web:*"
ConfigKey_WebOpenLinksInternally = "web:openlinksinternally"

View File

@ -51,6 +51,8 @@ type SettingsType struct {
TermFontFamily string `json:"term:fontfamily,omitempty"`
TermDisableWebGl bool `json:"term:disablewebgl,omitempty"`
EditorMinimapEnabled bool `json:"editor:minimapenabled,omitempty"`
WebClear bool `json:"web:*,omitempty"`
WebOpenLinksInternally bool `json:"web:openlinksinternally,omitempty"`