fix: prompt line still wraps+overlaps on long ghost text — hard-clip from front in JS
This commit is contained in:
+20
-1
@@ -15,6 +15,25 @@
|
||||
// right so the left (older) part clips off terminal-style instead of wrapping.
|
||||
function keepEnd() { if (promptEl) promptEl.scrollLeft = promptEl.scrollWidth; }
|
||||
|
||||
// hard guarantee: the prompt is ALWAYS one line. CSS (nowrap + overflow:hidden)
|
||||
// is normally enough, but a long ghost command (long path + filename) can still
|
||||
// force the line to wrap on some viewports/browsers, which then bugs out the
|
||||
// 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
|
||||
// mark the cut with "…" — the leading verb ("cat "/"cd ") is allowed to go first.
|
||||
function fitOneLine(text) {
|
||||
if (!promptEl) return text;
|
||||
promptEl.scrollLeft = 0; // measure from a clean, unscrolled state
|
||||
input.textContent = text;
|
||||
if (promptEl.scrollWidth <= promptEl.clientWidth) return text;
|
||||
var shown = text;
|
||||
while (shown.length > 1 && promptEl.scrollWidth > promptEl.clientWidth) {
|
||||
shown = shown.slice(1);
|
||||
input.textContent = "…" + shown;
|
||||
}
|
||||
return input.textContent;
|
||||
}
|
||||
|
||||
var home = bar.getAttribute("data-home") || "/";
|
||||
|
||||
// command → url: the always-open menu, plus any context routes (e.g. the
|
||||
@@ -45,7 +64,7 @@
|
||||
var ghostActive = false;
|
||||
function setGhost(text) {
|
||||
if (!ghostActive && input.textContent) return; // never clobber a real command in progress
|
||||
input.textContent = text;
|
||||
fitOneLine(text);
|
||||
ghostActive = true;
|
||||
input.classList.add("is-ghost");
|
||||
caretToEnd();
|
||||
|
||||
Reference in New Issue
Block a user