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)
|
||||
{
|
||||
BufferCoord cursor = context.editor().selections().back().last().coord();
|
||||
BufferCoord cursor = context.editor().main_selection().last().coord();
|
||||
std::ostringstream oss;
|
||||
oss << context.buffer().name()
|
||||
<< " " << (int)cursor.line+1 << "," << (int)cursor.column+1;
|
||||
|
|
|
@ -662,7 +662,7 @@ void info(const CommandParameters& params, Context& context)
|
|||
if (parser.has_option("anchor"))
|
||||
{
|
||||
style = MenuStyle::Inline;
|
||||
const auto& sel = context.editor().selections().back();
|
||||
const auto& sel = context.editor().main_selection();
|
||||
auto it = sel.last();
|
||||
String anchor = parser.option_value("anchor");
|
||||
if (anchor == "left")
|
||||
|
|
|
@ -261,7 +261,7 @@ void Editor::select(const Selector& selector, SelectMode mode)
|
|||
res.captures() = sel.captures();
|
||||
m_selections.push_back(res);
|
||||
}
|
||||
else if (mode == SelectMode::ReplaceLast)
|
||||
else if (mode == SelectMode::ReplaceMain)
|
||||
{
|
||||
auto& sel = m_selections.back();
|
||||
auto res = selector(sel);
|
||||
|
|
|
@ -18,7 +18,7 @@ enum class SelectMode
|
|||
Replace,
|
||||
Extend,
|
||||
Append,
|
||||
ReplaceLast,
|
||||
ReplaceMain,
|
||||
};
|
||||
|
||||
enum class InsertMode : unsigned
|
||||
|
@ -74,6 +74,7 @@ public:
|
|||
void multi_select(const MultiSelector& selector);
|
||||
|
||||
const SelectionList& selections() const { return m_selections; }
|
||||
const Selection& main_selection() const { return m_selections.back(); }
|
||||
std::vector<String> selections_content() const;
|
||||
|
||||
bool undo();
|
||||
|
|
|
@ -549,7 +549,7 @@ private:
|
|||
{
|
||||
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());
|
||||
if (completions.first.empty())
|
||||
completions = complete_word(cursor);
|
||||
|
|
|
@ -89,7 +89,7 @@ void do_go(Context& context)
|
|||
}
|
||||
case 'f':
|
||||
{
|
||||
String filename = context.editor().selections().back().content();
|
||||
String filename = context.editor().main_selection().content();
|
||||
static char forbidden[] = { '\'', '\\', '\0' };
|
||||
for (auto c : forbidden)
|
||||
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::Extend, false> },
|
||||
{ { 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, '*' }, use_selection_as_search_pattern },
|
||||
|
||||
|
@ -711,10 +711,10 @@ void register_env_vars()
|
|||
{ return ClientManager::instance().get_client_name(context); });
|
||||
shell_manager.register_env_var("cursor_line",
|
||||
[](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",
|
||||
[](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()
|
||||
|
|
|
@ -70,7 +70,7 @@ void test_editor()
|
|||
Selection sel{ buffer.iterator_at_line_begin(2_line), buffer.end() };
|
||||
editor.select(sel, SelectMode::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()
|
||||
|
|
|
@ -40,7 +40,7 @@ Window::~Window()
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -87,8 +87,8 @@ void Window::set_dimensions(const DisplayCoord& dimensions)
|
|||
|
||||
void Window::scroll_to_keep_cursor_visible_ifn()
|
||||
{
|
||||
const BufferIterator first = selections().back().first();
|
||||
const BufferIterator last = selections().back().last();
|
||||
const BufferIterator first = main_selection().first();
|
||||
const BufferIterator last = main_selection().last();
|
||||
|
||||
// scroll lines if needed
|
||||
if (first.line() < m_position.line)
|
||||
|
|
Loading…
Reference in New Issue
Block a user