fix(frontend): make general-settings font picker actually work

The font picker in 常规设置 silently failed in three distinct ways:

1. Font family changes were invisible on macOS because 6 of the 7 options
   (Inter / Roboto / Segoe UI / Cascadia Code / JetBrains Mono / Fira
   Code) aren't installed by default and fell back to system SF. Swap
   the picker to a platform-aware list — Mac / Windows / Linux each see
   only the fonts their OS actually ships. The "third sans slot" now
   always serves a serif face (Georgia / Times New Roman / DejaVu
   Serif) so the difference is unambiguously visible instead of being
   three near-identical sans families.

2. Font size flipped --app-font-scale on <html>, but that variable was
   only consumed by a handful of TDesign tokens and the body reset, so
   the ~1000+ hard-coded font-size: NNpx rules across the frontend
   stayed put. Apply the multiplier via `zoom` on <html> so the whole
   document scales, then fix the 15 `100vh` rules that would overflow
   under zoom (html / body / #app are already height: 100%, so the
   descendants can use 100% too).

3. The monospace picker had no visible effect even on a working stack
   because `<t-input style="font-family: ...">` is forwarded to the
   inner <input>, but TDesign applies `font: var(--td-font-body-medium)`
   — a shorthand that resets font-family. Reach the real <input> /
   <textarea> via `:deep()` instead of inline style.

Additional polish:
- Add a live preview row under each picker so users can see the effect
  without hunting for a code block or API Info screen
- Rename "等宽字体 / Monospace Font" → "代码字体 / Code Font" to match
  VSCode / GitHub / Notion convention; the old label was jargon
