MCPcopy Create free account
hub / github.com/TeXworks/texworks / doFindAgain

Method doFindAgain

src/TeXDocumentWindow.cpp:2305–2404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2303}
2304
2305void TeXDocumentWindow::doFindAgain(bool fromDialog)
2306{
2307 Tw::Settings settings;
2308 QString searchText = settings.value(QString::fromLatin1("searchText")).toString();
2309 if (searchText.isEmpty())
2310 return;
2311
2312 QTextDocument::FindFlags flags = static_cast<QTextDocument::FindFlags>(settings.value(QString::fromLatin1("searchFlags")).toInt());
2313
2314 QRegularExpression *regex = nullptr;
2315 if (settings.value(QString::fromLatin1("searchRegex")).toBool()) {
2316 regex = new QRegularExpression(searchText, ((flags & QTextDocument::FindCaseSensitively) != 0) ? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption);
2317 if (!regex->isValid()) {
2318 qApp->beep();
2319 statusBar()->showMessage(tr("Invalid regular expression"), kStatusMessageDuration);
2320 delete regex;
2321 return;
2322 }
2323 }
2324
2325 if (fromDialog && (settings.value(QString::fromLatin1("searchFindAll")).toBool() || settings.value(QString::fromLatin1("searchAllFiles")).toBool())) {
2326 QList<SearchResult> results;
2327 flags &= ~QTextDocument::FindBackward;
2328
2329 QList<TeXDocumentWindow*> docsToSearch{this};
2330 if (settings.value(QString::fromLatin1("searchAllFiles")).toBool()) {
2331 for (TeXDocumentWindow * theDoc : docList) {
2332 if (!docsToSearch.contains(theDoc)) {
2333 docsToSearch.append(theDoc);
2334 }
2335 }
2336 }
2337
2338 for (TeXDocumentWindow * theDoc : docsToSearch) {
2339 QTextCursor curs(theDoc->textDoc());
2340 curs.movePosition(QTextCursor::End);
2341 int rangeStart = 0;
2342 int rangeEnd = curs.position();
2343 while (true) {
2344 curs = theDoc->doSearch(searchText, regex, flags, rangeStart, rangeEnd);
2345 if (curs.isNull())
2346 break;
2347 int blockStart = curs.block().position();
2348 results.append(SearchResult(theDoc, curs.blockNumber() + 1,
2349 curs.selectionStart() - blockStart, curs.selectionEnd() - blockStart));
2350 if ((flags & QTextDocument::FindBackward) != 0)
2351 rangeEnd = curs.selectionStart();
2352 else
2353 rangeStart = curs.selectionEnd();
2354 }
2355 }
2356
2357 if (results.count() == 0) {
2358 qApp->beep();
2359 statusBar()->showMessage(tr("Not found"), kStatusMessageDuration);
2360 }
2361 else {
2362 const bool singleFile = (docsToSearch.size() == 1);

Callers

nothing calls this directly

Calls 11

containsMethod · 0.80
textDocMethod · 0.80
doSearchMethod · 0.80
isNullMethod · 0.80
selectionStartMethod · 0.80
textCursorMethod · 0.80
setTextCursorMethod · 0.80
SearchResultClass · 0.70
valueMethod · 0.45
isValidMethod · 0.45
documentMethod · 0.45

Tested by

no test coverage detected