mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
WIP Fuzzy search rework.
1) fts_fuzzy_match has been extended to support wchar_t for a char type and uint16_t for an index type for the match indices. 2) fts_fuzzy_match has been extended to place a proper stopper character into the match buffer. 3) Slicer integration now uses the fuzzy match indices for highlighting. 4) Slicer integration now correctly highlights the matched word. 5) Slicer search dialog now sorts based on match AND category. Further modifications are planned: 1) Matching in local language vs. English: Just show the English variant if matched in English. Don't mix the two together. 2) Matching the group or category: Continue matching the label. 3) For matches with equal match quality and category sort alphanumerically.
This commit is contained in:
parent
f479b77e01
commit
07ab5c31e6
4 changed files with 160 additions and 159 deletions
|
@ -37,6 +37,7 @@ struct GroupAndCategory {
|
|||
};
|
||||
|
||||
// fuzzy_match flag
|
||||
// Sorted by the order of importance. The outputs will be sorted by the importance if the match value given by fuzzy_match is equal.
|
||||
enum FMFlag
|
||||
{
|
||||
fmUndef = 0, // didn't find
|
||||
|
@ -53,28 +54,27 @@ struct Option {
|
|||
bool operator<(const Option& other) const { return other.label > this->label; }
|
||||
bool operator>(const Option& other) const { return other.label < this->label; }
|
||||
|
||||
std::string opt_key;
|
||||
// Fuzzy matching works at a character level. Thus matching with wide characters is a safer bet than with short characters,
|
||||
// though for some languages (Chinese?) it may not work correctly.
|
||||
std::wstring opt_key;
|
||||
Preset::Type type {Preset::TYPE_INVALID};
|
||||
wxString label;
|
||||
wxString label_local;
|
||||
wxString group;
|
||||
wxString group_local;
|
||||
wxString category;
|
||||
wxString category_local;
|
||||
std::wstring label;
|
||||
std::wstring label_local;
|
||||
std::wstring group;
|
||||
std::wstring group_local;
|
||||
std::wstring category;
|
||||
std::wstring category_local;
|
||||
|
||||
FMFlag fuzzy_match_simple(char const *search_pattern) const;
|
||||
FMFlag fuzzy_match_simple(const wxString& search) const;
|
||||
FMFlag fuzzy_match_simple(const std::string &search) const;
|
||||
FMFlag fuzzy_match(char const *search_pattern, int &outScore) const;
|
||||
FMFlag fuzzy_match(const wxString &search, int &outScore) const ;
|
||||
FMFlag fuzzy_match(const std::string &search, int &outScore) const ;
|
||||
FMFlag fuzzy_match(wchar_t const *search_pattern, int &outScore, std::vector<uint16_t> &out_matches) const;
|
||||
};
|
||||
|
||||
struct FoundOption {
|
||||
// UTF8 encoding, to be consumed by ImGUI by reference.
|
||||
std::string label;
|
||||
std::string marked_label;
|
||||
std::string tooltip;
|
||||
size_t option_idx {0};
|
||||
FMFlag category {fmUndef};
|
||||
int outScore {0};
|
||||
|
||||
// Returning pointers to contents of std::string members, to be used by ImGUI for rendering.
|
||||
|
@ -106,7 +106,7 @@ class OptionsSearcher
|
|||
}
|
||||
void sort_found() {
|
||||
std::sort(found.begin(), found.end(), [](const FoundOption& f1, const FoundOption& f2) {
|
||||
return f1.outScore > f2.outScore; });
|
||||
return f1.outScore > f2.outScore || (f1.outScore == f2.outScore && int(f1.category) < int(f2.category)); });
|
||||
};
|
||||
|
||||
size_t options_size() const { return options.size(); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue