fix(tui): position cursor for prompt history navigation

closes #5454
This commit is contained in:
Mario Zechner
2026-06-07 10:56:09 +02:00
parent 22ac2713a3
commit 59d7025668
3 changed files with 41 additions and 43 deletions

View File

@@ -390,16 +390,16 @@ export class Editor implements Component, Focusable {
// Returned to "current" state - clear editor
this.setTextInternal("");
} else {
this.setTextInternal(this.history[this.historyIndex] || "");
this.setTextInternal(this.history[this.historyIndex] || "", direction === -1 ? "start" : "end");
}
}
/** Internal setText that doesn't reset history state - used by navigateHistory */
private setTextInternal(text: string): void {
private setTextInternal(text: string, cursorPlacement: "start" | "end" = "end"): void {
const lines = text.split("\n");
this.state.lines = lines.length === 0 ? [""] : lines;
this.state.cursorLine = this.state.lines.length - 1;
this.setCursorCol(this.state.lines[this.state.cursorLine]?.length || 0);
this.state.cursorLine = cursorPlacement === "start" ? 0 : this.state.lines.length - 1;
this.setCursorCol(cursorPlacement === "start" ? 0 : this.state.lines[this.state.cursorLine]?.length || 0);
// Reset scroll - render() will adjust to show cursor
this.scrollOffset = 0;