Fix alias completion and overwritting
This commit is contained in:
parent
c6e1d9b3dd
commit
cb108b248a
|
@ -1,6 +1,7 @@
|
||||||
#include "alias_registry.hh"
|
#include "alias_registry.hh"
|
||||||
|
|
||||||
#include "command_manager.hh"
|
#include "command_manager.hh"
|
||||||
|
#include "containers.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
@ -9,7 +10,11 @@ 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.append({std::move(alias), std::move(command) });
|
auto it = m_aliases.find(alias);
|
||||||
|
if (it == m_aliases.end())
|
||||||
|
m_aliases.append({std::move(alias), std::move(command) });
|
||||||
|
else
|
||||||
|
it->value = std::move(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AliasRegistry::remove_alias(StringView alias)
|
void AliasRegistry::remove_alias(StringView alias)
|
||||||
|
@ -45,4 +50,17 @@ Vector<StringView> AliasRegistry::aliases_for(StringView command) const
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector<std::pair<StringView, StringView>> AliasRegistry::flatten_aliases() const
|
||||||
|
{
|
||||||
|
Vector<std::pair<StringView, StringView>> res;
|
||||||
|
if (m_parent)
|
||||||
|
res = m_parent->flatten_aliases();
|
||||||
|
for (auto& alias : m_aliases)
|
||||||
|
{
|
||||||
|
if (not contains(transformed(res, [](const std::pair<StringView, StringView>& val) { return val.first; }), alias.key))
|
||||||
|
res.emplace_back(alias.key, alias.value);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,9 @@ public:
|
||||||
|
|
||||||
using AliasMap = IdMap<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 end() const { return m_aliases.end(); }
|
|
||||||
|
|
||||||
Vector<StringView> aliases_for(StringView command) const;
|
Vector<StringView> aliases_for(StringView command) const;
|
||||||
|
Vector<std::pair<StringView, StringView>> flatten_aliases() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class Scope;
|
friend class Scope;
|
||||||
|
|
|
@ -571,10 +571,10 @@ Completions CommandManager::complete(const Context& context,
|
||||||
if (prefix_match(command.first, prefix))
|
if (prefix_match(command.first, prefix))
|
||||||
result.candidates.push_back(command.first);
|
result.candidates.push_back(command.first);
|
||||||
}
|
}
|
||||||
for (auto& alias : context.aliases())
|
for (auto& alias : context.aliases().flatten_aliases())
|
||||||
{
|
{
|
||||||
if (prefix_match(alias.key, prefix))
|
if (prefix_match(alias.first, prefix))
|
||||||
result.candidates.push_back(alias.key);
|
result.candidates.push_back(alias.first.str());
|
||||||
}
|
}
|
||||||
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