From 661d1a090572323627ccdb16aeba4e6adf4ca59a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 3 Jul 2023 20:48:59 +1000 Subject: [PATCH] Merge common docstring in key mapping assistant Fixes #4942 --- src/normal.cc | 22 ++++++++++++++-------- 1 file 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; }