diff --git a/src/editor.cc b/src/editor.cc index 36931e80..9c6a97c0 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -408,15 +408,13 @@ IncrementalInserter::~IncrementalInserter() m_editor.on_incremental_insertion_end(); } -void IncrementalInserter::insert(const String& string) +void IncrementalInserter::insert(String content) { Buffer& buffer = m_editor.buffer(); for (auto& sel : m_editor.m_selections) { - BufferIterator position = sel.last(); - String content = string; - m_editor.filters()(buffer, position, content); - buffer.insert(position, content); + m_editor.filters()(buffer, sel.selection, content); + buffer.insert(sel.last(), content); } } diff --git a/src/editor.hh b/src/editor.hh index 2d6f7d24..4ee5dfc2 100644 --- a/src/editor.hh +++ b/src/editor.hh @@ -117,7 +117,7 @@ public: IncrementalInserter(Editor& editor, InsertMode mode = InsertMode::Insert); ~IncrementalInserter(); - void insert(const String& string); + void insert(String content); void insert(const memoryview& strings); void erase(); void move_cursors(const BufferCoord& offset); diff --git a/src/filter.hh b/src/filter.hh index 592bc6a6..6f54d496 100644 --- a/src/filter.hh +++ b/src/filter.hh @@ -2,6 +2,7 @@ #define filter_hh_INCLUDED #include "string.hh" +#include "selection.hh" #include namespace Kakoune @@ -14,8 +15,8 @@ class BufferIterator; // Modification in order to mutate the Buffer or the Modification // prior to it's application. -typedef std::function FilterFunc; -typedef std::pair FilterAndId; +using FilterFunc = std::function; +using FilterAndId = std::pair; } diff --git a/src/filter_group.cc b/src/filter_group.cc index ac10faee..a366abf8 100644 --- a/src/filter_group.cc +++ b/src/filter_group.cc @@ -7,10 +7,10 @@ namespace Kakoune { void FilterGroup::operator()(Buffer& buffer, - BufferIterator& position, String& content) + Selection& selection, String& content) { for (auto& filter : m_filters) - filter.second(buffer, position, content); + filter.second(buffer, selection, content); } void FilterGroup::append(FilterAndId&& filter) diff --git a/src/filter_group.hh b/src/filter_group.hh index df3cbb9f..952e157f 100644 --- a/src/filter_group.hh +++ b/src/filter_group.hh @@ -12,7 +12,7 @@ namespace Kakoune class FilterGroup { public: - void operator()(Buffer& buffer, BufferIterator& position, String& content); + void operator()(Buffer& buffer, Selection& selection, String& content); void append(FilterAndId&& filter); void remove(const String& id); diff --git a/src/filters.cc b/src/filters.cc index 8df8b597..d66bf652 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -6,11 +6,11 @@ namespace Kakoune { -void preserve_indent(Buffer& buffer, BufferIterator& position, String& content) +void preserve_indent(Buffer& buffer, Selection& selection, String& content) { if (content == "\n") { - BufferIterator line_begin = buffer.iterator_at_line_begin(position - 1); + BufferIterator line_begin = buffer.iterator_at_line_begin(selection.last() - 1); BufferIterator first_non_white = line_begin; while ((*first_non_white == '\t' or *first_non_white == ' ') and not first_non_white.is_end()) @@ -20,8 +20,9 @@ void preserve_indent(Buffer& buffer, BufferIterator& position, String& content) } } -void cleanup_whitespaces(Buffer& buffer, BufferIterator& position, String& content) +void cleanup_whitespaces(Buffer& buffer, Selection& selection, String& content) { + const BufferIterator& position = selection.last(); if (content[0] == '\n' and not position.is_begin()) { BufferIterator whitespace_start = position-1; @@ -30,19 +31,17 @@ void cleanup_whitespaces(Buffer& buffer, BufferIterator& position, String& conte --whitespace_start; ++whitespace_start; if (whitespace_start!= position) - { buffer.erase(whitespace_start, position); - position = whitespace_start; - } } } -void expand_tabulations(Buffer& buffer, BufferIterator& position, String& content) +void expand_tabulations(Buffer& buffer, Selection& selection, String& content) { const int tabstop = buffer.option_manager()["tabstop"].as_int(); if (content == "\t") { int column = 0; + const BufferIterator& position = selection.last(); for (auto line_it = buffer.iterator_at_line_begin(position); line_it != position; ++line_it) { @@ -60,7 +59,7 @@ void expand_tabulations(Buffer& buffer, BufferIterator& position, String& conten } } -template +template class SimpleFilterFactory { public: