summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2022-08-06 21:51:35 +0200
committerJohannes Altmanninger <aclopte@gmail.com>2022-08-29 08:01:43 +0200
commit611bdebf3cd43c05bdf7573adf4f4a0a2fbc2efe (patch)
tree5203ea23a6b60cd7e668c47cb5a3993619675245
parentaeae2fba37c62e1603bb4c9bd589534090eef6ed (diff)
Access selections via helper methods
The next commit changes the selections to a history of selections. Today we directly access the selections data member. Let's instead use an accessor method, to reduce the number of changes in the next commit.
-rw-r--r--src/context.cc17
-rw-r--r--src/context.hh4
2 files changed, 10 insertions, 11 deletions
diff --git a/src/context.cc b/src/context.cc
index efa91938..3970a6ca 100644
--- a/src/context.cc
+++ b/src/context.cc
@@ -26,7 +26,7 @@ Buffer& Context::buffer() const
{
if (not has_buffer())
throw runtime_error("no buffer in context");
- return const_cast<Buffer&>((*m_selections).buffer());
+ return const_cast<Buffer&>(selections(false).buffer());
}
Window& Context::window() const
@@ -223,24 +223,23 @@ Buffer* Context::last_buffer() const
return previous_buffer != jump_list.rend() ? &previous_buffer->buffer() : nullptr;
}
-SelectionList& Context::selections()
+SelectionList& Context::selections(bool update)
{
if (not m_selections)
throw runtime_error("no selections in context");
- (*m_selections).update();
+ if (update)
+ (*m_selections).update();
return *m_selections;
}
SelectionList& Context::selections_write_only()
{
- if (not m_selections)
- throw runtime_error("no selections in context");
- return *m_selections;
+ return selections(false);
}
-const SelectionList& Context::selections() const
+const SelectionList& Context::selections(bool update) const
{
- return const_cast<Context&>(*this).selections();
+ return const_cast<Context&>(*this).selections(update);
}
Vector<String> Context::selections_content() const
@@ -277,7 +276,7 @@ void Context::end_edition()
StringView Context::main_sel_register_value(StringView reg) const
{
- size_t index = m_selections ? (*m_selections).main_index() : 0;
+ size_t index = has_buffer() ? selections(false).main_index() : 0;
return RegisterManager::instance()[reg].get_main(*this, index);
}
diff --git a/src/context.hh b/src/context.hh
index fd29b897..6a7480cc 100644
--- a/src/context.hh
+++ b/src/context.hh
@@ -83,8 +83,8 @@ public:
InputHandler& input_handler() const;
bool has_input_handler() const { return (bool)m_input_handler; }
- SelectionList& selections();
- const SelectionList& selections() const;
+ SelectionList& selections(bool update = true);
+ const SelectionList& selections(bool update = true) const;
Vector<String> selections_content() const;
// Return potentially out of date selections