MCPcopy Create free account
hub / github.com/KDE/konsole / executeOnScreenWindow

Method executeOnScreenWindow

src/SearchHistoryTask.cpp:38–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38void 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()) {

Callers

nothing calls this directly

Calls 14

emulationMethod · 0.80
isEmptyMethod · 0.80
linePositionsMethod · 0.80
hasNextMethod · 0.80
countMethod · 0.80
getSelectModeMethod · 0.80
notifyOutputChangedMethod · 0.80
lineCountMethod · 0.45
beginMethod · 0.45
writeToStreamMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected