From 71961b373fa71727d30ac157f832bb97ef6b5700 Mon Sep 17 00:00:00 2001 From: Sylvie Crowe <107814465+oneirocosm@users.noreply.github.com> Date: Mon, 16 Dec 2024 18:23:42 -0800 Subject: [PATCH] Extra Font Size Controls (#1537) This adds: - "editor:fontsize" to modify the code editor's font size - "ai:fontsize" to modify the ai widget's font size (for general text) - "ai:fixedfontsize" to modify the ai widget's fixed font size (for code fragments) --- frontend/app/view/codeeditor/codeeditor.tsx | 4 +- frontend/app/view/waveai/waveai.tsx | 45 ++++++++++++++++----- frontend/types/gotypes.d.ts | 3 ++ pkg/wconfig/metaconsts.go | 3 ++ pkg/wconfig/settingsconfig.go | 31 +++++++------- 5 files changed, 61 insertions(+), 25 deletions(-) diff --git a/frontend/app/view/codeeditor/codeeditor.tsx b/frontend/app/view/codeeditor/codeeditor.tsx index 256a13846..aca418143 100644 --- a/frontend/app/view/codeeditor/codeeditor.tsx +++ b/frontend/app/view/codeeditor/codeeditor.tsx @@ -122,6 +122,7 @@ export function CodeEditor({ blockId, text, language, filename, meta, onChange, const minimapEnabled = useOverrideConfigAtom(blockId, "editor:minimapenabled") ?? false; const stickyScrollEnabled = useOverrideConfigAtom(blockId, "editor:stickyscrollenabled") ?? false; const wordWrap = useOverrideConfigAtom(blockId, "editor:wordwrap") ?? false; + const fontSize = useOverrideConfigAtom(blockId, "editor:fontsize"); const theme = "wave-theme-dark"; React.useEffect(() => { @@ -150,8 +151,9 @@ export function CodeEditor({ blockId, text, language, filename, meta, onChange, opts.minimap.enabled = minimapEnabled; opts.stickyScroll.enabled = stickyScrollEnabled; opts.wordWrap = wordWrap ? "on" : "off"; + opts.fontSize = fontSize; return opts; - }, [minimapEnabled, stickyScrollEnabled, wordWrap]); + }, [minimapEnabled, stickyScrollEnabled, wordWrap, fontSize]); return (
diff --git a/frontend/app/view/waveai/waveai.tsx b/frontend/app/view/waveai/waveai.tsx index b84bdd37f..0bdc2412b 100644 --- a/frontend/app/view/waveai/waveai.tsx +++ b/frontend/app/view/waveai/waveai.tsx @@ -8,7 +8,7 @@ import { RpcResponseHelper, WshClient } from "@/app/store/wshclient"; import { RpcApi } from "@/app/store/wshclientapi"; import { makeFeBlockRouteId } from "@/app/store/wshrouter"; import { DefaultRouter, TabRpcClient } from "@/app/store/wshrpcutil"; -import { atoms, createBlock, fetchWaveFile, getApi, globalStore, WOS } from "@/store/global"; +import { atoms, createBlock, fetchWaveFile, getApi, globalStore, useOverrideConfigAtom, WOS } from "@/store/global"; import { BlockService, ObjectService } from "@/store/services"; import { adaptFromReactOrNativeKeyEvent, checkKeyPressed } from "@/util/keyutil"; import { fireAndForget, isBlank, makeIconClass } from "@/util/util"; @@ -30,6 +30,7 @@ const slidingWindowSize = 30; interface ChatItemProps { chatItem: ChatMessageType; + model: WaveAiModel; } function promptToMsg(prompt: OpenAIPromptMessageType): ChatMessageType { @@ -430,11 +431,12 @@ function makeWaveAiViewModel(blockId: string): WaveAiModel { return waveAiModel; } -const ChatItem = ({ chatItem }: ChatItemProps) => { +const ChatItem = ({ chatItem, model }: ChatItemProps) => { const { user, text } = chatItem; const cssVar = "--panel-bg-color"; const panelBgColor = getComputedStyle(document.documentElement).getPropertyValue(cssVar).trim(); - + const fontSize = useOverrideConfigAtom(model.blockId, "ai:fontsize"); + const fixedFontSize = useOverrideConfigAtom(model.blockId, "ai:fixedfontsize"); const renderContent = useMemo(() => { if (user == "error") { return ( @@ -445,7 +447,12 @@ const ChatItem = ({ chatItem }: ChatItemProps) => {
- +
); @@ -459,7 +466,12 @@ const ChatItem = ({ chatItem }: ChatItemProps) => {
- +
) : ( @@ -474,11 +486,17 @@ const ChatItem = ({ chatItem }: ChatItemProps) => { return ( <>
- +
); - }, [text, user]); + }, [text, user, fontSize, fixedFontSize]); return
{renderContent}
; }; @@ -487,10 +505,11 @@ interface ChatWindowProps { chatWindowRef: React.RefObject; messages: ChatMessageType[]; msgWidths: Object; + model: WaveAiModel; } const ChatWindow = memo( - forwardRef(({ chatWindowRef, messages, msgWidths }, ref) => { + forwardRef(({ chatWindowRef, messages, msgWidths, model }, ref) => { const [isUserScrolling, setIsUserScrolling] = useState(false); const osRef = useRef(null); @@ -559,7 +578,7 @@ const ChatWindow = memo(
{messages.map((chitem, idx) => ( - + ))}
@@ -804,7 +823,13 @@ const WaveAi = ({ model }: { model: WaveAiModel; blockId: string }) => { return (
- +
diff --git a/frontend/types/gotypes.d.ts b/frontend/types/gotypes.d.ts index afd3e6d24..afd817690 100644 --- a/frontend/types/gotypes.d.ts +++ b/frontend/types/gotypes.d.ts @@ -617,6 +617,8 @@ declare global { "ai:apiversion"?: string; "ai:maxtokens"?: number; "ai:timeoutms"?: number; + "ai:fontsize"?: number; + "ai:fixedfontsize"?: number; "term:*"?: boolean; "term:fontsize"?: number; "term:fontfamily"?: string; @@ -629,6 +631,7 @@ declare global { "editor:minimapenabled"?: boolean; "editor:stickyscrollenabled"?: boolean; "editor:wordwrap"?: boolean; + "editor:fontsize"?: number; "web:*"?: boolean; "web:openlinksinternally"?: boolean; "web:defaulturl"?: string; diff --git a/pkg/wconfig/metaconsts.go b/pkg/wconfig/metaconsts.go index 42c7c89bd..6e62b5c20 100644 --- a/pkg/wconfig/metaconsts.go +++ b/pkg/wconfig/metaconsts.go @@ -17,6 +17,8 @@ const ( ConfigKey_AIApiVersion = "ai:apiversion" ConfigKey_AiMaxTokens = "ai:maxtokens" ConfigKey_AiTimeoutMs = "ai:timeoutms" + ConfigKey_AiFontSize = "ai:fontsize" + ConfigKey_AiFixedFontSize = "ai:fixedfontsize" ConfigKey_TermClear = "term:*" ConfigKey_TermFontSize = "term:fontsize" @@ -31,6 +33,7 @@ const ( ConfigKey_EditorMinimapEnabled = "editor:minimapenabled" ConfigKey_EditorStickyScrollEnabled = "editor:stickyscrollenabled" ConfigKey_EditorWordWrap = "editor:wordwrap" + ConfigKey_EditorFontSize = "editor:fontsize" ConfigKey_WebClear = "web:*" ConfigKey_WebOpenLinksInternally = "web:openlinksinternally" diff --git a/pkg/wconfig/settingsconfig.go b/pkg/wconfig/settingsconfig.go index dc2671e4a..6b9e58319 100644 --- a/pkg/wconfig/settingsconfig.go +++ b/pkg/wconfig/settingsconfig.go @@ -33,17 +33,19 @@ const AnySchema = ` ` type SettingsType struct { - AiClear bool `json:"ai:*,omitempty"` - AiPreset string `json:"ai:preset,omitempty"` - AiApiType string `json:"ai:apitype,omitempty"` - AiBaseURL string `json:"ai:baseurl,omitempty"` - AiApiToken string `json:"ai:apitoken,omitempty"` - AiName string `json:"ai:name,omitempty"` - AiModel string `json:"ai:model,omitempty"` - AiOrgID string `json:"ai:orgid,omitempty"` - AIApiVersion string `json:"ai:apiversion,omitempty"` - AiMaxTokens float64 `json:"ai:maxtokens,omitempty"` - AiTimeoutMs float64 `json:"ai:timeoutms,omitempty"` + AiClear bool `json:"ai:*,omitempty"` + AiPreset string `json:"ai:preset,omitempty"` + AiApiType string `json:"ai:apitype,omitempty"` + AiBaseURL string `json:"ai:baseurl,omitempty"` + AiApiToken string `json:"ai:apitoken,omitempty"` + AiName string `json:"ai:name,omitempty"` + AiModel string `json:"ai:model,omitempty"` + AiOrgID string `json:"ai:orgid,omitempty"` + AIApiVersion string `json:"ai:apiversion,omitempty"` + AiMaxTokens float64 `json:"ai:maxtokens,omitempty"` + AiTimeoutMs float64 `json:"ai:timeoutms,omitempty"` + AiFontSize float64 `json:"ai:fontsize,omitempty"` + AiFixedFontSize float64 `json:"ai:fixedfontsize,omitempty"` TermClear bool `json:"term:*,omitempty"` TermFontSize float64 `json:"term:fontsize,omitempty"` @@ -55,9 +57,10 @@ type SettingsType struct { TermScrollback *int64 `json:"term:scrollback,omitempty"` TermCopyOnSelect *bool `json:"term:copyonselect,omitempty"` - EditorMinimapEnabled bool `json:"editor:minimapenabled,omitempty"` - EditorStickyScrollEnabled bool `json:"editor:stickyscrollenabled,omitempty"` - EditorWordWrap bool `json:"editor:wordwrap,omitempty"` + EditorMinimapEnabled bool `json:"editor:minimapenabled,omitempty"` + EditorStickyScrollEnabled bool `json:"editor:stickyscrollenabled,omitempty"` + EditorWordWrap bool `json:"editor:wordwrap,omitempty"` + EditorFontSize float64 `json:"editor:fontsize,omitempty"` WebClear bool `json:"web:*,omitempty"` WebOpenLinksInternally bool `json:"web:openlinksinternally,omitempty"`