home/src/keymap_manager.cc

53 lines
1.2 KiB
C++
Raw Normal View History

2013-10-25 01:01:17 +02:00
#include "keymap_manager.hh"
2015-01-06 14:40:56 +01:00
#include "array_view.hh"
#include "assert.hh"
2013-10-25 01:01:17 +02:00
#include <algorithm>
2013-10-25 01:01:17 +02:00
namespace Kakoune
{
void KeymapManager::map_key(Key key, KeymapMode mode,
KeyList mapping, String docstring)
2013-10-25 01:01:17 +02:00
{
m_mapping[KeyAndMode{key, mode}] = {std::move(mapping), std::move(docstring)};
2013-10-25 01:01:17 +02:00
}
void KeymapManager::unmap_key(Key key, KeymapMode mode)
{
m_mapping.remove(KeyAndMode{key, mode});
2013-10-25 01:01:17 +02:00
}
bool KeymapManager::is_mapped(Key key, KeymapMode mode) const
{
return m_mapping.find(KeyAndMode{key, mode}) != m_mapping.end() or
2013-10-25 01:01:17 +02:00
(m_parent and m_parent->is_mapped(key, mode));
}
2017-11-24 10:25:36 +01:00
const KeymapManager::KeymapInfo&
KeymapManager::get_mapping(Key key, KeymapMode mode) const
2013-10-25 01:01:17 +02:00
{
auto it = m_mapping.find(KeyAndMode{key, mode});
2013-10-25 01:01:17 +02:00
if (it != m_mapping.end())
return it->value;
2013-10-25 01:01:17 +02:00
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.key.second == mode and not contains(res, map.key.first))
res.emplace_back(map.key.first);
}
return res;
}
2013-10-25 01:01:17 +02:00
}