Use main selection index as default when accessing only one register value
Fixes #117
This commit is contained in:
parent
e202b7af50
commit
7235180614
|
@ -316,7 +316,7 @@ String eval_token(const Token& token, Context& context,
|
||||||
return ShellManager::instance().eval(content, context, shell_params,
|
return ShellManager::instance().eval(content, context, shell_params,
|
||||||
env_vars);
|
env_vars);
|
||||||
case Token::Type::RegisterExpand:
|
case Token::Type::RegisterExpand:
|
||||||
return RegisterManager::instance()[content].values(context)[0];
|
return context.main_sel_register_value(content);
|
||||||
case Token::Type::OptionExpand:
|
case Token::Type::OptionExpand:
|
||||||
return context.options()[content].get_as_string();
|
return context.options()[content].get_as_string();
|
||||||
case Token::Type::ValExpand:
|
case Token::Type::ValExpand:
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "client.hh"
|
#include "client.hh"
|
||||||
#include "user_interface.hh"
|
#include "user_interface.hh"
|
||||||
|
#include "register_manager.hh"
|
||||||
#include "window.hh"
|
#include "window.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
|
@ -226,4 +227,13 @@ void Context::end_edition()
|
||||||
--m_edition_level;
|
--m_edition_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringView Context::main_sel_register_value(StringView reg) const
|
||||||
|
{
|
||||||
|
auto strings = RegisterManager::instance()[reg].values(*this);
|
||||||
|
size_t index = m_selections ? (*m_selections).main_index() : 0;
|
||||||
|
if (strings.size() < index)
|
||||||
|
index = strings.size() - 1;
|
||||||
|
return strings[index];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,8 @@ public:
|
||||||
|
|
||||||
void print_status(DisplayLine status) const;
|
void print_status(DisplayLine status) const;
|
||||||
|
|
||||||
|
StringView main_sel_register_value(StringView reg) const;
|
||||||
|
|
||||||
void push_jump();
|
void push_jump();
|
||||||
const SelectionList& jump_forward();
|
const SelectionList& jump_forward();
|
||||||
const SelectionList& jump_backward();
|
const SelectionList& jump_backward();
|
||||||
|
|
|
@ -358,10 +358,10 @@ HighlighterAndId highlight_search_factory(HighlighterParameters params)
|
||||||
return ColorSpec{ { 0, &Kakoune::get_color("Search") } };
|
return ColorSpec{ { 0, &Kakoune::get_color("Search") } };
|
||||||
};
|
};
|
||||||
auto get_regex = [](const Context&){
|
auto get_regex = [](const Context&){
|
||||||
auto s = RegisterManager::instance()['/'].values(Context{});
|
auto s = Context().main_sel_register_value("/");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return s.empty() ? Regex{} : Regex{s[0].begin(), s[0].end()};
|
return s.empty() ? Regex{} : Regex{s.begin(), s.end()};
|
||||||
}
|
}
|
||||||
catch (boost::regex_error& err)
|
catch (boost::regex_error& err)
|
||||||
{
|
{
|
||||||
|
|
|
@ -374,7 +374,7 @@ public:
|
||||||
|
|
||||||
if (m_mode == Mode::InsertReg)
|
if (m_mode == Mode::InsertReg)
|
||||||
{
|
{
|
||||||
String reg = RegisterManager::instance()[key.key].values(context())[0];
|
StringView reg = context().main_sel_register_value(String{key.key});
|
||||||
m_line_editor.insert(reg);
|
m_line_editor.insert(reg);
|
||||||
m_mode = Mode::Default;
|
m_mode = Mode::Default;
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ void register_env_vars()
|
||||||
}, {
|
}, {
|
||||||
"reg_.+",
|
"reg_.+",
|
||||||
[](StringView name, const Context& context) -> String
|
[](StringView name, const Context& context) -> String
|
||||||
{ return RegisterManager::instance()[name.substr(4_byte)].values(context)[0]; }
|
{ return context.main_sel_register_value(name.substr(4_byte)); }
|
||||||
}, {
|
}, {
|
||||||
"client_env_.+",
|
"client_env_.+",
|
||||||
[](StringView name, const Context& context) -> String
|
[](StringView name, const Context& context) -> String
|
||||||
|
|
|
@ -384,9 +384,9 @@ void pipe(Context& context, int)
|
||||||
if (event != PromptEvent::Validate)
|
if (event != PromptEvent::Validate)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String real_cmd;
|
StringView real_cmd;
|
||||||
if (cmdline.empty())
|
if (cmdline.empty())
|
||||||
real_cmd = RegisterManager::instance()['|'].values(context)[0];
|
real_cmd = context.main_sel_register_value("|");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RegisterManager::instance()['|'] = cmdline;
|
RegisterManager::instance()['|'] = cmdline;
|
||||||
|
@ -575,7 +575,7 @@ void search(Context& context, int)
|
||||||
regex_prompt(context, direction == Forward ? "search:" : "reverse search:",
|
regex_prompt(context, direction == Forward ? "search:" : "reverse search:",
|
||||||
[](Regex ex, Context& context) {
|
[](Regex ex, Context& context) {
|
||||||
if (ex.empty())
|
if (ex.empty())
|
||||||
ex = Regex{RegisterManager::instance()['/'].values(context)[0]};
|
ex = Regex{context.main_sel_register_value("/").str()};
|
||||||
else
|
else
|
||||||
RegisterManager::instance()['/'] = String{ex.str()};
|
RegisterManager::instance()['/'] = String{ex.str()};
|
||||||
if (not ex.empty() and not ex.str().empty())
|
if (not ex.empty() and not ex.str().empty())
|
||||||
|
@ -586,12 +586,12 @@ void search(Context& context, int)
|
||||||
template<SelectMode mode, Direction direction>
|
template<SelectMode mode, Direction direction>
|
||||||
void search_next(Context& context, int param)
|
void search_next(Context& context, int param)
|
||||||
{
|
{
|
||||||
const String& str = RegisterManager::instance()['/'].values(context)[0];
|
StringView str = context.main_sel_register_value("/");
|
||||||
if (not str.empty())
|
if (not str.empty())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Regex ex{str};
|
Regex ex{str.begin(), str.end()};
|
||||||
do {
|
do {
|
||||||
select_next_match<direction, mode>(context.buffer(), context.selections(), ex);
|
select_next_match<direction, mode>(context.buffer(), context.selections(), ex);
|
||||||
} while (--param > 0);
|
} while (--param > 0);
|
||||||
|
@ -632,7 +632,7 @@ void select_regex(Context& context, int)
|
||||||
{
|
{
|
||||||
regex_prompt(context, "select:", [](Regex ex, Context& context) {
|
regex_prompt(context, "select:", [](Regex ex, Context& context) {
|
||||||
if (ex.empty())
|
if (ex.empty())
|
||||||
ex = Regex{RegisterManager::instance()['/'].values(context)[0]};
|
ex = Regex{context.main_sel_register_value("/").str()};
|
||||||
else
|
else
|
||||||
RegisterManager::instance()['/'] = String{ex.str()};
|
RegisterManager::instance()['/'] = String{ex.str()};
|
||||||
if (not ex.empty() and not ex.str().empty())
|
if (not ex.empty() and not ex.str().empty())
|
||||||
|
@ -644,7 +644,7 @@ void split_regex(Context& context, int)
|
||||||
{
|
{
|
||||||
regex_prompt(context, "split:", [](Regex ex, Context& context) {
|
regex_prompt(context, "split:", [](Regex ex, Context& context) {
|
||||||
if (ex.empty())
|
if (ex.empty())
|
||||||
ex = Regex{RegisterManager::instance()['/'].values(context)[0]};
|
ex = Regex{context.main_sel_register_value("/").str()};
|
||||||
else
|
else
|
||||||
RegisterManager::instance()['/'] = String{ex.str()};
|
RegisterManager::instance()['/'] = String{ex.str()};
|
||||||
if (not ex.empty() and not ex.str().empty())
|
if (not ex.empty() and not ex.str().empty())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user