From 15e79b09d33c7cac888f93d218ae8be5ae617a2b Mon Sep 17 00:00:00 2001
From: patrick96
Date: Thu, 19 Mar 2020 15:09:38 +0100
Subject: [PATCH] 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
---
src/drawtypes/iconset.cpp | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/src/drawtypes/iconset.cpp b/src/drawtypes/iconset.cpp
index 5bebe013..55426eed 100644
--- a/src/drawtypes/iconset.cpp
+++ b/src/drawtypes/iconset.cpp
@@ -12,26 +12,27 @@ namespace drawtypes {
}
label_t iconset::get(const string& id, const string& fallback_id, bool fuzzy_match) {
- if (fuzzy_match) {
- for (auto const& ent1 : m_icons) {
- if (id.find(ent1.first) != std::string::npos) {
- return ent1.second;
- }
- }
- return m_icons.find(fallback_id)->second;
+ // Try to match exactly first
+ auto icon = m_icons.find(id);
+ if (icon != m_icons.end()) {
+ return icon->second;
}
- // Not fuzzy matching so use old method which requires an exact match on icon id
- auto icon = m_icons.find(id);
- if (icon == m_icons.end()) {
- return m_icons.find(fallback_id)->second;
+ // If fuzzy matching is turned on, try that first before returning the fallback.
+ if (fuzzy_match) {
+ for (auto const& icon : m_icons) {
+ if (id.find(icon.first) != std::string::npos) {
+ return icon.second;
+ }
+ }
}
- return icon->second;
+
+ return m_icons.find(fallback_id)->second;
}
iconset::operator bool() {
return !m_icons.empty();
}
-}
+} // namespace drawtypes
POLYBAR_NS_END