1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-26 13:02:01 +03:00

Move Editor::selections_content to Context

This commit is contained in:
Maxime Coste 2013-12-15 20:37:07 +00:00
parent ad0682ec75
commit ea95632709
6 changed files with 17 additions and 19 deletions

View File

@ -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;

View File

@ -51,6 +51,7 @@ public:
SelectionList& selections();
const SelectionList& selections() const;
std::vector<String> selections_content() const;
void change_editor(Editor& editor);

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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())}}; } },
};

View File

@ -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);