summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-12-15 20:37:07 +0000
committerMaxime Coste <frrrwww@gmail.com>2013-12-15 20:37:07 +0000
commitea95632709a6ae3df76772e83e1497a9fcfee52d (patch)
treeaa258ec83e7ec6f765c9c055d5faf1748dbde91b /src
parentad0682ec75d072c648f044580d817bef4098abc0 (diff)
Move Editor::selections_content to Context
Diffstat (limited to 'src')
-rw-r--r--src/context.cc8
-rw-r--r--src/context.hh1
-rw-r--r--src/editor.cc8
-rw-r--r--src/editor.hh1
-rw-r--r--src/main.cc4
-rw-r--r--src/normal.cc14
6 files changed, 17 insertions, 19 deletions
diff --git a/src/context.cc b/src/context.cc
index 6e94b174..163beb16 100644
--- a/src/context.cc
+++ b/src/context.cc
@@ -187,6 +187,14 @@ const SelectionList& Context::selections() const
return editor().selections();
}
+std::vector<String> Context::selections_content() const
+{
+ std::vector<String> contents;
+ for (auto& sel : selections())
+ contents.push_back(buffer().string(sel.min(), buffer().char_next(sel.max())));
+ return contents;
+}
+
void Context::begin_edition()
{
++m_edition_level;
diff --git a/src/context.hh b/src/context.hh
index 58e7380c..fd82b8f9 100644
--- a/src/context.hh
+++ b/src/context.hh
@@ -51,6 +51,7 @@ public:
SelectionList& selections();
const SelectionList& selections() const;
+ std::vector<String> selections_content() const;
void change_editor(Editor& editor);
diff --git a/src/editor.cc b/src/editor.cc
index 13b4511f..8f6bbcf5 100644
--- a/src/editor.cc
+++ b/src/editor.cc
@@ -16,12 +16,4 @@ Editor::Editor(Buffer& buffer)
m_selections(buffer, {BufferCoord{}})
{}
-std::vector<String> Editor::selections_content() const
-{
- std::vector<String> contents;
- for (auto& sel : m_selections)
- contents.push_back(m_buffer->string(sel.min(), m_buffer->char_next(sel.max())));
- return contents;
-}
-
}
diff --git a/src/editor.hh b/src/editor.hh
index c425da84..0e068f90 100644
--- a/src/editor.hh
+++ b/src/editor.hh
@@ -28,7 +28,6 @@ public:
const SelectionList& selections() const { return m_selections; }
SelectionList& selections() { return m_selections; }
- std::vector<String> selections_content() const;
private:
safe_ptr<Buffer> m_buffer;
diff --git a/src/main.cc b/src/main.cc
index af5ffbf3..3cf6b926 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -74,7 +74,7 @@ void register_env_vars()
}, {
"selections",
[](const String& name, const Context& context)
- { auto sels = context.editor().selections_content();
+ { auto sels = context.selections_content();
String res;
for (size_t i = 0; i < sels.size(); ++i)
{
@@ -144,7 +144,7 @@ void register_registers()
struct DynRegDesc { char name; StringList (*func)(const Context&); };
static const DynRegDesc dyn_regs[] = {
{ '%', [](const Context& context) { return StringList{{context.buffer().display_name()}}; } },
- { '.', [](const Context& context) { return context.editor().selections_content(); } },
+ { '.', [](const Context& context) { return context.selections_content(); } },
{ '#', [](const Context& context) { return StringList{{to_string((int)context.selections().size())}}; } },
};
diff --git a/src/normal.cc b/src/normal.cc
index 52ca9694..6bdab3c1 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -393,8 +393,7 @@ template<Codepoint (*func)(Codepoint)>
void for_each_char(Context& context, int)
{
ScopedEdition edition(context);
- Editor& editor = context.editor();
- std::vector<String> sels = editor.selections_content();
+ std::vector<String> sels = context.selections_content();
for (auto& sel : sels)
{
for (auto& c : sel)
@@ -572,14 +571,14 @@ void use_selection_as_search_pattern(Context& context, int)
void yank(Context& context, int)
{
- RegisterManager::instance()['"'] = context.editor().selections_content();
+ RegisterManager::instance()['"'] = context.selections_content();
context.print_status({ "yanked " + to_string(context.selections().size()) +
" selections", get_color("Information") });
}
void cat_yank(Context& context, int)
{
- auto sels = context.editor().selections_content();
+ auto sels = context.selections_content();
String str;
for (auto& sel : sels)
str += sel;
@@ -590,14 +589,14 @@ void cat_yank(Context& context, int)
void erase_selections(Context& context, int)
{
- RegisterManager::instance()['"'] = context.editor().selections_content();
+ RegisterManager::instance()['"'] = context.selections_content();
ScopedEdition edition(context);
erase(context.buffer(), context.selections());
}
void change(Context& context, int param)
{
- RegisterManager::instance()['"'] = context.editor().selections_content();
+ RegisterManager::instance()['"'] = context.selections_content();
enter_insert_mode<InsertMode::Replace>(context, param);
}
@@ -902,8 +901,7 @@ void rotate_selections_content(Context& context, int count)
{
if (count == 0)
count = 1;
- Editor& editor = context.editor();
- auto strings = editor.selections_content();
+ auto strings = context.selections_content();
count = count % strings.size();
std::rotate(strings.begin(), strings.end()-count, strings.end());
context.selections().rotate_main(count);