diff --git a/src/app/components/ChatInterface.tsx b/src/app/components/ChatInterface.tsx index f06eeb0..9fe3027 100644 --- a/src/app/components/ChatInterface.tsx +++ b/src/app/components/ChatInterface.tsx @@ -2662,6 +2662,9 @@ function GenerationParamSlider({ }) { const anchor = override ?? fallback ?? min; const [draft, setDraft] = useState(null); + const [editing, setEditing] = useState(false); + const [editText, setEditText] = useState(""); + const editActiveRef = useRef(false); const shown = draft ?? anchor; const isOverride = override !== null || draft !== null; @@ -2672,6 +2675,29 @@ function GenerationParamSlider({ } }; + const startEdit = () => { + setEditText(shown.toFixed(2)); + editActiveRef.current = true; + setEditing(true); + }; + + const finishEdit = (shouldCommit: boolean) => { + if (!editActiveRef.current) return; + editActiveRef.current = false; + setEditing(false); + if (!shouldCommit) return; + const trimmed = editText.trim(); + if (trimmed === "") { + // Empty input resets to the registry default (only meaningful when an + // override exists). + if (override !== null) void onCommit(null); + return; + } + const parsed = Number(trimmed); + if (!Number.isFinite(parsed) || parsed < min || parsed > max) return; + commit(parsed); + }; + return ( commit(Number(event.target.value))} className="w-16 cursor-pointer accent-[var(--brand)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed" /> - + {editing ? ( + setEditText(event.target.value)} + onFocus={(event) => event.target.select()} + onKeyDown={(event) => { + if (event.key === "Enter") { + event.preventDefault(); + finishEdit(true); + } else if (event.key === "Escape") { + event.preventDefault(); + finishEdit(false); + } + }} + onBlur={() => finishEdit(true)} + className="w-12 text-left text-xs tabular-nums font-medium text-foreground bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" + /> + ) : ( + + )} ); }