From e1a19a0b808076c53251f4229d4ae27a0a1c04df Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Wed, 4 Sep 2024 23:08:56 -0700 Subject: [PATCH] add user setting for sticky scroll --- frontend/app/view/codeeditor/codeeditor.tsx | 9 ++++++++- frontend/types/gotypes.d.ts | 1 + pkg/wconfig/metaconsts.go | 1 + pkg/wconfig/settingsconfig.go | 3 ++- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/frontend/app/view/codeeditor/codeeditor.tsx b/frontend/app/view/codeeditor/codeeditor.tsx index 68acd30f6..dc544678d 100644 --- a/frontend/app/view/codeeditor/codeeditor.tsx +++ b/frontend/app/view/codeeditor/codeeditor.tsx @@ -82,10 +82,16 @@ const minimapEnabledAtom = atom((get) => { return settings["editor:minimapenabled"] ?? false; }); +const stickyScrollEnabledAtom = atom((get) => { + const settings = get(atoms.settingsAtom); + return settings["editor:stickyscrollenabled"] ?? false; +}); + export function CodeEditor({ text, language, filename, onChange, onMount }: CodeEditorProps) { const divRef = useRef(null); const unmountRef = useRef<() => void>(null); const minimapEnabled = useAtomValue(minimapEnabledAtom); + const stickyScrollEnabled = useAtomValue(stickyScrollEnabledAtom); const theme = "wave-theme-dark"; React.useEffect(() => { @@ -112,8 +118,9 @@ export function CodeEditor({ text, language, filename, onChange, onMount }: Code const editorOpts = useMemo(() => { const opts = defaultEditorOptions(); opts.minimap.enabled = minimapEnabled; + opts.stickyScroll.enabled = stickyScrollEnabled; return opts; - }, [minimapEnabled]); + }, [minimapEnabled, stickyScrollEnabled]); return (
diff --git a/frontend/types/gotypes.d.ts b/frontend/types/gotypes.d.ts index d784d2b6d..324ec0cfe 100644 --- a/frontend/types/gotypes.d.ts +++ b/frontend/types/gotypes.d.ts @@ -396,6 +396,7 @@ declare global { "term:fontfamily"?: string; "term:disablewebgl"?: boolean; "editor:minimapenabled"?: boolean; + "editor:stickyscrollenabled"?: boolean; "web:*"?: boolean; "web:openlinksinternally"?: boolean; "blockheader:*"?: boolean; diff --git a/pkg/wconfig/metaconsts.go b/pkg/wconfig/metaconsts.go index 6d7dfc807..d5cb9830e 100644 --- a/pkg/wconfig/metaconsts.go +++ b/pkg/wconfig/metaconsts.go @@ -20,6 +20,7 @@ const ( ConfigKey_TermDisableWebGl = "term:disablewebgl" ConfigKey_EditorMinimapEnabled = "editor:minimapenabled" + ConfigKey_EditorStickyScrollEnabled = "editor:stickyscrollenabled" ConfigKey_WebClear = "web:*" ConfigKey_WebOpenLinksInternally = "web:openlinksinternally" diff --git a/pkg/wconfig/settingsconfig.go b/pkg/wconfig/settingsconfig.go index bc28718d9..c30e13b72 100644 --- a/pkg/wconfig/settingsconfig.go +++ b/pkg/wconfig/settingsconfig.go @@ -51,7 +51,8 @@ type SettingsType struct { TermFontFamily string `json:"term:fontfamily,omitempty"` TermDisableWebGl bool `json:"term:disablewebgl,omitempty"` - EditorMinimapEnabled bool `json:"editor:minimapenabled,omitempty"` + EditorMinimapEnabled bool `json:"editor:minimapenabled,omitempty"` + EditorStickyScrollEnabled bool `json:"editor:stickyscrollenabled,omitempty"` WebClear bool `json:"web:*,omitempty"` WebOpenLinksInternally bool `json:"web:openlinksinternally,omitempty"`