From 716301f01a5d328c31a8d69a46d53ace9a3b23c1 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Wed, 18 Jun 2025 19:43:18 -0400 Subject: [PATCH] ensure non-null prefilled data doesn't uncorrectly retain previous loop entry --- terminal.d | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/terminal.d b/terminal.d index 8d2c6cf..9fd2bcc 100644 --- a/terminal.d +++ b/terminal.d @@ -2582,6 +2582,7 @@ http://msdn.microsoft.com/en-us/library/windows/desktop/ms683193%28v=vs.85%29.as lineGetter.prompt = prompt; if(prefilledData) { + lineGetter.clear(); lineGetter.addString(prefilledData); lineGetter.maintainBuffer = true; } @@ -6540,17 +6541,12 @@ class LineGetter { void startGettingLine() { // reset from any previous call first if(!maintainBuffer) { - cursorPosition = 0; - horizontalScrollPosition = 0; - verticalScrollPosition = 0; - justHitTab = false; + clear(); currentHistoryViewPosition = 0; - if(line.length) { - line = line[0 .. 0]; - line.assumeSafeAppend(); - } } + justHitTab = false; + maintainBuffer = false; initializeWithSize(true); @@ -6795,6 +6791,22 @@ class LineGetter { return supplementalGetter !is null; } + /++ + Clears the buffer. + + History: + Added June 18, 2025 (dub v12.1) + +/ + void clear() { + cursorPosition = 0; + horizontalScrollPosition = 0; + verticalScrollPosition = 0; + if(line.length) { + line = line[0 .. 0]; + line.assumeSafeAppend(); + } + } + /++ Cancels an in-progress history search immediately, discarding the result, returning to the normal prompt. @@ -6974,10 +6986,7 @@ class LineGetter { if(multiLineMode) multiLineMode = false; else { - cursorPosition = 0; - horizontalScrollPosition = 0; - line = line[0 .. 0]; - line.assumeSafeAppend(); + clear(); } redraw(); break;