From dd9a31e301e756ce31a58915d8bbad404af18969 Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Mon, 20 Jul 2026 14:49:59 +0300 Subject: [PATCH] Stabilize panel speed label width Cap formatBytesShort at four characters by rolling the mantissa up to the next unit once it reaches 1000, and give .sbx-speed-label a fixed min-width so the panel widget no longer shifts horizontally as speed values change. Co-Authored-By: Claude Opus 4.8 (1M context) --- lib/format.js | 9 ++++++++- stylesheet.css | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/format.js b/lib/format.js index 8cd6243..f6c7c86 100644 --- a/lib/format.js +++ b/lib/format.js @@ -21,8 +21,15 @@ export function formatBytes(n) { } // Compact for the panel: "2.4M", "120K", "0". +// Keeps the mantissa under three integer digits so a value is at most four +// characters wide ("999K", "9.9M", "1023") — the panel field has a fixed width +// and must never overflow it (see .sbx-speed-label in stylesheet.css). export function formatBytesShort(n) { - const [v, i] = scale(n); + let [v, i] = scale(n); + if (i > 0 && v >= 1000 && i < SHORT_UNITS.length - 1) { + v /= 1024; + i += 1; + } if (i === 0) return `${Math.round(v)}`; const digits = v < 10 ? 1 : 0; diff --git a/stylesheet.css b/stylesheet.css index 7430beb..bd435da 100644 --- a/stylesheet.css +++ b/stylesheet.css @@ -15,6 +15,10 @@ .sbx-speed-label { font-feature-settings: "tnum"; font-size: 0.9em; + /* Fixed width so the panel widget doesn't shift as speed values change. + Sized for the widest field: "↓1023 ↑1023" (see formatBytesShort). */ + min-width: 7.5em; + text-align: left; } .sbx-status-item {