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

Method doSearch

src/TeXDocumentWindow.cpp:2602–2664  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2600}
2601
2602QTextCursor TeXDocumentWindow::doSearch(const QString& searchText, const QRegularExpression * regex, QTextDocument::FindFlags flags, int s, int e)
2603{
2604 QTextCursor curs;
2605 using pos_type = decltype(curs.position());
2606 QTextDocument * theDoc = textEdit->document();
2607 const QString& docText = textEdit->text();
2608
2609 if ((flags & QTextDocument::FindBackward) != 0) {
2610 if (regex) {
2611 // this doesn't seem to match \n or even \x2029 for newline
2612 // curs = theDoc->find(*regex, e, flags);
2613 QRegularExpressionMatch m;
2614#if QT_VERSION >= 0x050500
2615 QString::size_type offset = docText.lastIndexOf(*regex, e, &m);
2616#else
2617 int offset = docText.lastIndexOf(*regex, e);
2618 if (offset >= 0)
2619 m = regex->match(docText, offset);
2620#endif
2621 while (offset >= s && m.capturedEnd() > e) {
2622#if QT_VERSION >= 0x050500
2623 offset = docText.lastIndexOf(*regex, offset - 1, &m);
2624#else
2625 offset = docText.lastIndexOf(*regex, offset - 1);
2626 if (offset >= 0)
2627 m = regex->match(docText, offset);
2628#endif
2629 }
2630 if (offset >= s) {
2631 curs = QTextCursor(textEdit->document());
2632 curs.setPosition(static_cast<pos_type>(m.capturedStart()));
2633 curs.setPosition(static_cast<pos_type>(m.capturedEnd()), QTextCursor::KeepAnchor);
2634 }
2635 }
2636 else {
2637 curs = theDoc->find(searchText, e, flags);
2638 if (!curs.isNull()) {
2639 if (curs.selectionEnd() > e)
2640 curs = theDoc->find(searchText, curs, flags);
2641 if (curs.selectionStart() < s)
2642 curs = QTextCursor();
2643 }
2644 }
2645 }
2646 else {
2647 if (regex) {
2648 // this doesn't seem to match \n or even \x2029 for newline
2649 // curs = theDoc->find(*regex, s, flags);
2650 QRegularExpressionMatch m = regex->match(docText, s);
2651 if (m.hasMatch()) {
2652 curs = QTextCursor(theDoc);
2653 curs.setPosition(static_cast<pos_type>(m.capturedStart()));
2654 curs.setPosition(static_cast<pos_type>(m.capturedEnd()), QTextCursor::KeepAnchor);
2655 }
2656 }
2657 else {
2658 curs = theDoc->find(searchText, s, flags);
2659 }

Callers 1

doFindAgainMethod · 0.80

Calls 5

setPositionMethod · 0.80
isNullMethod · 0.80
selectionStartMethod · 0.80
documentMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected