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

List:       kde-commits
Subject:    KDE/kdelibs/kate/part
From:       Christoph Cullmann <cullmann () kde ! org>
Date:       2007-04-30 21:40:02
Message-ID: 1177969202.779206.24079.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 659835 by cullmann:

add patch, to compile

 M  +89 -0     katedocument.cpp  
 M  +34 -0     katedocument.h  
 M  +4 -2      katesearchbar.cpp  


--- trunk/KDE/kdelibs/kate/part/katedocument.cpp #659834:659835
@@ -2152,8 +2152,97 @@
   return KTextEditor::Range::invalid();
 }
 
+QVector<KTextEditor::Range> KateDocument::searchText(
+    const KTextEditor::Range & range,
+    const QString & pattern,
+    const KTextEditor::Search::SearchOptions options)
+{
+  // TODO
+  // * support BlockInputRange
+  // * support DotMatchesNewline
+  // * return captchure ranges (not only full match)
 
+  KTextEditor::Search::SearchOptions finalOptions(options);
+  const bool escapeSequences = \
finalOptions.testFlag(KTextEditor::Search::EscapeSequences);  
+  // abuse regex for whole word plaintext search
+  if (finalOptions.testFlag(KTextEditor::Search::WholeWords))
+  {
+    // resolve escape sequences like \t
+    QString expression(pattern);
+    if (escapeSequences)
+    {
+      KateDocument::escapePlaintext(expression);
+    }
+
+    // escape dot and friends
+    expression = "\\b" + QRegExp::escape(expression) + "\\b";
+
+    // regex ON, whole words OFF
+    finalOptions |= KTextEditor::Search::Regex;
+    finalOptions &= \
~KTextEditor::Search::SearchOptions(KTextEditor::Search::WholeWords); +  }
+
+  const bool regexMode = finalOptions.testFlag(KTextEditor::Search::Regex);
+  const bool caseSensitive = \
!finalOptions.testFlag(KTextEditor::Search::CaseInsensitive); +  const bool backwards \
= finalOptions.testFlag(KTextEditor::Search::Backwards); +
+  const KTextEditor::Cursor & start = range.start();
+  KTextEditor::Range resultRange;
+  if (regexMode)
+  {
+    // regex search
+    const Qt::CaseSensitivity caseSensitivity =
+        caseSensitive
+        ? Qt::CaseSensitive
+        : Qt::CaseInsensitive;
+
+    QRegExp matcher(pattern, caseSensitivity);
+    if (matcher.isValid())
+    {
+      // valid pattern
+      // run engine
+      resultRange = searchText(start, matcher, backwards);
+    }
+    else
+    {
+      // invalid pattern
+      resultRange = KTextEditor::Range::invalid();
+    }
+  }
+  else
+  {
+    // plaintext search
+
+    // resolve escape sequences like \t
+    QString finalPattern(pattern);
+    if (escapeSequences)
+    {
+      KateDocument::escapePlaintext(finalPattern);
+    }
+
+    // run engine
+    resultRange = searchText(start, finalPattern, caseSensitive, backwards);
+  }
+
+  QVector<KTextEditor::Range> result;
+  result.append(resultRange);
+  return result;
+}
+
+KTextEditor::Search::SearchOptions KateDocument::supportedSearchOptions() const
+{
+  KTextEditor::Search::SearchOptions supported(KTextEditor::Search::Default);
+  supported |= KTextEditor::Search::Regex;
+  supported |= KTextEditor::Search::CaseInsensitive;
+  supported |= KTextEditor::Search::Backwards;
+// supported |= KTextEditor::Search::BlockInputRange;
+  supported |= KTextEditor::Search::EscapeSequences;
+  supported |= KTextEditor::Search::WholeWords;
+// supported |= KTextEditor::Search::DotMatchesNewline;
+  return supported;
+}
+
 void KateDocument::escapePlaintext(QString & text) {
   // get input
   const int inputLen = text.length();
--- trunk/KDE/kdelibs/kate/part/katedocument.h #659834:659835
@@ -376,11 +376,45 @@
   // KTextEditor::SearchInterface stuff
   //
   public Q_SLOTS:
+    /**
+     * Search for the given \p text beginning from \p startPosition taking
+     * into account whether to search \p casesensitive and \p backwards.
+     *
+     * \param startPosition start cursor position
+     * \param text text to search for
+     * \param casesensitive if \e true, the search is performed case
+     *        sensitive, otherwise case insensitive
+     * \param backwards if \e true, the search will be backwards
+     * \return The valid range of the matched text if \p text was found. If
+     *        the \p text was not found, the returned range is not valid
+     *        (see Range::isValid()).
+     * \see KTextEditor::Range
+     */
     KTextEditor::Range searchText (const KTextEditor::Cursor& startPosition,
         const QString &text, bool casesensitive = true, bool backwards = false);
+
+    /**
+     * Search for the regular expression \p regexp beginning from
+     * \p startPosition, if \p backwards is \e true, the search direction will
+     * be reversed.
+     *
+     * \param startPosition start cursor position
+     * \param regexp text to search for
+     * \param backwards if \e true, the search will be backwards
+     * \return The valid range of the matched \p regexp. If the search was not
+     *        successful, the returned range is not valid
+     *        (see Range::isValid()).
+     * \see KTextEditor::Range, QRegExp
+     */
     KTextEditor::Range searchText (const KTextEditor::Cursor& startPosition,
         const QRegExp &regexp, bool backwards = false);
 
+    QVector<KTextEditor::Range> searchText(
+        const KTextEditor::Range & range,
+        const QString & pattern,
+        const KTextEditor::Search::SearchOptions options);
+    KTextEditor::Search::SearchOptions supportedSearchOptions() const;
+
   public:
     static void escapePlaintext(QString & text);
     static int repairPattern(QString & pattern, bool & stillMultiLine);
--- trunk/KDE/kdelibs/kate/part/katesearchbar.cpp #659834:659835
@@ -153,6 +153,7 @@
 
 void KateSearchBar::doSearch(const QString &_expression, bool init, bool backwards)
 {
+#if 0
     QString expression = _expression;
 
     bool selected = d->selectionOnlyBox->checkState();
@@ -230,7 +231,7 @@
         wrapped = true;
     }
 
-    if ( foundMatch && selected )
+    if ( foundMatch && selectionOnly )
         foundMatch = m_view->selectionRange().contains( d->match );
 
     if (foundMatch)
@@ -239,7 +240,7 @@
         m_view->setSelection(d->match);
         d->lastMatch = d->match;
         // it makes no sense to have this enabled after a match
-        if ( selected )
+        if ( selectionOnly )
             d->selectionOnlyBox->setCheckState( Qt::Unchecked );
 
         // highlight all matches
@@ -279,6 +280,7 @@
 
 
     d->expressionEdit->setStatus(foundMatch ? (wrapped ? \
KateSearchBarEdit::SearchWrapped : KateSearchBarEdit::Normal) : \
KateSearchBarEdit::NotFound); +#endif
 }
 
 void KateSearchBar::slotSpecialOptionTogled()


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

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