mirror of
https://github.com/KDE/konsole.git
synced 2025-12-23 23:38:08 -05:00
Fix search wrapping behavior at boundaries
Issues: - At the second-to-last line, "Find Next" doesn't wrap to the start. - At the second line, "Find Previous" doesn't wrap to the end. These issues occurred because the initial value of startLine equaled endLine, causing the loop to terminate after one cycle. Changes: - Added a continueLoop flag: In wrap mode, the loop only terminates when hasWrapped is true. - Added an invertDirection flag to control the continueLoop flag in no-wrap mode. BUG: 396510
This commit is contained in:
committed by
Christoph Cullmann
parent
ff6246f999
commit
b83680a693
@@ -78,6 +78,8 @@ void SearchHistoryTask::executeOnScreenWindow(const QPointer<Session> &session,
|
||||
int delta = forwards ? maxDelta : -maxDelta;
|
||||
|
||||
int endLine = line;
|
||||
bool continueLoop = true;
|
||||
bool invertDirection = false;
|
||||
bool hasWrapped = false; // set to true when we reach the top/bottom
|
||||
// of the output and continue from the other
|
||||
// end
|
||||
@@ -126,9 +128,15 @@ void SearchHistoryTask::executeOnScreenWindow(const QPointer<Session> &session,
|
||||
endLine += delta;
|
||||
|
||||
if (forwards) {
|
||||
endLine = qMin(startLine, endLine);
|
||||
if (endLine >= startLine) {
|
||||
endLine = startLine;
|
||||
continueLoop = false;
|
||||
}
|
||||
} else {
|
||||
endLine = qMax(startLine, endLine);
|
||||
if (endLine <= startLine) {
|
||||
endLine = startLine;
|
||||
continueLoop = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
endLine += delta;
|
||||
@@ -177,7 +185,11 @@ void SearchHistoryTask::executeOnScreenWindow(const QPointer<Session> &session,
|
||||
|
||||
// if noWrap is checked and we wrapped, set cursor at last match
|
||||
if (hasWrapped && _noWrap) {
|
||||
// invert search direction
|
||||
// one chance to invert search direction
|
||||
if (invertDirection) {
|
||||
continueLoop = false;
|
||||
}
|
||||
invertDirection = true;
|
||||
forwards = !forwards;
|
||||
delta = -delta;
|
||||
endLine += (forwards ? 1 : -1);
|
||||
@@ -187,7 +199,7 @@ void SearchHistoryTask::executeOnScreenWindow(const QPointer<Session> &session,
|
||||
// clear the current block of text and move to the next one
|
||||
string.clear();
|
||||
line = endLine;
|
||||
} while (startLine != endLine);
|
||||
} while (continueLoop);
|
||||
if (!session->getSelectMode()) {
|
||||
// if no match was found, clear selection to indicate this,
|
||||
window->clearSelection();
|
||||
|
||||
Reference in New Issue
Block a user