fix(iconset): Try exact match before fuzzy match
If an exact match was possible, fuzzy matching could still return a non-exact match if it appeared before the exact match in the list of icons. Fixes #2041
This commit is contained in:
parent
3f7eb1b2aa
commit
15e79b09d3
@ -12,26 +12,27 @@ namespace drawtypes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
label_t iconset::get(const string& id, const string& fallback_id, bool fuzzy_match) {
|
label_t iconset::get(const string& id, const string& fallback_id, bool fuzzy_match) {
|
||||||
if (fuzzy_match) {
|
// Try to match exactly first
|
||||||
for (auto const& ent1 : m_icons) {
|
auto icon = m_icons.find(id);
|
||||||
if (id.find(ent1.first) != std::string::npos) {
|
if (icon != m_icons.end()) {
|
||||||
return ent1.second;
|
return icon->second;
|
||||||
}
|
|
||||||
}
|
|
||||||
return m_icons.find(fallback_id)->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not fuzzy matching so use old method which requires an exact match on icon id
|
// If fuzzy matching is turned on, try that first before returning the fallback.
|
||||||
auto icon = m_icons.find(id);
|
if (fuzzy_match) {
|
||||||
if (icon == m_icons.end()) {
|
for (auto const& icon : m_icons) {
|
||||||
return m_icons.find(fallback_id)->second;
|
if (id.find(icon.first) != std::string::npos) {
|
||||||
|
return icon.second;
|
||||||
}
|
}
|
||||||
return icon->second;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_icons.find(fallback_id)->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
iconset::operator bool() {
|
iconset::operator bool() {
|
||||||
return !m_icons.empty();
|
return !m_icons.empty();
|
||||||
}
|
}
|
||||||
}
|
} // namespace drawtypes
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
Loading…
Reference in New Issue
Block a user