summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2023-07-03 20:48:59 +1000
committerMaxime Coste <mawww@kakoune.org>2023-07-03 20:48:59 +1000
commit661d1a090572323627ccdb16aeba4e6adf4ca59a (patch)
tree595776a517da49d2cab5a7057fa9abba7061384c
parent4b605c582caddf4066d5e5f0421026b7d7060e20 (diff)
Merge common docstring in key mapping assistant
Fixes #4942
-rw-r--r--src/normal.cc22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/normal.cc b/src/normal.cc
index 08ce028d..64b67e63 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -190,23 +190,29 @@ String build_autoinfo_for_mapping(const Context& context, KeymapMode mode,
}
for (auto& key : keymaps.get_mapped_keys(mode))
- descs.emplace_back(to_string(key),
- keymaps.get_mapping_docstring(key, mode));
+ {
+ const String& docstring = keymaps.get_mapping_docstring(key, mode);
+ if (auto it = find_if(descs, [&](auto& elem) { return elem.second == docstring; });
+ it != descs.end())
+ it->first += ',' + to_string(key);
+ else
+ descs.emplace_back(to_string(key), docstring);
+ }
auto max_len = 0_col;
- for (auto& desc : descs)
+ for (auto& [keys, docstring] : descs)
{
- auto len = desc.first.column_length();
+ auto len = keys.column_length();
if (len > max_len)
max_len = len;
}
String res;
- for (auto& desc : descs)
+ for (auto& [keys, docstring] : descs)
res += format("{}:{}{}\n",
- desc.first,
- String{' ', max_len - desc.first.column_length() + 1},
- desc.second);
+ keys,
+ String{' ', max_len - keys.column_length() + 1},
+ docstring);
return res;
}