[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kwrite-devel
Subject:    Re: KTextEditor::SearchInterface
From:       Dominik Haumann <dhdev () gmx ! de>
Date:       2011-12-19 21:07:35
Message-ID: 201112192207.36176.dhdev () gmx ! de
[Download RAW message or body]

Hi,

the documentation [1] of searchText() says:

  When searching for regular expressions, the first element holds
  the range of the full match, the subsequent elements hold the
  ranges of the capturing parentheses.

In other words, it always only searches for the first match. The return
value is a QVector, because it may contain capturing sequences.

[1] http://api.kde.org/4.x-api/kdelibs-apidocs/interfaces/ktexteditor/html/classKTextEditor_1_1SearchInterface.html



You simply need to add a while-loop. For instance, I do it like this in
part/plugins/hlselection/hlselectionplugin.cpp:

  KTextEditor::SearchInterface* siface =
    qobject_cast<KTextEditor::SearchInterface*>(m_view->document());

  if (!siface) {
    return;
  }

  KTextEditor::Cursor start(0, 0);
  KTextEditor::Range searchRange;

  QVector<KTextEditor::Range> matches;

  do {
    searchRange.setRange(start, m_view->document()->documentEnd());

    matches = siface->searchText(searchRange, m_currentText, \
KTextEditor::Search::WholeWords);

    if (matches.first().isValid()) {
      // I got a valid match. Do something with it.
      //matches.first() ....
      // ...or simply add the match to a list: myMatches.append(matches.first());

      // now adapt the start of the search range and continue
      start = matches.first().end();
    }
  } while (matches.first().isValid());


This really should work for you.

Dominik
_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic