Skip to content

Commit

Permalink
fuzzy suggetion in auto complete
Browse files Browse the repository at this point in the history
update screencast
  • Loading branch information
ychclone committed Oct 18, 2021
1 parent 640ec73 commit ef36b20
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 9 deletions.
33 changes: 30 additions & 3 deletions Display/CMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ bTagBuildInProgress_(false)
bool bSymbolSearchCaseSensitive;
bool bSymbolSearchRegularExpression;
bool bLiveSearch;
bool bFuzzyAutoComplete;

bProjectAndGroupFilterCaseSensitive = confManager_->getAppSettingValue("ProjectAndGroupFilterCaseSensitive", false).toBool();
if (bProjectAndGroupFilterCaseSensitive) {
Expand Down Expand Up @@ -306,6 +307,14 @@ bTagBuildInProgress_(false)
actionLiveSearch->setChecked(false);
}

// fuzzy auto complete
bFuzzyAutoComplete = confManager_->getAppSettingValue("FuzzyAutoComplete", true).toBool();
if (bFuzzyAutoComplete) {
actionFuzzyAutoComplete->setChecked(true);
} else {
actionFuzzyAutoComplete->setChecked(false);
}

createActions();
}

Expand Down Expand Up @@ -1189,10 +1198,17 @@ void CMainWindow::on_actionAlways_on_top_toggled()
on_actionTransparent_toggled(); // still transparency
}

void CMainWindow::on_actionLiveSearch_toggled()
void CMainWindow::on_actionFuzzyAutoComplete_toggled()
{
qDebug() << "on_actionLiveSearch_toggled IN";
if (actionFuzzyAutoComplete->isChecked()) {
confManager_->setAppSettingValue("FuzzyAutoComplete", true);
} else {
confManager_->setAppSettingValue("FuzzyAutoComplete", false);
}
}

void CMainWindow::on_actionLiveSearch_toggled()
{
if (actionLiveSearch->isChecked()) {
confManager_->setAppSettingValue("LiveSearch", true);
} else {
Expand Down Expand Up @@ -1564,7 +1580,14 @@ void CMainWindow::searchLineEditChanged()

QStringList tagList;
QMap<int, QString> tagMap;
tagger_.getMatchedTags(search_lineEdit->text(), tagMap, caseSensitivity);

bool bFuzzyAutoComplete = confManager_->getAppSettingValue("FuzzyAutoComplete", true).toBool();

if (bFuzzyAutoComplete) {
tagger_.getFuzzyMatchedTags(search_lineEdit->text(), tagMap, caseSensitivity);
} else {
tagger_.getMatchedTags(search_lineEdit->text(), tagMap, caseSensitivity);
}

for (auto tag: tagMap) {
tagList.push_back(tag);
Expand All @@ -1577,6 +1600,10 @@ void CMainWindow::searchLineEditChanged()
completer_.setCaseSensitivity(caseSensitivity);
completer_.setFilterMode(Qt::MatchContains);

if (bFuzzyAutoComplete) {
completer_.setCompletionMode(QCompleter::UnfilteredPopupCompletion);
}

search_lineEdit->setCompleter(&completer_);

bool bLiveSearch = confManager_->getAppSettingValue("LiveSearch", true).toBool();
Expand Down
1 change: 1 addition & 0 deletions Display/CMainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ private slots:
void on_nextSymbolButton_clicked();
void on_previousSymbolButton_clicked();

void on_actionFuzzyAutoComplete_toggled();
void on_actionLiveSearch_toggled();

void frameSymbolLineEditChanged();
Expand Down
57 changes: 57 additions & 0 deletions Model/qTagger/qTagger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,63 @@ int QTagger::levenshteinDistance(const QString &source, const QString &target)
return previousColumn.at(targetCount);
}

bool QTagger::fuzzyMatch(const QString& targetInput, const QString& patternInput, const Qt::CaseSensitivity& caseSensitivity)
{
int i = 0;
int patternPos = 0;
int matchedChar = 0;
QString target, pattern;

if (caseSensitivity == Qt::CaseInsensitive) {
target = targetInput.toLower();
pattern = patternInput.toLower();
} else {
target = targetInput;
pattern = patternInput;
}

for (i = 0; i < target.length(); i++) {
if (pattern.at(patternPos) == target.at(i)) {
patternPos++;
matchedChar++;
} else {
continue;
}
if (matchedChar == pattern.length()) { // all char in pattern match
break;
}
if (patternPos >= pattern.length()) { // no match for all chars in pattern
break;
}
if (i + pattern.length() - patternPos > target.length()) { // not match yet pattern reach end of string
break;
}
}

if (matchedChar == pattern.length()) {
return true;
} else {
return false;
}
}

int QTagger::getFuzzyMatchedTags(const QString& tagToQuery, QMap<int, QString>& matchedTokenList, const Qt::CaseSensitivity& caseSensitivity)
{
QStringList result;
foreach (const CTagItem &tagItem, tagList_) {
if (fuzzyMatch(tagItem.tag_, tagToQuery, caseSensitivity)) {
int distance = levenshteinDistance(tagToQuery, tagItem.tag_);
matchedTokenList[distance] = tagItem.tag_;
}

if (matchedTokenList.size() > 500) {
break;
}
}

return 0;
}

int QTagger::getMatchedTags(const QString& tagToQuery, QMap<int, QString>& matchedTokenList, const Qt::CaseSensitivity& caseSensitivity)
{
QStringList result;
Expand Down
6 changes: 5 additions & 1 deletion Model/qTagger/qTagger.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "CTagItem.h"

typedef QMap<QString, QString> T_TokenMapType;
typedef QHash<QString, QString> T_TokenMapType;

class QTagger
{
Expand All @@ -38,6 +38,10 @@ class QTagger
int loadTagList(const QString& tagDbFileName);

int levenshteinDistance(const QString &source, const QString &target);

bool fuzzyMatch(const QString& targetInput, const QString& patternInput, const Qt::CaseSensitivity& caseSensitivity);
int getFuzzyMatchedTags(const QString& tagToQuery, QMap<int, QString>& matchedTokenList, const Qt::CaseSensitivity& caseSensitivity);

int getMatchedTags(const QString& tagToQuery, QMap<int, QString>& matchedTokenList, const Qt::CaseSensitivity& caseSensitivity);

int queryTagLoadedSymbol(const T_FileItemList& inputFileItemList, const QString& tagToQuery,
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
![Blink logo](https://raw.githubusercontent.com/ychclone/blink/master/Resources/Images/graphics3.png)

# Blink code search
GUI of live indexed grep for source code, files locator, search and replace.
Switch different projects and start searching.
GUI of live indexed grep for source code. Fuzzy suggestion in autocomplete.
Files locator, search and replace. Switch different projects and start searching.
Drag and drop of filenames to your favourite editor.

[![Build status](https://ci.appveyor.com/api/projects/status/afn8q3ai3e7wphrf?svg=true)](https://ci.appveyor.com/project/ychclone/blink)
Expand All @@ -12,8 +12,8 @@ Drag and drop of filenames to your favourite editor.

# Features
* Search without delay using prebuilt index, comparing to ack or ripgrep
* Fuzzy suggestion in autocomplete
* Live grep
* Queries support autocomplete
* Drag and drop for filename to your favourite editor
* Switch between multiple projects
* Very small index size compared to trigram
Expand Down
2 changes: 1 addition & 1 deletion Resources/Forms/aboutDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Blink v1.7.2</string>
<string>Blink v1.7.3</string>
</property>
</widget>
</item>
Expand Down
11 changes: 10 additions & 1 deletion Resources/Forms/mainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e6f0fc, st
<addaction name="actionSymbolCaseSensitive"/>
<addaction name="actionSymbolRegularExpression"/>
<addaction name="actionLiveSearch"/>
<addaction name="actionFuzzyAutoComplete"/>
</widget>
<widget class="QMenu" name="menuProject">
<property name="title">
Expand Down Expand Up @@ -1098,7 +1099,7 @@ background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e6f0fc, st
<normaloff>:/Icons/22x22/zoom-3.png</normaloff>:/Icons/22x22/zoom-3.png</iconset>
</property>
<property name="text">
<string>&amp;Replace in files</string>
<string>&amp;Replace in Files</string>
</property>
</action>
<action name="actionSymbolRegularExpression">
Expand Down Expand Up @@ -1138,6 +1139,14 @@ background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e6f0fc, st
<string>Live search</string>
</property>
</action>
<action name="actionFuzzyAutoComplete">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Fuzzy Auto Complete</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down
Binary file modified Screencast/Usage.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ef36b20

Please sign in to comment.