| 36 | } |
| 37 | |
| 38 | void SearchHistoryTask::executeOnScreenWindow(const QPointer<Session> &session, const ScreenWindowPtr &window) |
| 39 | { |
| 40 | Q_ASSERT(session); |
| 41 | Q_ASSERT(window); |
| 42 | |
| 43 | Emulation *emulation = session->emulation(); |
| 44 | |
| 45 | if (!_regExp.pattern().isEmpty()) { |
| 46 | bool forwards = (_direction == Enum::ForwardsSearch); |
| 47 | const int lastLine = window->lineCount() - 1; |
| 48 | |
| 49 | int startLine = _startLine; |
| 50 | if (forwards && (_startLine == lastLine)) { |
| 51 | if (!_noWrap) { |
| 52 | startLine = 0; |
| 53 | } |
| 54 | } else if (!forwards && (_startLine == 0)) { |
| 55 | if (!_noWrap) { |
| 56 | startLine = lastLine; |
| 57 | } |
| 58 | } else { |
| 59 | startLine = _startLine + (forwards ? 1 : -1); |
| 60 | } |
| 61 | |
| 62 | QString string; |
| 63 | |
| 64 | // text stream to read history into string for pattern or regular expression searching |
| 65 | QTextStream searchStream(&string); |
| 66 | |
| 67 | PlainTextDecoder decoder; |
| 68 | decoder.setRecordLinePositions(true); |
| 69 | |
| 70 | // setup first and last lines depending on search direction |
| 71 | int line = startLine; |
| 72 | |
| 73 | // read through and search history in blocks of 10K lines. |
| 74 | // this balances the need to retrieve lots of data from the history each time |
| 75 | //(for efficient searching) |
| 76 | // without using silly amounts of memory if the history is very large. |
| 77 | const int maxDelta = qMin(window->lineCount(), 10000); |
| 78 | int delta = forwards ? maxDelta : -maxDelta; |
| 79 | |
| 80 | int endLine = line; |
| 81 | bool continueLoop = true; |
| 82 | bool invertDirection = false; |
| 83 | bool hasWrapped = false; // set to true when we reach the top/bottom |
| 84 | // of the output and continue from the other |
| 85 | // end |
| 86 | |
| 87 | QSet<int> matchPositions; |
| 88 | |
| 89 | decoder.begin(&searchStream); |
| 90 | emulation->writeToStream(&decoder, 0, lastLine); |
| 91 | decoder.end(); |
| 92 | const QList<int> linePositions = decoder.linePositions(); |
| 93 | |
| 94 | QRegularExpressionMatchIterator matchIterator = _regExp.globalMatch(string); |
| 95 | while (matchIterator.hasNext()) { |
nothing calls this directly
no test coverage detected