fix(config): Use proper token object

When using the same token multiple times in the same label with
different length properties, polybar would always use the settings for
the first token. This now replaces the tokens one by one, so that a new
token object is used for the length settings each time a token is used
again. Because the token objects are added in order, the replacement
always uses the right token object for the token that is replaced.

Fixes #971
This commit is contained in:
patrick96 2018-01-23 16:42:53 +01:00 committed by NBonaparte
parent 5ca1940629
commit 5c7ff09ed6

View File

@ -47,14 +47,18 @@ namespace drawtypes {
} }
for (auto&& tok : m_tokens) { for (auto&& tok : m_tokens) {
string repl{replacement};
if (token == tok.token) { if (token == tok.token) {
if (tok.max != 0_z && string_util::char_len(replacement) > tok.max) { if (tok.max != 0_z && string_util::char_len(repl) > tok.max) {
replacement = string_util::utf8_truncate(std::move(replacement), tok.max) + tok.suffix; repl = string_util::utf8_truncate(std::move(repl), tok.max) + tok.suffix;
} else if (tok.min != 0_z && replacement.length() < tok.min) { } else if (tok.min != 0_z && repl.length() < tok.min) {
replacement.insert(0_z, tok.min - replacement.length(), ' '); repl.insert(0_z, tok.min - repl.length(), ' ');
} }
m_tokenized = string_util::replace_all(m_tokenized, token, move(replacement));
m_tokenized = string_util::replace_all(m_tokenized, token, move(replacement)); /*
* Only replace first occurence, so that the proper token objects can be used
*/
m_tokenized = string_util::replace(m_tokenized, token, move(repl));
} }
} }
} }