Add Context::selections method, and use it in priority to the Editor's one
This commit is contained in:
parent
9b6639eb27
commit
935bc3cec9
|
@ -41,7 +41,7 @@ void Client::print_status(DisplayLine status_line)
|
||||||
|
|
||||||
DisplayLine Client::generate_mode_line() const
|
DisplayLine Client::generate_mode_line() const
|
||||||
{
|
{
|
||||||
auto pos = context().editor().selections().main().last();
|
auto pos = context().selections().main().last();
|
||||||
auto col = context().buffer()[pos.line].char_count_to(pos.column);
|
auto col = context().buffer()[pos.line].char_count_to(pos.column);
|
||||||
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
|
@ -76,7 +76,7 @@ void Client::redraw_ifn()
|
||||||
static void reload_buffer(Context& context, const String& filename)
|
static void reload_buffer(Context& context, const String& filename)
|
||||||
{
|
{
|
||||||
DisplayCoord view_pos = context.window().position();
|
DisplayCoord view_pos = context.window().position();
|
||||||
BufferCoord cursor_pos = context.editor().selections().main().last();
|
BufferCoord cursor_pos = context.selections().main().last();
|
||||||
Buffer* buf = create_buffer_from_file(filename);
|
Buffer* buf = create_buffer_from_file(filename);
|
||||||
if (not buf)
|
if (not buf)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -127,7 +127,7 @@ void edit(CommandParameters params, Context& context)
|
||||||
int column = param_count > 2 and not parser[2].empty() ?
|
int column = param_count > 2 and not parser[2].empty() ?
|
||||||
std::max(0, str_to_int(parser[2]) - 1) : 0;
|
std::max(0, str_to_int(parser[2]) - 1) : 0;
|
||||||
|
|
||||||
context.editor().selections() = context.buffer().clamp({ line, column });
|
context.selections() = context.buffer().clamp({ line, column });
|
||||||
if (context.has_window())
|
if (context.has_window())
|
||||||
context.window().center_selection();
|
context.window().center_selection();
|
||||||
}
|
}
|
||||||
|
@ -671,7 +671,7 @@ void info(CommandParameters params, Context& context)
|
||||||
if (parser.has_option("anchor"))
|
if (parser.has_option("anchor"))
|
||||||
{
|
{
|
||||||
style = MenuStyle::Inline;
|
style = MenuStyle::Inline;
|
||||||
const auto& sel = context.editor().selections().main();
|
const auto& sel = context.selections().main();
|
||||||
auto it = sel.last();
|
auto it = sel.last();
|
||||||
String anchor = parser.option_value("anchor");
|
String anchor = parser.option_value("anchor");
|
||||||
if (anchor == "left")
|
if (anchor == "left")
|
||||||
|
|
|
@ -103,7 +103,7 @@ void Context::print_status(DisplayLine status) const
|
||||||
|
|
||||||
void Context::push_jump()
|
void Context::push_jump()
|
||||||
{
|
{
|
||||||
const SelectionList& jump = editor().selections();
|
const SelectionList& jump = selections();
|
||||||
if (m_current_jump != m_jump_list.end())
|
if (m_current_jump != m_jump_list.end())
|
||||||
{
|
{
|
||||||
auto begin = m_current_jump;
|
auto begin = m_current_jump;
|
||||||
|
@ -129,7 +129,7 @@ const DynamicSelectionList& Context::jump_forward()
|
||||||
const DynamicSelectionList& Context::jump_backward()
|
const DynamicSelectionList& Context::jump_backward()
|
||||||
{
|
{
|
||||||
if (m_current_jump != m_jump_list.end() and
|
if (m_current_jump != m_jump_list.end() and
|
||||||
*m_current_jump != editor().selections())
|
*m_current_jump != selections())
|
||||||
{
|
{
|
||||||
push_jump();
|
push_jump();
|
||||||
return *--m_current_jump;
|
return *--m_current_jump;
|
||||||
|
@ -177,4 +177,14 @@ void Context::change_editor(Editor& editor)
|
||||||
input_handler().reset_normal_mode();
|
input_handler().reset_normal_mode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SelectionList& Context::selections()
|
||||||
|
{
|
||||||
|
return editor().selections();
|
||||||
|
}
|
||||||
|
|
||||||
|
const SelectionList& Context::selections() const
|
||||||
|
{
|
||||||
|
return editor().selections();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,9 @@ public:
|
||||||
UserInterface& ui() const;
|
UserInterface& ui() const;
|
||||||
bool has_ui() const { return has_client(); }
|
bool has_ui() const { return has_client(); }
|
||||||
|
|
||||||
|
SelectionList& selections();
|
||||||
|
const SelectionList& selections() const;
|
||||||
|
|
||||||
void change_editor(Editor& editor);
|
void change_editor(Editor& editor);
|
||||||
|
|
||||||
void set_client(Client& client);
|
void set_client(Client& client);
|
||||||
|
|
|
@ -87,7 +87,7 @@ public:
|
||||||
|
|
||||||
String description() const override
|
String description() const override
|
||||||
{
|
{
|
||||||
return to_string(context().editor().selections().size()) +
|
return to_string(context().selections().size()) +
|
||||||
(m_count != 0 ? " sel; param=" + to_string(m_count) : " sel");
|
(m_count != 0 ? " sel; param=" + to_string(m_count) : " sel");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -590,13 +590,13 @@ public:
|
||||||
if (m_current_candidate < 0)
|
if (m_current_candidate < 0)
|
||||||
m_current_candidate += m_matching_candidates.size();
|
m_current_candidate += m_matching_candidates.size();
|
||||||
const String& candidate = m_matching_candidates[m_current_candidate];
|
const String& candidate = m_matching_candidates[m_current_candidate];
|
||||||
const auto& cursor_pos = m_context.editor().selections().main().last();
|
const auto& cursor_pos = m_context.selections().main().last();
|
||||||
const auto prefix_len = buffer.distance(m_completions.begin, cursor_pos);
|
const auto prefix_len = buffer.distance(m_completions.begin, cursor_pos);
|
||||||
const auto suffix_len = std::max(0_byte, buffer.distance(cursor_pos, m_completions.end));
|
const auto suffix_len = std::max(0_byte, buffer.distance(cursor_pos, m_completions.end));
|
||||||
const auto buffer_len = buffer.byte_count();
|
const auto buffer_len = buffer.byte_count();
|
||||||
|
|
||||||
auto ref = buffer.string(m_completions.begin, m_completions.end);
|
auto ref = buffer.string(m_completions.begin, m_completions.end);
|
||||||
for (auto& sel : m_context.editor().selections())
|
for (auto& sel : m_context.selections())
|
||||||
{
|
{
|
||||||
auto offset = buffer.offset(sel.last());
|
auto offset = buffer.offset(sel.last());
|
||||||
auto pos = buffer.iterator_at(sel.last());
|
auto pos = buffer.iterator_at(sel.last());
|
||||||
|
@ -628,7 +628,7 @@ public:
|
||||||
for (auto& candidate : m_completions.candidates)
|
for (auto& candidate : m_completions.candidates)
|
||||||
longest_completion = std::max(longest_completion, candidate.length());
|
longest_completion = std::max(longest_completion, candidate.length());
|
||||||
|
|
||||||
BufferCoord cursor = m_context.editor().selections().main().last();
|
BufferCoord cursor = m_context.selections().main().last();
|
||||||
BufferCoord compl_beg = m_completions.begin;
|
BufferCoord compl_beg = m_completions.begin;
|
||||||
if (cursor.line == compl_beg.line and
|
if (cursor.line == compl_beg.line and
|
||||||
is_in_range(cursor.column - compl_beg.column,
|
is_in_range(cursor.column - compl_beg.column,
|
||||||
|
@ -672,7 +672,7 @@ public:
|
||||||
bool try_complete()
|
bool try_complete()
|
||||||
{
|
{
|
||||||
auto& buffer = m_context.buffer();
|
auto& buffer = m_context.buffer();
|
||||||
BufferCoord cursor_pos = m_context.editor().selections().main().last();
|
BufferCoord cursor_pos = m_context.selections().main().last();
|
||||||
m_completions = (this->*complete_func)(buffer, cursor_pos);
|
m_completions = (this->*complete_func)(buffer, cursor_pos);
|
||||||
if (not m_completions.is_valid())
|
if (not m_completions.is_valid())
|
||||||
return false;
|
return false;
|
||||||
|
|
14
src/main.cc
14
src/main.cc
|
@ -69,7 +69,7 @@ void register_env_vars()
|
||||||
}, {
|
}, {
|
||||||
"selection",
|
"selection",
|
||||||
[](const String& name, const Context& context)
|
[](const String& name, const Context& context)
|
||||||
{ const Range& sel = context.editor().selections().main();
|
{ const Range& sel = context.selections().main();
|
||||||
return content(context.buffer(), sel); }
|
return content(context.buffer(), sel); }
|
||||||
}, {
|
}, {
|
||||||
"selections",
|
"selections",
|
||||||
|
@ -106,20 +106,20 @@ void register_env_vars()
|
||||||
}, {
|
}, {
|
||||||
"cursor_line",
|
"cursor_line",
|
||||||
[](const String& name, const Context& context)
|
[](const String& name, const Context& context)
|
||||||
{ return to_string(context.editor().selections().main().last().line + 1); }
|
{ return to_string(context.selections().main().last().line + 1); }
|
||||||
}, {
|
}, {
|
||||||
"cursor_column",
|
"cursor_column",
|
||||||
[](const String& name, const Context& context)
|
[](const String& name, const Context& context)
|
||||||
{ return to_string(context.editor().selections().main().last().column + 1); }
|
{ return to_string(context.selections().main().last().column + 1); }
|
||||||
}, {
|
}, {
|
||||||
"cursor_char_column",
|
"cursor_char_column",
|
||||||
[](const String& name, const Context& context)
|
[](const String& name, const Context& context)
|
||||||
{ auto coord = context.editor().selections().main().last();
|
{ auto coord = context.selections().main().last();
|
||||||
return to_string(context.buffer()[coord.line].char_count_to(coord.column) + 1); }
|
return to_string(context.buffer()[coord.line].char_count_to(coord.column) + 1); }
|
||||||
}, {
|
}, {
|
||||||
"selection_desc",
|
"selection_desc",
|
||||||
[](const String& name, const Context& context)
|
[](const String& name, const Context& context)
|
||||||
{ auto& sel = context.editor().selections().main();
|
{ auto& sel = context.selections().main();
|
||||||
auto beg = sel.min();
|
auto beg = sel.min();
|
||||||
return to_string(beg.line + 1) + ':' + to_string(beg.column + 1) + '+' +
|
return to_string(beg.line + 1) + ':' + to_string(beg.column + 1) + '+' +
|
||||||
to_string((int)context.buffer().distance(beg, sel.max())+1); }
|
to_string((int)context.buffer().distance(beg, sel.max())+1); }
|
||||||
|
@ -145,7 +145,7 @@ void register_registers()
|
||||||
static const DynRegDesc dyn_regs[] = {
|
static const DynRegDesc dyn_regs[] = {
|
||||||
{ '%', [](const Context& context) { return StringList{{context.buffer().display_name()}}; } },
|
{ '%', [](const Context& context) { return StringList{{context.buffer().display_name()}}; } },
|
||||||
{ '.', [](const Context& context) { return context.editor().selections_content(); } },
|
{ '.', [](const Context& context) { return context.editor().selections_content(); } },
|
||||||
{ '#', [](const Context& context) { return StringList{{to_string((int)context.editor().selections().size())}}; } },
|
{ '#', [](const Context& context) { return StringList{{to_string((int)context.selections().size())}}; } },
|
||||||
};
|
};
|
||||||
|
|
||||||
RegisterManager& register_manager = RegisterManager::instance();
|
RegisterManager& register_manager = RegisterManager::instance();
|
||||||
|
@ -157,7 +157,7 @@ void register_registers()
|
||||||
register_manager.register_dynamic_register('0'+i,
|
register_manager.register_dynamic_register('0'+i,
|
||||||
[i](const Context& context) {
|
[i](const Context& context) {
|
||||||
std::vector<String> result;
|
std::vector<String> result;
|
||||||
for (auto& sel : context.editor().selections())
|
for (auto& sel : context.selections())
|
||||||
result.emplace_back(i < sel.captures().size() ? sel.captures()[i] : "");
|
result.emplace_back(i < sel.captures().size() ? sel.captures()[i] : "");
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
101
src/normal.cc
101
src/normal.cc
|
@ -31,7 +31,7 @@ public:
|
||||||
void operator() (Context& context, int)
|
void operator() (Context& context, int)
|
||||||
{
|
{
|
||||||
auto& buffer = context.buffer();
|
auto& buffer = context.buffer();
|
||||||
auto& selections = context.editor().selections();
|
auto& selections = context.selections();
|
||||||
if (mode == SelectMode::Append)
|
if (mode == SelectMode::Append)
|
||||||
{
|
{
|
||||||
auto& sel = selections.main();
|
auto& sel = selections.main();
|
||||||
|
@ -130,7 +130,7 @@ void goto_commands(Context& context, int line)
|
||||||
if (line != 0)
|
if (line != 0)
|
||||||
{
|
{
|
||||||
context.push_jump();
|
context.push_jump();
|
||||||
select_coord<mode>(LineCount{line - 1}, context.editor().selections());
|
select_coord<mode>(LineCount{line - 1}, context.selections());
|
||||||
if (context.has_window())
|
if (context.has_window())
|
||||||
context.window().center_selection();
|
context.window().center_selection();
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ void goto_commands(Context& context, int line)
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'k':
|
case 'k':
|
||||||
context.push_jump();
|
context.push_jump();
|
||||||
select_coord<mode>(BufferCoord{0,0}, context.editor().selections());
|
select_coord<mode>(BufferCoord{0,0}, context.selections());
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
select<mode>(select_to_eol)(context, 0);
|
select<mode>(select_to_eol)(context, 0);
|
||||||
|
@ -157,18 +157,18 @@ void goto_commands(Context& context, int line)
|
||||||
case 'j':
|
case 'j':
|
||||||
{
|
{
|
||||||
context.push_jump();
|
context.push_jump();
|
||||||
select_coord<mode>({editor.buffer().line_count() - 1, 0}, editor.selections());
|
select_coord<mode>({editor.buffer().line_count() - 1, 0}, context.selections());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'e':
|
case 'e':
|
||||||
context.push_jump();
|
context.push_jump();
|
||||||
select_coord<mode>(editor.buffer().back_coord(), editor.selections());
|
select_coord<mode>(editor.buffer().back_coord(), context.selections());
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
if (context.has_window())
|
if (context.has_window())
|
||||||
{
|
{
|
||||||
auto line = context.window().position().line;
|
auto line = context.window().position().line;
|
||||||
select_coord<mode>(line, editor.selections());
|
select_coord<mode>(line, context.selections());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
|
@ -176,7 +176,7 @@ void goto_commands(Context& context, int line)
|
||||||
{
|
{
|
||||||
auto& window = context.window();
|
auto& window = context.window();
|
||||||
auto line = window.position().line + window.dimensions().line - 1;
|
auto line = window.position().line + window.dimensions().line - 1;
|
||||||
select_coord<mode>(line, editor.selections());
|
select_coord<mode>(line, context.selections());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
|
@ -184,7 +184,7 @@ void goto_commands(Context& context, int line)
|
||||||
{
|
{
|
||||||
auto& window = context.window();
|
auto& window = context.window();
|
||||||
auto line = window.position().line + window.dimensions().line / 2;
|
auto line = window.position().line + window.dimensions().line / 2;
|
||||||
select_coord<mode>(line, editor.selections());
|
select_coord<mode>(line, context.selections());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
|
@ -200,7 +200,7 @@ void goto_commands(Context& context, int line)
|
||||||
}
|
}
|
||||||
case 'f':
|
case 'f':
|
||||||
{
|
{
|
||||||
const Range& sel = context.editor().selections().main();
|
const Range& sel = context.selections().main();
|
||||||
const Buffer& buffer = context.buffer();
|
const Buffer& buffer = context.buffer();
|
||||||
String filename = content(buffer, sel);
|
String filename = content(buffer, sel);
|
||||||
static constexpr char forbidden[] = { '\'', '\\', '\0' };
|
static constexpr char forbidden[] = { '\'', '\\', '\0' };
|
||||||
|
@ -283,9 +283,9 @@ void replace_with_char(Context& context, int)
|
||||||
if (not isprint(key.key))
|
if (not isprint(key.key))
|
||||||
return;
|
return;
|
||||||
Editor& editor = context.editor();
|
Editor& editor = context.editor();
|
||||||
SelectionList sels = editor.selections();
|
SelectionList sels = context.selections();
|
||||||
auto restore_sels = on_scope_end([&]{ editor.selections() = std::move(sels); });
|
auto restore_sels = on_scope_end([&]{ context.selections() = std::move(sels); });
|
||||||
select_all_matches(editor.buffer(), editor.selections(), Regex{"."});
|
select_all_matches(editor.buffer(), context.selections(), Regex{"."});
|
||||||
editor.insert(codepoint_to_str(key.key), InsertMode::Replace);
|
editor.insert(codepoint_to_str(key.key), InsertMode::Replace);
|
||||||
}, "replace with char", "enter char to replace with\n");
|
}, "replace with char", "enter char to replace with\n");
|
||||||
}
|
}
|
||||||
|
@ -345,7 +345,7 @@ void pipe(Context& context, int)
|
||||||
|
|
||||||
Editor& editor = context.editor();
|
Editor& editor = context.editor();
|
||||||
std::vector<String> strings;
|
std::vector<String> strings;
|
||||||
for (auto& sel : context.editor().selections())
|
for (auto& sel : context.selections())
|
||||||
{
|
{
|
||||||
auto str = content(context.buffer(), sel);
|
auto str = content(context.buffer(), sel);
|
||||||
bool insert_eol = str.back() != '\n';
|
bool insert_eol = str.back() != '\n';
|
||||||
|
@ -365,12 +365,12 @@ template<SelectMode mode, Direction direction>
|
||||||
void search(Context& context, int)
|
void search(Context& context, int)
|
||||||
{
|
{
|
||||||
const char* prompt = direction == Forward ? "search:" : "reverse search:";
|
const char* prompt = direction == Forward ? "search:" : "reverse search:";
|
||||||
DynamicSelectionList selections{context.buffer(), context.editor().selections()};
|
DynamicSelectionList selections{context.buffer(), context.selections()};
|
||||||
context.input_handler().prompt(prompt, get_color("Prompt"), complete_nothing,
|
context.input_handler().prompt(prompt, get_color("Prompt"), complete_nothing,
|
||||||
[selections](const String& str, PromptEvent event, Context& context) {
|
[selections](const String& str, PromptEvent event, Context& context) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
context.editor().selections() = selections;
|
context.selections() = selections;
|
||||||
|
|
||||||
if (event == PromptEvent::Abort)
|
if (event == PromptEvent::Abort)
|
||||||
return;
|
return;
|
||||||
|
@ -388,7 +388,7 @@ void search(Context& context, int)
|
||||||
else if (str.empty() or not context.options()["incsearch"].get<bool>())
|
else if (str.empty() or not context.options()["incsearch"].get<bool>())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
select_next_match<direction, mode>(context.buffer(), context.editor().selections(), ex);
|
select_next_match<direction, mode>(context.buffer(), context.selections(), ex);
|
||||||
}
|
}
|
||||||
catch (boost::regex_error& err)
|
catch (boost::regex_error& err)
|
||||||
{
|
{
|
||||||
|
@ -399,7 +399,7 @@ void search(Context& context, int)
|
||||||
}
|
}
|
||||||
catch (runtime_error&)
|
catch (runtime_error&)
|
||||||
{
|
{
|
||||||
context.editor().selections() = selections;
|
context.selections() = selections;
|
||||||
// only validation should propagate errors,
|
// only validation should propagate errors,
|
||||||
// incremental search should not.
|
// incremental search should not.
|
||||||
if (event == PromptEvent::Validate)
|
if (event == PromptEvent::Validate)
|
||||||
|
@ -418,7 +418,7 @@ void search_next(Context& context, int param)
|
||||||
{
|
{
|
||||||
Regex ex{str};
|
Regex ex{str};
|
||||||
do {
|
do {
|
||||||
select_next_match<direction, mode>(context.buffer(), context.editor().selections(), ex);
|
select_next_match<direction, mode>(context.buffer(), context.selections(), ex);
|
||||||
} while (--param > 0);
|
} while (--param > 0);
|
||||||
}
|
}
|
||||||
catch (boost::regex_error& err)
|
catch (boost::regex_error& err)
|
||||||
|
@ -434,7 +434,7 @@ template<bool smart>
|
||||||
void use_selection_as_search_pattern(Context& context, int)
|
void use_selection_as_search_pattern(Context& context, int)
|
||||||
{
|
{
|
||||||
std::vector<String> patterns;
|
std::vector<String> patterns;
|
||||||
auto& sels = context.editor().selections();
|
auto& sels = context.selections();
|
||||||
const auto& buffer = context.buffer();
|
const auto& buffer = context.buffer();
|
||||||
for (auto& sel : sels)
|
for (auto& sel : sels)
|
||||||
{
|
{
|
||||||
|
@ -456,7 +456,7 @@ void use_selection_as_search_pattern(Context& context, int)
|
||||||
void yank(Context& context, int)
|
void yank(Context& context, int)
|
||||||
{
|
{
|
||||||
RegisterManager::instance()['"'] = context.editor().selections_content();
|
RegisterManager::instance()['"'] = context.editor().selections_content();
|
||||||
context.print_status({ "yanked " + to_string(context.editor().selections().size()) +
|
context.print_status({ "yanked " + to_string(context.selections().size()) +
|
||||||
" selections", get_color("Information") });
|
" selections", get_color("Information") });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,7 +545,7 @@ void select_regex(Context& context, int)
|
||||||
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())
|
||||||
select_all_matches(context.buffer(), context.editor().selections(), ex);
|
select_all_matches(context.buffer(), context.selections(), ex);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -557,13 +557,13 @@ void split_regex(Context& context, int)
|
||||||
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())
|
||||||
split_selections(context.buffer(), context.editor().selections(), ex);
|
split_selections(context.buffer(), context.selections(), ex);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void split_lines(Context& context, int)
|
void split_lines(Context& context, int)
|
||||||
{
|
{
|
||||||
auto& selections = context.editor().selections();
|
auto& selections = context.selections();
|
||||||
auto& buffer = context.buffer();
|
auto& buffer = context.buffer();
|
||||||
SelectionList res;
|
SelectionList res;
|
||||||
for (auto& sel : selections)
|
for (auto& sel : selections)
|
||||||
|
@ -590,8 +590,8 @@ void join_select_spaces(Context& context, int)
|
||||||
select<SelectMode::Extend>(select_to_eol)(context, 0);
|
select<SelectMode::Extend>(select_to_eol)(context, 0);
|
||||||
auto& editor = context.editor();
|
auto& editor = context.editor();
|
||||||
auto& buffer = context.buffer();
|
auto& buffer = context.buffer();
|
||||||
auto& selections = editor.selections();
|
auto& selections = context.selections();
|
||||||
select_all_matches(buffer, editor.selections(), Regex{"(\n\\h*)+"});
|
select_all_matches(buffer, context.selections(), Regex{"(\n\\h*)+"});
|
||||||
// remove last end of line if selected
|
// remove last end of line if selected
|
||||||
kak_assert(std::is_sorted(selections.begin(), selections.end(),
|
kak_assert(std::is_sorted(selections.begin(), selections.end(),
|
||||||
[](const Selection& lhs, const Selection& rhs)
|
[](const Selection& lhs, const Selection& rhs)
|
||||||
|
@ -604,8 +604,8 @@ void join_select_spaces(Context& context, int)
|
||||||
void join(Context& context, int param)
|
void join(Context& context, int param)
|
||||||
{
|
{
|
||||||
Editor& editor = context.editor();
|
Editor& editor = context.editor();
|
||||||
DynamicSelectionList sels{editor.buffer(), editor.selections()};
|
DynamicSelectionList sels{editor.buffer(), context.selections()};
|
||||||
auto restore_sels = on_scope_end([&]{ editor.selections() = std::move(sels); });
|
auto restore_sels = on_scope_end([&]{ context.selections() = std::move(sels); });
|
||||||
join_select_spaces(context, param);
|
join_select_spaces(context, param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,10 +616,9 @@ void keep(Context& context, int)
|
||||||
regex_prompt(context, prompt, [](const Regex& ex, Context& context) {
|
regex_prompt(context, prompt, [](const Regex& ex, Context& context) {
|
||||||
if (ex.empty())
|
if (ex.empty())
|
||||||
return;
|
return;
|
||||||
Editor& editor = context.editor();
|
|
||||||
const Buffer& buffer = context.buffer();
|
const Buffer& buffer = context.buffer();
|
||||||
SelectionList keep;
|
SelectionList keep;
|
||||||
for (auto& sel : editor.selections())
|
for (auto& sel : context.selections())
|
||||||
{
|
{
|
||||||
if (boost::regex_search(buffer.iterator_at(sel.min()),
|
if (boost::regex_search(buffer.iterator_at(sel.min()),
|
||||||
utf8::next(buffer.iterator_at(sel.max())), ex) == matching)
|
utf8::next(buffer.iterator_at(sel.max())), ex) == matching)
|
||||||
|
@ -627,7 +626,7 @@ void keep(Context& context, int)
|
||||||
}
|
}
|
||||||
if (keep.empty())
|
if (keep.empty())
|
||||||
throw runtime_error("no selections remaining");
|
throw runtime_error("no selections remaining");
|
||||||
editor.selections() = std::move(keep);
|
context.selections() = std::move(keep);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -639,10 +638,10 @@ void indent(Context& context, int)
|
||||||
|
|
||||||
auto& editor = context.editor();
|
auto& editor = context.editor();
|
||||||
auto& buffer = context.buffer();
|
auto& buffer = context.buffer();
|
||||||
DynamicSelectionList sels{editor.buffer(), editor.selections()};
|
DynamicSelectionList sels{editor.buffer(), context.selections()};
|
||||||
auto restore_sels = on_scope_end([&]{ editor.selections() = std::move(sels); });
|
auto restore_sels = on_scope_end([&]{ context.selections() = std::move(sels); });
|
||||||
SelectionList res;
|
SelectionList res;
|
||||||
for (auto& sel : editor.selections())
|
for (auto& sel : context.selections())
|
||||||
{
|
{
|
||||||
for (auto line = sel.min().line; line < sel.max().line+1; ++line)
|
for (auto line = sel.min().line; line < sel.max().line+1; ++line)
|
||||||
{
|
{
|
||||||
|
@ -650,7 +649,7 @@ void indent(Context& context, int)
|
||||||
res.emplace_back(line, line);
|
res.emplace_back(line, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
editor.selections() = std::move(res);
|
context.selections() = std::move(res);
|
||||||
editor.insert(indent, InsertMode::Insert);
|
editor.insert(indent, InsertMode::Insert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -664,11 +663,11 @@ void deindent(Context& context, int)
|
||||||
|
|
||||||
auto& editor = context.editor();
|
auto& editor = context.editor();
|
||||||
auto& buffer = context.buffer();
|
auto& buffer = context.buffer();
|
||||||
DynamicSelectionList sels{editor.buffer(), editor.selections()};
|
DynamicSelectionList sels{editor.buffer(), context.selections()};
|
||||||
auto restore_sels = on_scope_end([&]{ editor.selections() = std::move(sels); });
|
auto restore_sels = on_scope_end([&]{ context.selections() = std::move(sels); });
|
||||||
|
|
||||||
SelectionList res;
|
SelectionList res;
|
||||||
for (auto& sel : editor.selections())
|
for (auto& sel : context.selections())
|
||||||
{
|
{
|
||||||
for (auto line = sel.min().line; line < sel.max().line+1; ++line)
|
for (auto line = sel.min().line; line < sel.max().line+1; ++line)
|
||||||
{
|
{
|
||||||
|
@ -695,7 +694,7 @@ void deindent(Context& context, int)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
editor.selections() = std::move(res);
|
context.selections() = std::move(res);
|
||||||
editor.erase();
|
editor.erase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -787,7 +786,7 @@ void scroll(Context& context, int)
|
||||||
|
|
||||||
void rotate_selections(Context& context, int count)
|
void rotate_selections(Context& context, int count)
|
||||||
{
|
{
|
||||||
context.editor().selections().rotate_main(count != 0 ? count : 1);
|
context.selections().rotate_main(count != 0 ? count : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rotate_selections_content(Context& context, int count)
|
void rotate_selections_content(Context& context, int count)
|
||||||
|
@ -799,7 +798,7 @@ void rotate_selections_content(Context& context, int count)
|
||||||
count = count % strings.size();
|
count = count % strings.size();
|
||||||
std::rotate(strings.begin(), strings.end()-count, strings.end());
|
std::rotate(strings.begin(), strings.end()-count, strings.end());
|
||||||
editor.insert(strings, InsertMode::Replace);
|
editor.insert(strings, InsertMode::Replace);
|
||||||
editor.selections().rotate_main(count);
|
context.selections().rotate_main(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class SelectFlags
|
enum class SelectFlags
|
||||||
|
@ -876,13 +875,13 @@ void jump(Context& context, int)
|
||||||
auto& manager = ClientManager::instance();
|
auto& manager = ClientManager::instance();
|
||||||
context.change_editor(manager.get_unused_window_for_buffer(buffer));
|
context.change_editor(manager.get_unused_window_for_buffer(buffer));
|
||||||
}
|
}
|
||||||
context.editor().selections() = jump;
|
context.selections() = jump;
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_selections(Context& context, int)
|
void save_selections(Context& context, int)
|
||||||
{
|
{
|
||||||
context.push_jump();
|
context.push_jump();
|
||||||
context.print_status({ "saved " + to_string(context.editor().selections().size()) +
|
context.print_status({ "saved " + to_string(context.selections().size()) +
|
||||||
" selections", get_color("Information") });
|
" selections", get_color("Information") });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -905,7 +904,7 @@ static CharCount get_column(const Buffer& buffer,
|
||||||
|
|
||||||
void align(Context& context, int)
|
void align(Context& context, int)
|
||||||
{
|
{
|
||||||
auto& selections = context.editor().selections();
|
auto& selections = context.selections();
|
||||||
auto& buffer = context.buffer();
|
auto& buffer = context.buffer();
|
||||||
const CharCount tabstop = context.options()["tabstop"].get<int>();
|
const CharCount tabstop = context.options()["tabstop"].get<int>();
|
||||||
|
|
||||||
|
@ -956,7 +955,7 @@ void align_indent(Context& context, int selection)
|
||||||
{
|
{
|
||||||
auto& editor = context.editor();
|
auto& editor = context.editor();
|
||||||
auto& buffer = context.buffer();
|
auto& buffer = context.buffer();
|
||||||
auto& selections = editor.selections();
|
auto& selections = context.selections();
|
||||||
std::vector<LineCount> lines;
|
std::vector<LineCount> lines;
|
||||||
for (auto sel : selections)
|
for (auto sel : selections)
|
||||||
{
|
{
|
||||||
|
@ -966,7 +965,7 @@ void align_indent(Context& context, int selection)
|
||||||
if (selection > selections.size())
|
if (selection > selections.size())
|
||||||
throw runtime_error("invalid selection index");
|
throw runtime_error("invalid selection index");
|
||||||
if (selection == 0)
|
if (selection == 0)
|
||||||
selection = editor.selections().main_index() + 1;
|
selection = context.selections().main_index() + 1;
|
||||||
|
|
||||||
const String& line = buffer[selections[selection-1].min().line];
|
const String& line = buffer[selections[selection-1].min().line];
|
||||||
auto it = line.begin();
|
auto it = line.begin();
|
||||||
|
@ -1011,7 +1010,7 @@ void move(Context& context, int count)
|
||||||
Type offset(std::max(count,1));
|
Type offset(std::max(count,1));
|
||||||
if (direction == Backward)
|
if (direction == Backward)
|
||||||
offset = -offset;
|
offset = -offset;
|
||||||
auto& selections = context.editor().selections();
|
auto& selections = context.selections();
|
||||||
for (auto& sel : selections)
|
for (auto& sel : selections)
|
||||||
{
|
{
|
||||||
auto last = context.has_window() ? context.window().offset_coord(sel.last(), offset)
|
auto last = context.has_window() ? context.window().offset_coord(sel.last(), offset)
|
||||||
|
@ -1072,14 +1071,14 @@ KeyMap keymap =
|
||||||
|
|
||||||
{ '.', repeat_insert },
|
{ '.', repeat_insert },
|
||||||
|
|
||||||
{ '%', [](Context& context, int) { select_whole_buffer(context.buffer(), context.editor().selections()); } },
|
{ '%', [](Context& context, int) { select_whole_buffer(context.buffer(), context.selections()); } },
|
||||||
|
|
||||||
{ ':', command },
|
{ ':', command },
|
||||||
{ '|', pipe },
|
{ '|', pipe },
|
||||||
{ ' ', [](Context& context, int count) { if (count == 0) clear_selections(context.buffer(), context.editor().selections());
|
{ ' ', [](Context& context, int count) { if (count == 0) clear_selections(context.buffer(), context.selections());
|
||||||
else keep_selection(context.editor().selections(), count-1); } },
|
else keep_selection(context.selections(), count-1); } },
|
||||||
{ alt(' '), [](Context& context, int count) { if (count == 0) flip_selections(context.editor().selections());
|
{ alt(' '), [](Context& context, int count) { if (count == 0) flip_selections(context.selections());
|
||||||
else remove_selection(context.editor().selections(), count-1); } },
|
else remove_selection(context.selections(), count-1); } },
|
||||||
{ 'w', repeated(select<SelectMode::Replace>(select_to_next_word<Word>)) },
|
{ 'w', repeated(select<SelectMode::Replace>(select_to_next_word<Word>)) },
|
||||||
{ 'e', repeated(select<SelectMode::Replace>(select_to_next_word_end<Word>)) },
|
{ 'e', repeated(select<SelectMode::Replace>(select_to_next_word_end<Word>)) },
|
||||||
{ 'b', repeated(select<SelectMode::Replace>(select_to_previous_word<Word>)) },
|
{ 'b', repeated(select<SelectMode::Replace>(select_to_previous_word<Word>)) },
|
||||||
|
|
Loading…
Reference in New Issue
Block a user