mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-29 10:02:57 +03:00
Use a sorted IdMap for aliases
This commit is contained in:
parent
bab95491c8
commit
e7a8f64722
@ -9,21 +9,21 @@ void AliasRegistry::add_alias(String alias, String command)
|
|||||||
{
|
{
|
||||||
kak_assert(not alias.empty());
|
kak_assert(not alias.empty());
|
||||||
kak_assert(CommandManager::instance().command_defined(command));
|
kak_assert(CommandManager::instance().command_defined(command));
|
||||||
m_aliases[alias] = std::move(command);
|
m_aliases.append({std::move(alias), std::move(command) }, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AliasRegistry::remove_alias(const String& alias)
|
void AliasRegistry::remove_alias(StringView alias)
|
||||||
{
|
{
|
||||||
auto it = m_aliases.find(alias);
|
auto it = m_aliases.find(alias);
|
||||||
if (it != m_aliases.end())
|
if (it != m_aliases.end())
|
||||||
m_aliases.erase(it);
|
m_aliases.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView AliasRegistry::operator[](const String& alias) const
|
StringView AliasRegistry::operator[](StringView alias) const
|
||||||
{
|
{
|
||||||
auto it = m_aliases.find(alias);
|
auto it = m_aliases.find(alias);
|
||||||
if (it != m_aliases.end())
|
if (it != m_aliases.end())
|
||||||
return it->second;
|
return it->value;
|
||||||
else if (m_parent)
|
else if (m_parent)
|
||||||
return (*m_parent)[alias];
|
return (*m_parent)[alias];
|
||||||
else
|
else
|
||||||
@ -38,8 +38,8 @@ Vector<StringView> AliasRegistry::aliases_for(StringView command) const
|
|||||||
|
|
||||||
for (auto& alias : m_aliases)
|
for (auto& alias : m_aliases)
|
||||||
{
|
{
|
||||||
if (alias.second == command)
|
if (alias.value == command)
|
||||||
res.push_back(alias.first);
|
res.push_back(alias.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "safe_ptr.hh"
|
#include "safe_ptr.hh"
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
#include "unordered_map.hh"
|
#include "id_map.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
@ -13,10 +13,10 @@ class AliasRegistry : public SafeCountable
|
|||||||
public:
|
public:
|
||||||
AliasRegistry(AliasRegistry& parent) : m_parent(&parent) {}
|
AliasRegistry(AliasRegistry& parent) : m_parent(&parent) {}
|
||||||
void add_alias(String alias, String command);
|
void add_alias(String alias, String command);
|
||||||
void remove_alias(const String& alias);
|
void remove_alias(StringView alias);
|
||||||
StringView operator[](const String& name) const;
|
StringView operator[](StringView name) const;
|
||||||
|
|
||||||
using AliasMap = UnorderedMap<String, String, MemoryDomain::Aliases>;
|
using AliasMap = IdMap<String, MemoryDomain::Aliases>;
|
||||||
using iterator = AliasMap::const_iterator;
|
using iterator = AliasMap::const_iterator;
|
||||||
iterator begin() const { return m_aliases.begin(); }
|
iterator begin() const { return m_aliases.begin(); }
|
||||||
iterator end() const { return m_aliases.end(); }
|
iterator end() const { return m_aliases.end(); }
|
||||||
@ -28,7 +28,7 @@ private:
|
|||||||
AliasRegistry() {}
|
AliasRegistry() {}
|
||||||
|
|
||||||
SafePtr<AliasRegistry> m_parent;
|
SafePtr<AliasRegistry> m_parent;
|
||||||
UnorderedMap<String, String, MemoryDomain::Aliases> m_aliases;
|
AliasMap m_aliases;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -572,8 +572,8 @@ Completions CommandManager::complete(const Context& context,
|
|||||||
}
|
}
|
||||||
for (auto& alias : context.aliases())
|
for (auto& alias : context.aliases())
|
||||||
{
|
{
|
||||||
if (prefix_match(alias.first, prefix))
|
if (prefix_match(alias.key, prefix))
|
||||||
result.candidates.push_back(alias.first);
|
result.candidates.push_back(alias.key);
|
||||||
}
|
}
|
||||||
std::sort(result.candidates.begin(), result.candidates.end());
|
std::sort(result.candidates.begin(), result.candidates.end());
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user