diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-03-03 16:51:29 +0000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-03-03 20:16:36 +0000 |
| commit | e3cfde6d07cc8b52b46745609c18b3dc79883511 (patch) | |
| tree | 8d0cb753c8b2ad3ed36cc9141b0f5746accea153 /src/keymap_manager.cc | |
| parent | 7d487e3b4cd32d0f9d031f258bf080ac43efdc68 (diff) | |
Add docstring support for mappings, and use them in autoinfo
Fixes #105
Fixes #1100
Closes #1165
Diffstat (limited to 'src/keymap_manager.cc')
| -rw-r--r-- | src/keymap_manager.cc | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/keymap_manager.cc b/src/keymap_manager.cc index 42308538..ba6d16ed 100644 --- a/src/keymap_manager.cc +++ b/src/keymap_manager.cc @@ -3,12 +3,15 @@ #include "array_view.hh" #include "assert.hh" +#include <algorithm> + namespace Kakoune { -void KeymapManager::map_key(Key key, KeymapMode mode, KeyList mapping) +void KeymapManager::map_key(Key key, KeymapMode mode, + KeyList mapping, String docstring) { - m_mapping[{key, mode}] = std::move(mapping); + m_mapping[{key, mode}] = {std::move(mapping), std::move(docstring)}; } void KeymapManager::unmap_key(Key key, KeymapMode mode) @@ -23,13 +26,29 @@ bool KeymapManager::is_mapped(Key key, KeymapMode mode) const (m_parent and m_parent->is_mapped(key, mode)); } -ConstArrayView<Key> KeymapManager::get_mapping(Key key, KeymapMode mode) const +const KeymapManager::KeyMapInfo& +KeymapManager::get_mapping(Key key, KeymapMode mode) const { auto it = m_mapping.find({key, mode}); if (it != m_mapping.end()) - return { it->second }; + return it->second; kak_assert(m_parent); return m_parent->get_mapping(key, mode); } +KeymapManager::KeyList KeymapManager::get_mapped_keys(KeymapMode mode) const +{ + KeyList res; + if (m_parent) + res = m_parent->get_mapped_keys(mode); + for (auto& map : m_mapping) + { + if (map.first.second == mode) + res.emplace_back(map.first.first); + } + std::sort(res.begin(), res.end()); + res.erase(std::unique(res.begin(), res.end()), res.end()); + return res; +} + } |
