mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-25 20:41:49 +03:00
Editor: replace selections().back() with main_selection()
This commit is contained in:
parent
5e88b7fe28
commit
a981d41cde
@ -190,7 +190,7 @@ Context& ClientManager::get_client_context(const String& name)
|
|||||||
|
|
||||||
static String generate_status_line(const Context& context)
|
static String generate_status_line(const Context& context)
|
||||||
{
|
{
|
||||||
BufferCoord cursor = context.editor().selections().back().last().coord();
|
BufferCoord cursor = context.editor().main_selection().last().coord();
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << context.buffer().name()
|
oss << context.buffer().name()
|
||||||
<< " " << (int)cursor.line+1 << "," << (int)cursor.column+1;
|
<< " " << (int)cursor.line+1 << "," << (int)cursor.column+1;
|
||||||
|
@ -662,7 +662,7 @@ void info(const 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().back();
|
const auto& sel = context.editor().main_selection();
|
||||||
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")
|
||||||
|
@ -261,7 +261,7 @@ void Editor::select(const Selector& selector, SelectMode mode)
|
|||||||
res.captures() = sel.captures();
|
res.captures() = sel.captures();
|
||||||
m_selections.push_back(res);
|
m_selections.push_back(res);
|
||||||
}
|
}
|
||||||
else if (mode == SelectMode::ReplaceLast)
|
else if (mode == SelectMode::ReplaceMain)
|
||||||
{
|
{
|
||||||
auto& sel = m_selections.back();
|
auto& sel = m_selections.back();
|
||||||
auto res = selector(sel);
|
auto res = selector(sel);
|
||||||
|
@ -18,7 +18,7 @@ enum class SelectMode
|
|||||||
Replace,
|
Replace,
|
||||||
Extend,
|
Extend,
|
||||||
Append,
|
Append,
|
||||||
ReplaceLast,
|
ReplaceMain,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class InsertMode : unsigned
|
enum class InsertMode : unsigned
|
||||||
@ -74,6 +74,7 @@ public:
|
|||||||
void multi_select(const MultiSelector& selector);
|
void multi_select(const MultiSelector& selector);
|
||||||
|
|
||||||
const SelectionList& selections() const { return m_selections; }
|
const SelectionList& selections() const { return m_selections; }
|
||||||
|
const Selection& main_selection() const { return m_selections.back(); }
|
||||||
std::vector<String> selections_content() const;
|
std::vector<String> selections_content() const;
|
||||||
|
|
||||||
bool undo();
|
bool undo();
|
||||||
|
@ -549,7 +549,7 @@ private:
|
|||||||
{
|
{
|
||||||
if (not m_position.is_valid())
|
if (not m_position.is_valid())
|
||||||
{
|
{
|
||||||
BufferIterator cursor = m_context.editor().selections().back().last();
|
BufferIterator cursor = m_context.editor().main_selection().last();
|
||||||
auto completions = complete_opt(cursor, m_context.options());
|
auto completions = complete_opt(cursor, m_context.options());
|
||||||
if (completions.first.empty())
|
if (completions.first.empty())
|
||||||
completions = complete_word(cursor);
|
completions = complete_word(cursor);
|
||||||
|
@ -89,7 +89,7 @@ void do_go(Context& context)
|
|||||||
}
|
}
|
||||||
case 'f':
|
case 'f':
|
||||||
{
|
{
|
||||||
String filename = context.editor().selections().back().content();
|
String filename = context.editor().main_selection().content();
|
||||||
static char forbidden[] = { '\'', '\\', '\0' };
|
static char forbidden[] = { '\'', '\\', '\0' };
|
||||||
for (auto c : forbidden)
|
for (auto c : forbidden)
|
||||||
if (contains(filename, c))
|
if (contains(filename, c))
|
||||||
@ -646,7 +646,7 @@ std::unordered_map<Key, std::function<void (Context& context)>> keymap =
|
|||||||
{ { Key::Modifiers::Alt, '/' }, do_search<SelectMode::Replace, false> },
|
{ { Key::Modifiers::Alt, '/' }, do_search<SelectMode::Replace, false> },
|
||||||
{ { Key::Modifiers::Alt, '?' }, do_search<SelectMode::Extend, false> },
|
{ { Key::Modifiers::Alt, '?' }, do_search<SelectMode::Extend, false> },
|
||||||
{ { Key::Modifiers::None, 'n' }, do_search_next<SelectMode::Replace, true> },
|
{ { Key::Modifiers::None, 'n' }, do_search_next<SelectMode::Replace, true> },
|
||||||
{ { Key::Modifiers::Alt, 'n' }, do_search_next<SelectMode::ReplaceLast, true> },
|
{ { Key::Modifiers::Alt, 'n' }, do_search_next<SelectMode::ReplaceMain, true> },
|
||||||
{ { Key::Modifiers::None, 'N' }, do_search_next<SelectMode::Append, true> },
|
{ { Key::Modifiers::None, 'N' }, do_search_next<SelectMode::Append, true> },
|
||||||
{ { Key::Modifiers::None, '*' }, use_selection_as_search_pattern },
|
{ { Key::Modifiers::None, '*' }, use_selection_as_search_pattern },
|
||||||
|
|
||||||
@ -711,10 +711,10 @@ void register_env_vars()
|
|||||||
{ return ClientManager::instance().get_client_name(context); });
|
{ return ClientManager::instance().get_client_name(context); });
|
||||||
shell_manager.register_env_var("cursor_line",
|
shell_manager.register_env_var("cursor_line",
|
||||||
[](const String& name, const Context& context)
|
[](const String& name, const Context& context)
|
||||||
{ return int_to_str((int)context.editor().selections().back().last().line() + 1); });
|
{ return int_to_str((int)context.editor().main_selection().last().line() + 1); });
|
||||||
shell_manager.register_env_var("cursor_column",
|
shell_manager.register_env_var("cursor_column",
|
||||||
[](const String& name, const Context& context)
|
[](const String& name, const Context& context)
|
||||||
{ return int_to_str((int)context.editor().selections().back().last().column() + 1); });
|
{ return int_to_str((int)context.editor().main_selection().last().column() + 1); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_registers()
|
void register_registers()
|
||||||
|
@ -70,7 +70,7 @@ void test_editor()
|
|||||||
Selection sel{ buffer.iterator_at_line_begin(2_line), buffer.end() };
|
Selection sel{ buffer.iterator_at_line_begin(2_line), buffer.end() };
|
||||||
editor.select(sel, SelectMode::Replace);
|
editor.select(sel, SelectMode::Replace);
|
||||||
editor.insert("",InsertMode::Replace);
|
editor.insert("",InsertMode::Replace);
|
||||||
assert(not editor.selections().back().first().is_end());
|
assert(not editor.main_selection().first().is_end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_incremental_inserter()
|
void test_incremental_inserter()
|
||||||
|
@ -40,7 +40,7 @@ Window::~Window()
|
|||||||
|
|
||||||
void Window::center_selection()
|
void Window::center_selection()
|
||||||
{
|
{
|
||||||
BufferIterator cursor = selections().back().last();
|
BufferIterator cursor = main_selection().last();
|
||||||
m_position.line = std::max(0_line, cursor.line() - m_dimensions.line/2_line);
|
m_position.line = std::max(0_line, cursor.line() - m_dimensions.line/2_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,8 +87,8 @@ void Window::set_dimensions(const DisplayCoord& dimensions)
|
|||||||
|
|
||||||
void Window::scroll_to_keep_cursor_visible_ifn()
|
void Window::scroll_to_keep_cursor_visible_ifn()
|
||||||
{
|
{
|
||||||
const BufferIterator first = selections().back().first();
|
const BufferIterator first = main_selection().first();
|
||||||
const BufferIterator last = selections().back().last();
|
const BufferIterator last = main_selection().last();
|
||||||
|
|
||||||
// scroll lines if needed
|
// scroll lines if needed
|
||||||
if (first.line() < m_position.line)
|
if (first.line() < m_position.line)
|
||||||
|
Loading…
Reference in New Issue
Block a user