Browse Source

TagExplorer: use RegularExpression instead of WholeWordOnly when searching for a tag

"\bc#\b" won't match a word. We use "^c#$" instead.
Le Tan 7 years ago
parent
commit
47503fddfe
1 changed files with 6 additions and 3 deletions
  1. 6 3
      src/vtagexplorer.cpp

+ 6 - 3
src/vtagexplorer.cpp

@@ -223,13 +223,16 @@ bool VTagExplorer::activateTag(const QString &p_tag)
     QVector<VNotebook *> notebooks;
     notebooks.append(m_notebook);
     getVSearch()->clear();
+    // We could not use WholeWordOnly here, since "c#" won't match a word.
+    int opts = VSearchConfig::CaseSensitive | VSearchConfig::RegularExpression;
+    QString pattern = QRegExp::escape(p_tag);
+    pattern = "^" + pattern + "$";
     QSharedPointer<VSearchConfig> config(new VSearchConfig(VSearchConfig::CurrentNotebook,
                                                            VSearchConfig::Tag,
                                                            VSearchConfig::Note,
                                                            VSearchConfig::Internal,
-                                                           VSearchConfig::CaseSensitive
-                                                           | VSearchConfig::WholeWordOnly,
-                                                           p_tag,
+                                                           opts,
+                                                           pattern,
                                                            QString()));
     getVSearch()->setConfig(config);
     QSharedPointer<VSearchResult> result = getVSearch()->search(notebooks);