Move Editor::selections_content to Context
This commit is contained in:
parent
ad0682ec75
commit
ea95632709
|
@ -187,6 +187,14 @@ const SelectionList& Context::selections() const
|
||||||
return editor().selections();
|
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()
|
void Context::begin_edition()
|
||||||
{
|
{
|
||||||
++m_edition_level;
|
++m_edition_level;
|
||||||
|
|
|
@ -51,6 +51,7 @@ public:
|
||||||
|
|
||||||
SelectionList& selections();
|
SelectionList& selections();
|
||||||
const SelectionList& selections() const;
|
const SelectionList& selections() const;
|
||||||
|
std::vector<String> selections_content() const;
|
||||||
|
|
||||||
void change_editor(Editor& editor);
|
void change_editor(Editor& editor);
|
||||||
|
|
||||||
|
|
|
@ -16,12 +16,4 @@ Editor::Editor(Buffer& buffer)
|
||||||
m_selections(buffer, {BufferCoord{}})
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ public:
|
||||||
|
|
||||||
const SelectionList& selections() const { return m_selections; }
|
const SelectionList& selections() const { return m_selections; }
|
||||||
SelectionList& selections() { return m_selections; }
|
SelectionList& selections() { return m_selections; }
|
||||||
std::vector<String> selections_content() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
safe_ptr<Buffer> m_buffer;
|
safe_ptr<Buffer> m_buffer;
|
||||||
|
|
|
@ -74,7 +74,7 @@ void register_env_vars()
|
||||||
}, {
|
}, {
|
||||||
"selections",
|
"selections",
|
||||||
[](const String& name, const Context& context)
|
[](const String& name, const Context& context)
|
||||||
{ auto sels = context.editor().selections_content();
|
{ auto sels = context.selections_content();
|
||||||
String res;
|
String res;
|
||||||
for (size_t i = 0; i < sels.size(); ++i)
|
for (size_t i = 0; i < sels.size(); ++i)
|
||||||
{
|
{
|
||||||
|
@ -144,7 +144,7 @@ void register_registers()
|
||||||
struct DynRegDesc { char name; StringList (*func)(const Context&); };
|
struct DynRegDesc { char name; StringList (*func)(const Context&); };
|
||||||
static const DynRegDesc dyn_regs[] = {
|
static const DynRegDesc dyn_regs[] = {
|
||||||
{ '%', [](const Context& context) { return StringList{{context.buffer().display_name()}}; } },
|
{ '%', [](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())}}; } },
|
{ '#', [](const Context& context) { return StringList{{to_string((int)context.selections().size())}}; } },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -393,8 +393,7 @@ template<Codepoint (*func)(Codepoint)>
|
||||||
void for_each_char(Context& context, int)
|
void for_each_char(Context& context, int)
|
||||||
{
|
{
|
||||||
ScopedEdition edition(context);
|
ScopedEdition edition(context);
|
||||||
Editor& editor = context.editor();
|
std::vector<String> sels = context.selections_content();
|
||||||
std::vector<String> sels = editor.selections_content();
|
|
||||||
for (auto& sel : sels)
|
for (auto& sel : sels)
|
||||||
{
|
{
|
||||||
for (auto& c : sel)
|
for (auto& c : sel)
|
||||||
|
@ -572,14 +571,14 @@ void use_selection_as_search_pattern(Context& context, int)
|
||||||
|
|
||||||
void yank(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()) +
|
context.print_status({ "yanked " + to_string(context.selections().size()) +
|
||||||
" selections", get_color("Information") });
|
" selections", get_color("Information") });
|
||||||
}
|
}
|
||||||
|
|
||||||
void cat_yank(Context& context, int)
|
void cat_yank(Context& context, int)
|
||||||
{
|
{
|
||||||
auto sels = context.editor().selections_content();
|
auto sels = context.selections_content();
|
||||||
String str;
|
String str;
|
||||||
for (auto& sel : sels)
|
for (auto& sel : sels)
|
||||||
str += sel;
|
str += sel;
|
||||||
|
@ -590,14 +589,14 @@ void cat_yank(Context& context, int)
|
||||||
|
|
||||||
void erase_selections(Context& context, int)
|
void erase_selections(Context& context, int)
|
||||||
{
|
{
|
||||||
RegisterManager::instance()['"'] = context.editor().selections_content();
|
RegisterManager::instance()['"'] = context.selections_content();
|
||||||
ScopedEdition edition(context);
|
ScopedEdition edition(context);
|
||||||
erase(context.buffer(), context.selections());
|
erase(context.buffer(), context.selections());
|
||||||
}
|
}
|
||||||
|
|
||||||
void change(Context& context, int param)
|
void change(Context& context, int param)
|
||||||
{
|
{
|
||||||
RegisterManager::instance()['"'] = context.editor().selections_content();
|
RegisterManager::instance()['"'] = context.selections_content();
|
||||||
enter_insert_mode<InsertMode::Replace>(context, param);
|
enter_insert_mode<InsertMode::Replace>(context, param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -902,8 +901,7 @@ void rotate_selections_content(Context& context, int count)
|
||||||
{
|
{
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
count = 1;
|
count = 1;
|
||||||
Editor& editor = context.editor();
|
auto strings = context.selections_content();
|
||||||
auto strings = editor.selections_content();
|
|
||||||
count = count % strings.size();
|
count = count % strings.size();
|
||||||
std::rotate(strings.begin(), strings.end()-count, strings.end());
|
std::rotate(strings.begin(), strings.end()-count, strings.end());
|
||||||
context.selections().rotate_main(count);
|
context.selections().rotate_main(count);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user