Avoid unneeded update of selections when we are going to overwrite them
This commit is contained in:
parent
9f65a4e6dd
commit
1dfa2d7fe4
|
@ -138,7 +138,7 @@ void Client::change_buffer(Buffer& buffer)
|
||||||
m_window->options().register_watcher(*this);
|
m_window->options().register_watcher(*this);
|
||||||
m_ui->set_ui_options(m_window->options()["ui_options"].get<UserInterface::Options>());
|
m_ui->set_ui_options(m_window->options()["ui_options"].get<UserInterface::Options>());
|
||||||
|
|
||||||
context().m_selections = std::move(ws.selections);
|
context().selections_write_only() = std::move(ws.selections);
|
||||||
context().set_window(*m_window);
|
context().set_window(*m_window);
|
||||||
m_window->set_dimensions(ui().dimensions());
|
m_window->set_dimensions(ui().dimensions());
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ void Client::reload_buffer()
|
||||||
ByteCoord cursor_pos = context().selections().main().cursor();
|
ByteCoord cursor_pos = context().selections().main().cursor();
|
||||||
Buffer* buf = create_buffer_from_file(buffer.name());
|
Buffer* buf = create_buffer_from_file(buffer.name());
|
||||||
kak_assert(buf == &buffer);
|
kak_assert(buf == &buffer);
|
||||||
context().selections() = SelectionList{buffer, buffer.clamp(cursor_pos)};
|
context().selections_write_only() = SelectionList{buffer, buffer.clamp(cursor_pos)};
|
||||||
context().window().set_position(view_pos);
|
context().window().set_position(view_pos);
|
||||||
context().print_status({ "'" + buffer.display_name() + "' reloaded",
|
context().print_status({ "'" + buffer.display_name() + "' reloaded",
|
||||||
get_face("Information") });
|
get_face("Information") });
|
||||||
|
|
|
@ -175,7 +175,7 @@ void edit(const ParametersParser& parser, Context& context)
|
||||||
std::max(0, str_to_int(parser[2]) - 1) : 0;
|
std::max(0, str_to_int(parser[2]) - 1) : 0;
|
||||||
|
|
||||||
auto& buffer = context.buffer();
|
auto& buffer = context.buffer();
|
||||||
context.selections() = { buffer, buffer.clamp({ line, column }) };
|
context.selections_write_only() = { buffer, buffer.clamp({ line, column }) };
|
||||||
if (context.has_window())
|
if (context.has_window())
|
||||||
context.window().center_line(context.selections().main().cursor().line);
|
context.window().center_line(context.selections().main().cursor().line);
|
||||||
}
|
}
|
||||||
|
@ -1180,7 +1180,7 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func)
|
||||||
ScopedEdition edition{c};
|
ScopedEdition edition{c};
|
||||||
for (auto& sel : sels)
|
for (auto& sel : sels)
|
||||||
{
|
{
|
||||||
c.selections() = SelectionList{ sels.buffer(), sel, sels.timestamp() };
|
c.selections_write_only() = SelectionList{ sels.buffer(), sel, sels.timestamp() };
|
||||||
c.selections().update();
|
c.selections().update();
|
||||||
|
|
||||||
func(parser, c);
|
func(parser, c);
|
||||||
|
@ -1489,7 +1489,7 @@ const CommandDesc select_cmd = {
|
||||||
CommandCompleter{},
|
CommandCompleter{},
|
||||||
[](const ParametersParser& parser, Context& context)
|
[](const ParametersParser& parser, Context& context)
|
||||||
{
|
{
|
||||||
context.selections() = selection_list_from_string(context.buffer(), parser[0]);
|
context.selections_write_only() = selection_list_from_string(context.buffer(), parser[0]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -197,6 +197,13 @@ SelectionList& Context::selections()
|
||||||
return *m_selections;
|
return *m_selections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SelectionList& Context::selections_write_only()
|
||||||
|
{
|
||||||
|
if (not m_selections)
|
||||||
|
throw runtime_error("no selections in context");
|
||||||
|
return *m_selections;
|
||||||
|
}
|
||||||
|
|
||||||
const SelectionList& Context::selections() const
|
const SelectionList& Context::selections() const
|
||||||
{
|
{
|
||||||
return const_cast<Context&>(*this).selections();
|
return const_cast<Context&>(*this).selections();
|
||||||
|
|
|
@ -90,6 +90,9 @@ public:
|
||||||
const SelectionList& selections() const;
|
const SelectionList& selections() const;
|
||||||
Vector<String> selections_content() const;
|
Vector<String> selections_content() const;
|
||||||
|
|
||||||
|
// Return potentially out of date selections
|
||||||
|
SelectionList& selections_write_only();
|
||||||
|
|
||||||
void change_buffer(Buffer& buffer);
|
void change_buffer(Buffer& buffer);
|
||||||
|
|
||||||
void set_client(Client& client);
|
void set_client(Client& client);
|
||||||
|
@ -141,7 +144,6 @@ private:
|
||||||
SafePtr<Window> m_window;
|
SafePtr<Window> m_window;
|
||||||
SafePtr<Client> m_client;
|
SafePtr<Client> m_client;
|
||||||
|
|
||||||
friend class Client;
|
|
||||||
Optional<SelectionList> m_selections;
|
Optional<SelectionList> m_selections;
|
||||||
|
|
||||||
String m_name;
|
String m_name;
|
||||||
|
|
|
@ -60,7 +60,7 @@ struct MouseHandler
|
||||||
{
|
{
|
||||||
m_dragging = true;
|
m_dragging = true;
|
||||||
m_anchor = context.window().buffer_coord(key.mouse_coord());
|
m_anchor = context.window().buffer_coord(key.mouse_coord());
|
||||||
context.selections() = SelectionList{ context.buffer(), m_anchor };
|
context.selections_write_only() = SelectionList{ context.buffer(), m_anchor };
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (key.modifiers == Key::Modifiers::MouseRelease)
|
if (key.modifiers == Key::Modifiers::MouseRelease)
|
||||||
|
@ -69,7 +69,7 @@ struct MouseHandler
|
||||||
return true;
|
return true;
|
||||||
m_dragging = false;
|
m_dragging = false;
|
||||||
auto cursor = context.window().buffer_coord(key.mouse_coord());
|
auto cursor = context.window().buffer_coord(key.mouse_coord());
|
||||||
context.selections() = SelectionList{ context.buffer(), Selection{m_anchor, cursor} };
|
context.selections_write_only() = SelectionList{ context.buffer(), Selection{m_anchor, cursor} };
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (key.modifiers == Key::Modifiers::MousePos)
|
if (key.modifiers == Key::Modifiers::MousePos)
|
||||||
|
@ -77,7 +77,7 @@ struct MouseHandler
|
||||||
if (not m_dragging)
|
if (not m_dragging)
|
||||||
return true;
|
return true;
|
||||||
auto cursor = context.window().buffer_coord(key.mouse_coord());
|
auto cursor = context.window().buffer_coord(key.mouse_coord());
|
||||||
context.selections() = SelectionList{ context.buffer(), Selection{m_anchor, cursor} };
|
context.selections_write_only() = SelectionList{ context.buffer(), Selection{m_anchor, cursor} };
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (key.modifiers == Key::Modifiers::MouseWheelDown)
|
if (key.modifiers == Key::Modifiers::MouseWheelDown)
|
||||||
|
|
|
@ -563,7 +563,7 @@ void regex_prompt(Context& context, const String prompt, T func)
|
||||||
if (event != PromptEvent::Change and context.has_ui())
|
if (event != PromptEvent::Change and context.has_ui())
|
||||||
context.ui().info_hide();
|
context.ui().info_hide();
|
||||||
selections.update();
|
selections.update();
|
||||||
context.selections() = selections;
|
context.selections_write_only() = selections;
|
||||||
context.input_handler().set_prompt_face(get_face("Prompt"));
|
context.input_handler().set_prompt_face(get_face("Prompt"));
|
||||||
if (event == PromptEvent::Abort)
|
if (event == PromptEvent::Abort)
|
||||||
return;
|
return;
|
||||||
|
@ -600,7 +600,7 @@ void regex_prompt(Context& context, const String prompt, T func)
|
||||||
}
|
}
|
||||||
catch (runtime_error&)
|
catch (runtime_error&)
|
||||||
{
|
{
|
||||||
context.selections() = selections;
|
context.selections_write_only() = 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)
|
||||||
|
@ -733,7 +733,7 @@ void join_lines_select_spaces(Context& context, NormalParams)
|
||||||
}
|
}
|
||||||
if (selections.empty())
|
if (selections.empty())
|
||||||
return;
|
return;
|
||||||
context.selections() = selections;
|
context.selections_write_only() = std::move(selections);
|
||||||
ScopedEdition edition(context);
|
ScopedEdition edition(context);
|
||||||
context.selections().insert(" "_str, InsertMode::Replace);
|
context.selections().insert(" "_str, InsertMode::Replace);
|
||||||
}
|
}
|
||||||
|
@ -743,7 +743,7 @@ void join_lines(Context& context, NormalParams params)
|
||||||
SelectionList sels{context.selections()};
|
SelectionList sels{context.selections()};
|
||||||
auto restore_sels = on_scope_end([&]{
|
auto restore_sels = on_scope_end([&]{
|
||||||
sels.update();
|
sels.update();
|
||||||
context.selections() = std::move(sels);
|
context.selections_write_only() = std::move(sels);
|
||||||
});
|
});
|
||||||
|
|
||||||
join_lines_select_spaces(context, params);
|
join_lines_select_spaces(context, params);
|
||||||
|
@ -766,7 +766,7 @@ void keep(Context& context, NormalParams)
|
||||||
}
|
}
|
||||||
if (keep.empty())
|
if (keep.empty())
|
||||||
throw runtime_error("no selections remaining");
|
throw runtime_error("no selections remaining");
|
||||||
context.selections() = std::move(keep);
|
context.selections_write_only() = std::move(keep);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -788,7 +788,7 @@ void keep_pipe(Context& context, NormalParams)
|
||||||
}
|
}
|
||||||
if (keep.empty())
|
if (keep.empty())
|
||||||
throw runtime_error("no selections remaining");
|
throw runtime_error("no selections remaining");
|
||||||
context.selections() = std::move(keep);
|
context.selections_write_only() = std::move(keep);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
template<bool indent_empty = false>
|
template<bool indent_empty = false>
|
||||||
|
@ -1100,7 +1100,7 @@ void jump(Context& context, NormalParams)
|
||||||
BufferManager::instance().set_last_used_buffer(buffer);
|
BufferManager::instance().set_last_used_buffer(buffer);
|
||||||
if (&buffer != &context.buffer())
|
if (&buffer != &context.buffer())
|
||||||
context.change_buffer(buffer);
|
context.change_buffer(buffer);
|
||||||
context.selections() = jump;
|
context.selections_write_only() = jump;
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_selections(Context& context, NormalParams)
|
void save_selections(Context& context, NormalParams)
|
||||||
|
@ -1267,7 +1267,7 @@ void undo(Context& context, NormalParams)
|
||||||
{
|
{
|
||||||
auto ranges = compute_modified_ranges(buffer, timestamp);
|
auto ranges = compute_modified_ranges(buffer, timestamp);
|
||||||
if (not ranges.empty())
|
if (not ranges.empty())
|
||||||
context.selections() = std::move(ranges);
|
context.selections_write_only() = std::move(ranges);
|
||||||
context.selections().avoid_eol();
|
context.selections().avoid_eol();
|
||||||
}
|
}
|
||||||
else if (not res)
|
else if (not res)
|
||||||
|
@ -1284,7 +1284,7 @@ void redo(Context& context, NormalParams)
|
||||||
{
|
{
|
||||||
auto ranges = compute_modified_ranges(buffer, timestamp);
|
auto ranges = compute_modified_ranges(buffer, timestamp);
|
||||||
if (not ranges.empty())
|
if (not ranges.empty())
|
||||||
context.selections() = std::move(ranges);
|
context.selections_write_only() = std::move(ranges);
|
||||||
context.selections().avoid_eol();
|
context.selections().avoid_eol();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user