Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(web): model settings fields reserve the room their in-field units really take (#683)

Yaowei Zheng9f79a406bbd2
diff --git a/changelog/unreleased/2026-09-11-price-unit-overlap.md b/changelog/unreleased/2026-09-11-price-unit-overlap.md
new file mode 100644
index 00000000..5e02f013
--- /dev/null
+++ b/changelog/unreleased/2026-09-11-price-unit-overlap.md
@@ -0,0 +1,25 @@
+# The model settings fields size their own in-field units
+
+- **Date:** 2026-09-11
+- **Type:** fix
+- **Scope:** `web`
+- **PR:** [#683](https://github.com/Prism-Shadow/penguin-harness/pull/683)
+
+[中文版](2026-09-11-price-unit-overlap.zh.md)
+
+Five inputs in the model settings dialog draw a unit inside their own box and reserved room for
+it with a fixed padding. Each reserve is now derived from the width its unit actually renders at,
+measured live, so the value keeps the same gap from it whatever the resolved font, the interface
+font size and the selected currency make that unit.
+
+## Details
+
+- The three price fields carry the currency symbol on the left and `/M tok` on the right. The
+ right reserve was 1.2px narrower than the unit occupies at the default interface font, so the
+ value ran into `/M tok` at every font size, in both currencies and both languages.
+- The context window and max output tokens fields carry the `Token` unit, whose fixed reserve ran
+ 5.8–7.3px wider than it occupies. Both now leave the same measured gap as the price fields.
+- The max output tokens placeholder is wider than its half-width cell in English, and an input
+ clips at its padding box rather than at its value area, so the placeholder reached the unit and
+ read as `Empty = inherit agent set Token`. Both fields in that row now end an overlong
+ placeholder in an ellipsis; the full text stays on the field's hover title.
diff --git a/changelog/unreleased/2026-09-11-price-unit-overlap.zh.md b/changelog/unreleased/2026-09-11-price-unit-overlap.zh.md
new file mode 100644
index 00000000..d5174b03
--- /dev/null
+++ b/changelog/unreleased/2026-09-11-price-unit-overlap.zh.md
@@ -0,0 +1,22 @@
+# 模型设置的字段按自身单位的实际宽度留位
+
+- **Date:** 2026-09-11
+- **Type:** fix
+- **Scope:** `web`
+- **PR:** [#683](https://github.com/Prism-Shadow/penguin-harness/pull/683)
+
+[English](2026-09-11-price-unit-overlap.md)
+
+模型设置对话框中有五个输入框在自身框内绘制单位,此前都用固定内边距为其留位。现在每处留位都按该单位实际
+渲染出的宽度实时测量得出,无论解析到的字体、界面字号与所选货币把单位撑成多宽,数值与它之间都保持相同
+间距。
+
+## 细节
+
+- 三个价格字段左端是货币符号、右端是 `/M tok`。右侧留位比该单位在默认界面字体下占用的宽度窄 1.2px,
+ 于是在任意字号、两种货币与两种界面语言下,数值都会与 `/M tok` 相撞。
+- 上下文窗口与最大输出长度两个字段带 `Token` 单位,其固定留位比该单位实际占用的宽度宽 5.8–7.3px。二者
+ 现在与价格字段留出同样的实测间距。
+- 最大输出长度的占位文字在英文下宽于其半宽单元格,而输入框按 padding box 而非数值区域裁剪,于是占位文字
+ 一路顶到单位处,显示为 `Empty = inherit agent set Token`。该行两个字段现在都会把过长的占位文字以省略号
+ 收尾,完整文案仍保留在字段的悬停提示中。
diff --git a/packages/web/src/features/models/models-page.tsx b/packages/web/src/features/models/models-page.tsx
index 932d8387..25c8cfe4 100644
--- a/packages/web/src/features/models/models-page.tsx
+++ b/packages/web/src/features/models/models-page.tsx
@@ -29,8 +29,16 @@
* Saving does a PUT full-table replace (models not present are deleted; an empty apiKey
* means keep the existing value); only the owner can edit.
*/
-import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from "react";
-import type { DragEvent as ReactDragEvent, ReactNode } from "react";
+import {
+ Fragment,
+ useCallback,
+ useEffect,
+ useLayoutEffect,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
+import type { DragEvent as ReactDragEvent, ReactNode, RefObject } from "react";
import type {
CredentialInfo,
ModelProtocolDetectRequest,
@@ -2141,6 +2149,46 @@ const CONFIRM_BODY: Record<DialogAction, (name: string) => string> = {
remove: (n) => S.models.confirmDelete(n),
};
+/**
+ * Live width of one affix drawn inside an input — the currency symbol, the "/M tok" price unit,
+ * the "Token" unit — so the input can reserve exactly the room it actually occupies. An affix is
+ * rendered text: its width follows the resolved font, the root font size (the appearance setting
+ * scales it) and, for the currency symbol, the selected currency, none of which is known where
+ * the padding is written, which is why it is measured rather than typed. The affix is absolutely
+ * positioned, so its size does not depend on the padding derived from it. One call covers every
+ * field drawing the same string at the same size; fields whose affixes differ take one each.
+ */
+function useAffixWidth(): [RefObject<HTMLSpanElement | null>, number] {
+ const ref = useRef<HTMLSpanElement>(null);
+ const [width, setWidth] = useState(0);
+ useLayoutEffect(() => {
+ const el = ref.current;
+ if (!el) return;
+ // The observer reports the box LAYOUT size, which is what has to be reserved. A rect read
+ // off the element would be wrong here: the dialog pops in under `scale(0.96)`, so a
+ // measurement taken while that animation runs comes back 4% short, and a transform never
+ // notifies an observer that would correct it. Delivery is after layout and before paint,
+ // so the unmeasured state is not painted; a currency switch, a language switch and a
+ // font-size change all resize the affix and re-run this.
+ const ro = new ResizeObserver(([entry]) => {
+ if (entry) setWidth(entry.borderBoxSize[0]?.inlineSize ?? entry.contentRect.width);
+ });
+ ro.observe(el);
+ return () => ro.disconnect();
+ }, []);
+ return [ref, width];
+}
+
+/**
+ * Padding that clears an affix of the given rendered width: the 0.5rem the affix is inset
+ * from the input edge (`left-2` / `right-2`), the affix itself, and 0.25rem of separation so
+ * the value does not read as one run of text with it. An unmeasured width (0) still yields a
+ * padding no smaller than the control's own, so nothing lands outside the box.
+ */
+function affixPadding(width: number): string {
+ return `calc(${width}px + 0.75rem)`;
+}
+
function ModelDialog({
projectId,
row,
@@ -2253,6 +2301,12 @@ function ModelDialog({
const [visionDetecting, setVisionDetecting] = useState(false);
/** Single-flight guard for the vision probe: it bills the user, so never twice at once. */
const visionInFlight = useRef<Promise<void> | null>(null);
+ // Room each in-field affix needs (see useAffixWidth). The three price inputs share one
+ // currency symbol and one "/M tok" unit; the context-window and max-tokens inputs share the
+ // "Token" unit with each other, so each distinct string is measured once.
+ const [currencyRef, currencyWidth] = useAffixWidth();
+ const [priceUnitRef, priceUnitWidth] = useAffixWidth();
+ const [tokenUnitRef, tokenUnitWidth] = useAffixWidth();
const isNew = row === null;
const preset = row !== null && isPreset(row);
@@ -3121,7 +3175,12 @@ function ModelDialog({
disabled={!canEdit}
invalid={Boolean(fieldErrors.contextWindow)}
onChange={(e) => set({ contextWindow: digitsOnly(e.target.value) })}
- className="pr-12 font-mono"
+ // Half-width cell: the placeholder is wider than the box in English, and an
+ // input clips at its padding box, so an unclipped one runs past the value area
+ // and collides with the unit. `truncate` ends it in an ellipsis instead, which
+ // reads as "there is more" rather than as text colliding; the title has it in full.
+ className="truncate font-mono"
+ style={{ paddingRight: affixPadding(tokenUnitWidth) }}
// The title mirrors the placeholder: at half width the (EN) copy can clip, hover reveals it in full.
title={
preset
@@ -3134,7 +3193,12 @@ function ModelDialog({
: S.models.contextWindowDefaultHint(CUSTOM_CONTEXT_DEFAULT)
}
/>
- <span className="pointer-events-none absolute inset-y-0 right-2 flex items-center text-xs text-gray-400">
+ <span
+ // Both fields in this row draw the same unit at the same size, so one
+ // measurement sizes the reserve for the pair.
+ ref={tokenUnitRef}
+ className="pointer-events-none absolute inset-y-0 right-2 flex items-center text-xs text-gray-400"
+ >
{S.models.tokenUnit}
</span>
</span>
@@ -3150,7 +3214,9 @@ function ModelDialog({
disabled={!canEdit}
invalid={Boolean(fieldErrors.maxTokens)}
onChange={(e) => set({ maxTokens: digitsOnly(e.target.value) })}
- className="pr-12 font-mono"
+ // Truncated for the same reason as the context window beside it.
+ className="truncate font-mono"
+ style={{ paddingRight: affixPadding(tokenUnitWidth) }}
// Short placeholder (fits the half-width box); the full explanation incl. the small-context advice is the hover title.
title={S.models.maxTokensTitle}
placeholder={S.models.maxTokensHint}
@@ -3174,11 +3240,16 @@ function ModelDialog({
["cacheWrite", S.models.priceCacheWrite, form.cacheWrite],
["output", S.models.priceOutput, form.output],
] as Array<[keyof FieldErrors & keyof RowState, string, string]>
- ).map(([key, label, value]) => (
+ ).map(([key, label, value], i) => (
<label key={key} className="block">
<FieldLabel>{label}</FieldLabel>
<span className="relative block">
- <span className="pointer-events-none absolute inset-y-0 left-2 flex items-center text-xs text-gray-400">
+ <span
+ // The three fields draw the same symbol and the same unit at the same size,
+ // so only the first pair is measured and every field reserves from it.
+ ref={i === 0 ? currencyRef : undefined}
+ className="pointer-events-none absolute inset-y-0 left-2 flex items-center text-xs text-gray-400"
+ >
{CURRENCY_SYMBOL[currency]}
</span>
<Input
@@ -3188,9 +3259,16 @@ function ModelDialog({
disabled={!canEdit}
invalid={Boolean(fieldErrors[key])}
onChange={(e) => set({ [key]: decimalOnly(e.target.value) })}
- className="pl-4 pr-11 text-right font-mono"
+ className="text-right font-mono"
+ style={{
+ paddingLeft: affixPadding(currencyWidth),
+ paddingRight: affixPadding(priceUnitWidth),
+ }}
/>
- <span className="pointer-events-none absolute inset-y-0 right-2 flex items-center text-xs text-gray-400">
+ <span
+ ref={i === 0 ? priceUnitRef : undefined}
+ className="pointer-events-none absolute inset-y-0 right-2 flex items-center text-xs text-gray-400"
+ >
{S.models.priceUnitShort}
</span>
</span>