- Rewrite descriptions to explain the actual purpose and scope
This commit is contained in:
wizardchen
2026-05-07 15:02:47 +08:00
committed by lyingbug
parent fb9ae11aa8
commit 4a5caf54af
17 changed files with 362 additions and 119 deletions
+1 -1
View File
@@ -962,7 +962,7 @@ defineExpose({
<style scoped lang="less">
.agent-list-container {
margin: 0 16px 0 0;
height: calc(100vh);
height: 100%;
box-sizing: border-box;
flex: 1;
display: flex;
+1 -1
View File
@@ -699,7 +699,7 @@ onMounted(async () => {
.login-layout {
display: flex;
width: 100%;
min-height: 100vh;
min-height: 100%;
overflow: hidden;
position: relative;
background: linear-gradient(225deg, #022c22 0%, #064e3b 15%, #065f46 25%, #047857 38%, #059669 50%, #07C05F 65%, #10B981 78%, #34D399 90%, #6EE7B7 100%);
@@ -1248,7 +1248,7 @@ const handleUploadFinishedEvent = (event: Event) => {
<style scoped lang="less">
.kb-list-container {
margin: 0 16px 0 0;
height: calc(100vh);
height: 100%;
box-sizing: border-box;
flex: 1;
display: flex;
@@ -65,7 +65,7 @@ const goToOrganizations = () => {
<style scoped lang="less">
.join-page {
min-height: 100vh;
min-height: 100%;
display: flex;
align-items: center;
justify-content: center;
@@ -1237,7 +1237,7 @@ onUnmounted(() => {
<style scoped lang="less">
.org-list-container {
margin: 0 16px 0 0;
height: calc(100vh);
height: 100%;
box-sizing: border-box;
flex: 1;
display: flex;
+16 -3
View File
@@ -162,7 +162,8 @@
@blur="handleSystemPromptChange"
@input="handlePromptInput"
@keydown="handlePromptKeydown"
style="width: 100%; font-family: var(--app-font-family-mono); font-size: 13px;"
class="mono-text-input"
style="width: 100%;"
/>
<PromptTemplateSelector
type="agentSystemPrompt"
@@ -220,7 +221,8 @@
:autosize="{ minRows: 10, maxRows: 20 }"
:placeholder="$t('conversationSettings.systemPrompt.placeholder')"
@blur="handleSystemPromptNormalChange"
style="width: 100%; font-family: var(--app-font-family-mono); font-size: 13px;"
class="mono-text-input"
style="width: 100%;"
/>
<PromptTemplateSelector
type="systemPrompt"
@@ -246,7 +248,8 @@
:autosize="{ minRows: 15, maxRows: 30 }"
:placeholder="$t('conversationSettings.contextTemplate.placeholder')"
@blur="handleContextTemplateChange"
style="width: 100%; font-family: var(--app-font-family-mono); font-size: 13px;"
class="mono-text-input"
style="width: 100%;"
/>
<PromptTemplateSelector
type="contextTemplate"
@@ -1749,6 +1752,16 @@ const handleConversationRerankModelChange = async (value: string) => {
width: 100%;
}
// TDesign's <t-input>/<t-textarea> forwards `style=""` to its wrapper but
// applies `font: var(--td-font-body-medium)` (a shorthand) to the inner
// <input>/<textarea>, which silently resets font-family. Reach into those
// elements explicitly so the code font takes effect for prompt editors.
.mono-text-input :deep(input),
.mono-text-input :deep(textarea) {
font-family: var(--app-font-family-mono);
font-size: 13px;
}
.section-header {
+19 -6
View File
@@ -30,11 +30,12 @@
</div>
<div class="setting-control">
<div class="api-key-control">
<t-input
v-model="displayApiKey"
readonly
<t-input
v-model="displayApiKey"
readonly
type="text"
style="width: 100%; font-family: var(--app-font-family-mono); font-size: 12px;"
class="mono-text-input"
style="width: 100%;"
/>
<t-button
size="small"
@@ -77,7 +78,8 @@
:model-value="apiBaseUrlDisplay"
readonly
type="text"
style="width: 100%; font-family: var(--app-font-family-mono); font-size: 12px;"
class="mono-text-input"
style="width: 100%;"
/>
<t-button
size="small"
@@ -136,7 +138,8 @@
:model-value="wailsApiLanBaseURL"
readonly
type="text"
style="width: 100%; font-family: var(--app-font-family-mono); font-size: 12px;"
class="mono-text-input"
style="width: 100%;"
/>
<t-button
size="small"
@@ -571,6 +574,16 @@ onMounted(async () => {
width: 100%;
}
// TDesign's <t-input> forwards `style=""` to its wrapper but applies
// `font: var(--td-font-body-medium)` (a shorthand) to the real <input>
// inside, which silently resets font-family. Reach into the inner input
// explicitly so the code font actually takes effect for API keys, URLs,
// etc. Scoped via `.mono-text-input` so this only applies where we opt in.
.mono-text-input :deep(input) {
font-family: var(--app-font-family-mono);
font-size: 12px;
}
.section-header {
margin-bottom: 32px;
+60 -21
View File
@@ -53,7 +53,7 @@
<label>{{ $t('font.uiFont') }}</label>
<p class="desc">{{ $t('font.uiFontDescription') }}</p>
</div>
<div class="setting-control">
<div class="setting-control setting-control--stacked">
<t-select
v-model="localSansFont"
style="width: 280px;"
@@ -69,16 +69,19 @@
<span :style="{ fontFamily: opt.preview }">{{ opt.label }}</span>
</t-option>
</t-select>
<div class="font-preview" :style="{ fontFamily: currentSansStack }">
{{ $t('font.sansPreview') }}
</div>
</div>
</div>
<!-- 等宽字体 -->
<!-- 代码字体 -->
<div class="setting-row">
<div class="setting-info">
<label>{{ $t('font.monoFont') }}</label>
<p class="desc">{{ $t('font.monoFontDescription') }}</p>
</div>
<div class="setting-control">
<div class="setting-control setting-control--stacked">
<t-select
v-model="localMonoFont"
style="width: 280px;"
@@ -94,6 +97,9 @@
<span :style="{ fontFamily: opt.preview }">{{ opt.label }}</span>
</t-option>
</t-select>
<div class="font-preview font-preview--mono" :style="{ fontFamily: currentMonoStack }">
{{ $t('font.monoPreview') }}
</div>
</div>
</div>
@@ -170,6 +176,8 @@ import {
useFont,
SANS_STACKS,
MONO_STACKS,
visibleSansKeys,
visibleMonoKeys,
type FontKey,
type MonoFontKey,
type FontSizeKey,
@@ -201,25 +209,27 @@ watch(currentSans, (val) => { localSansFont.value = val })
watch(currentMono, (val) => { localMonoFont.value = val })
watch(currentSize, (val) => { localFontSize.value = val })
const sansFontOptions = computed<{ value: FontKey; label: string; preview: string }[]>(() => [
{ value: 'system', label: t('font.sans.system'), preview: SANS_STACKS.system },
{ value: 'pingfang', label: t('font.sans.pingfang'), preview: SANS_STACKS.pingfang },
{ value: 'inter', label: t('font.sans.inter'), preview: SANS_STACKS.inter },
{ value: 'helvetica', label: t('font.sans.helvetica'), preview: SANS_STACKS.helvetica },
{ value: 'segoe', label: t('font.sans.segoe'), preview: SANS_STACKS.segoe },
{ value: 'roboto', label: t('font.sans.roboto'), preview: SANS_STACKS.roboto },
{ value: 'sans-serif', label: t('font.sans.sansSerif'), preview: SANS_STACKS['sans-serif'] },
])
const sansFontOptions = computed<{ value: FontKey; label: string; preview: string }[]>(() =>
visibleSansKeys().map((key) => ({
value: key,
label: t(`font.sans.${key}`),
preview: SANS_STACKS[key],
})),
)
const monoFontOptions = computed<{ value: MonoFontKey; label: string; preview: string }[]>(() => [
{ value: 'system', label: t('font.mono.system'), preview: MONO_STACKS.system },
{ value: 'cascadia', label: t('font.mono.cascadia'), preview: MONO_STACKS.cascadia },
{ value: 'jetbrains', label: t('font.mono.jetbrains'), preview: MONO_STACKS.jetbrains },
{ value: 'fira', label: t('font.mono.fira'), preview: MONO_STACKS.fira },
{ value: 'monaco', label: t('font.mono.monaco'), preview: MONO_STACKS.monaco },
{ value: 'consolas', label: t('font.mono.consolas'), preview: MONO_STACKS.consolas },
{ value: 'monospace', label: t('font.mono.monospace'), preview: MONO_STACKS.monospace },
])
const monoFontOptions = computed<{ value: MonoFontKey; label: string; preview: string }[]>(() =>
visibleMonoKeys().map((key) => ({
value: key,
label: t(`font.mono.${key}`),
preview: MONO_STACKS[key],
})),
)
// Live preview stacks, driven by the local form refs so the preview row
// updates immediately on selection — even before handleSansFontChange
// commits the choice to the global store and writes the CSS variable.
const currentSansStack = computed(() => SANS_STACKS[localSansFont.value] ?? SANS_STACKS.system)
const currentMonoStack = computed(() => MONO_STACKS[localMonoFont.value] ?? MONO_STACKS.system)
// 系统信息
const systemInfo = ref<any>(null)
@@ -396,4 +406,33 @@ const handleFontSizeChange = (val: FontSizeKey) => {
justify-content: flex-end;
align-items: center;
}
// When a font picker is rendered, stack the select on top of a live
// preview line so the user can verify their choice without hunting for
// an API Info page or a code block.
.setting-control--stacked {
flex-direction: column;
align-items: flex-end;
gap: 8px;
}
.font-preview {
width: 280px;
padding: 8px 12px;
border: 1px solid var(--td-component-stroke);
border-radius: var(--td-radius-medium);
background: var(--td-bg-color-container);
color: var(--td-text-color-primary);
font-size: 14px;
line-height: 1.4;
text-align: left;
box-sizing: border-box;
&--mono {
// Harden the preview against wrap-around for long monospace samples.
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
</style>