fix: ghost-text clip also respects the de/en lang-switch at the row end

This commit is contained in:
kgva CMS
2026-08-10 21:20:20 +00:00
parent b37c1a94be
commit 121273ff54
+16 -2
View File
@@ -21,13 +21,27 @@
// layout below it. so on top of the CSS, actually shorten the text in the DOM: // layout below it. so on top of the CSS, actually shorten the text in the DOM:
// clip from the FRONT (oldest part, same side as the terminal-scroll above) and // clip from the FRONT (oldest part, same side as the terminal-scroll above) and
// mark the cut with "…" — the leading verb ("cat "/"cd ") is allowed to go first. // mark the cut with "…" — the leading verb ("cat "/"cd ") is allowed to go first.
//
// the lang-switch (de/en) is position:absolute top-right over the same row —
// CSS reserves padding-right for it, but that padding doesn't actually stop
// overflowing nowrap text (padding isn't a layout barrier for overflow), so a
// long enough line still slides under it. check the real rendered edges too,
// not just clientWidth, so the toggle at the far end is never covered.
function overlapsLangSwitch() {
var ls = document.querySelector(".lang-switch");
if (!ls) return false;
var lsRect = ls.getBoundingClientRect();
var inRect = input.getBoundingClientRect();
return inRect.right > lsRect.left - 8; // 8px breathing room
}
function fits() { return promptEl.scrollWidth <= promptEl.clientWidth && !overlapsLangSwitch(); }
function fitOneLine(text) { function fitOneLine(text) {
if (!promptEl) return text; if (!promptEl) return text;
promptEl.scrollLeft = 0; // measure from a clean, unscrolled state promptEl.scrollLeft = 0; // measure from a clean, unscrolled state
input.textContent = text; input.textContent = text;
if (promptEl.scrollWidth <= promptEl.clientWidth) return text; if (fits()) return text;
var shown = text; var shown = text;
while (shown.length > 1 && promptEl.scrollWidth > promptEl.clientWidth) { while (shown.length > 1 && !fits()) {
shown = shown.slice(1); shown = shown.slice(1);
input.textContent = "…" + shown; input.textContent = "…" + shown;
} }