From 74612c7e622e8cdf373603c93377bdce2c6ba515 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Wed, 4 Sep 2024 14:00:29 -0700 Subject: [PATCH] Add user setting for the editor minimap (#321) --- frontend/app/store/global.ts | 4 +++- frontend/app/view/codeeditor/codeeditor.tsx | 18 ++++++++++++++++-- frontend/types/gotypes.d.ts | 1 + pkg/wconfig/defaultconfig/settings.json | 3 ++- pkg/wconfig/metaconsts.go | 2 ++ pkg/wconfig/settingsconfig.go | 2 ++ 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/frontend/app/store/global.ts b/frontend/app/store/global.ts index 0562d4d3d..9e1e5e5ce 100644 --- a/frontend/app/store/global.ts +++ b/frontend/app/store/global.ts @@ -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") { diff --git a/frontend/app/view/codeeditor/codeeditor.tsx b/frontend/app/view/codeeditor/codeeditor.tsx index acfaf06f9..31632e7b3 100644 --- a/frontend/app/view/codeeditor/codeeditor.tsx +++ b/frontend/app/view/codeeditor/codeeditor.tsx @@ -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(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 (
diff --git a/frontend/types/gotypes.d.ts b/frontend/types/gotypes.d.ts index 79f861e4b..b15047580 100644 --- a/frontend/types/gotypes.d.ts +++ b/frontend/types/gotypes.d.ts @@ -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; diff --git a/pkg/wconfig/defaultconfig/settings.json b/pkg/wconfig/defaultconfig/settings.json index 414b3c966..8c5cb0449 100644 --- a/pkg/wconfig/defaultconfig/settings.json +++ b/pkg/wconfig/defaultconfig/settings.json @@ -4,5 +4,6 @@ "ai:timeoutms": 10000, "autoupdate:enabled": true, "autoupdate:installonquit": true, - "autoupdate:intervalms": 3600000 + "autoupdate:intervalms": 3600000, + "editor:minimapenabled": true } diff --git a/pkg/wconfig/metaconsts.go b/pkg/wconfig/metaconsts.go index 688f5f347..2d57fae14 100644 --- a/pkg/wconfig/metaconsts.go +++ b/pkg/wconfig/metaconsts.go @@ -19,6 +19,8 @@ const ( ConfigKey_TermFontFamily = "term:fontfamily" ConfigKey_TermDisableWebGl = "term:disablewebgl" + ConfigKey_EditorMinimapEnabled = "editor:minimapenabled" + ConfigKey_WebClear = "web:*" ConfigKey_WebOpenLinksInternally = "web:openlinksinternally" diff --git a/pkg/wconfig/settingsconfig.go b/pkg/wconfig/settingsconfig.go index 499c8fd0d..0c77371f3 100644 --- a/pkg/wconfig/settingsconfig.go +++ b/pkg/wconfig/settingsconfig.go @@ -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"`