ensure non-null prefilled data doesn't uncorrectly retain previous loop entry

This commit is contained in:
Adam D. Ruppe 2025-06-18 19:43:18 -04:00
parent c284a5c857
commit 716301f01a
1 changed files with 21 additions and 12 deletions

View File

@ -2582,6 +2582,7 @@ http://msdn.microsoft.com/en-us/library/windows/desktop/ms683193%28v=vs.85%29.as
lineGetter.prompt = prompt; lineGetter.prompt = prompt;
if(prefilledData) { if(prefilledData) {
lineGetter.clear();
lineGetter.addString(prefilledData); lineGetter.addString(prefilledData);
lineGetter.maintainBuffer = true; lineGetter.maintainBuffer = true;
} }
@ -6540,17 +6541,12 @@ class LineGetter {
void startGettingLine() { void startGettingLine() {
// reset from any previous call first // reset from any previous call first
if(!maintainBuffer) { if(!maintainBuffer) {
cursorPosition = 0; clear();
horizontalScrollPosition = 0;
verticalScrollPosition = 0;
justHitTab = false;
currentHistoryViewPosition = 0; currentHistoryViewPosition = 0;
if(line.length) {
line = line[0 .. 0];
line.assumeSafeAppend();
}
} }
justHitTab = false;
maintainBuffer = false; maintainBuffer = false;
initializeWithSize(true); initializeWithSize(true);
@ -6795,6 +6791,22 @@ class LineGetter {
return supplementalGetter !is null; 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 Cancels an in-progress history search immediately, discarding the result, returning
to the normal prompt. to the normal prompt.
@ -6974,10 +6986,7 @@ class LineGetter {
if(multiLineMode) if(multiLineMode)
multiLineMode = false; multiLineMode = false;
else { else {
cursorPosition = 0; clear();
horizontalScrollPosition = 0;
line = line[0 .. 0];
line.assumeSafeAppend();
} }
redraw(); redraw();
break; break;