Pass the selection instead of only point of insertion to filters
This commit is contained in:
parent
fd50046f3a
commit
45bd3dbe5a
|
@ -408,15 +408,13 @@ IncrementalInserter::~IncrementalInserter()
|
||||||
m_editor.on_incremental_insertion_end();
|
m_editor.on_incremental_insertion_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IncrementalInserter::insert(const String& string)
|
void IncrementalInserter::insert(String content)
|
||||||
{
|
{
|
||||||
Buffer& buffer = m_editor.buffer();
|
Buffer& buffer = m_editor.buffer();
|
||||||
for (auto& sel : m_editor.m_selections)
|
for (auto& sel : m_editor.m_selections)
|
||||||
{
|
{
|
||||||
BufferIterator position = sel.last();
|
m_editor.filters()(buffer, sel.selection, content);
|
||||||
String content = string;
|
buffer.insert(sel.last(), content);
|
||||||
m_editor.filters()(buffer, position, content);
|
|
||||||
buffer.insert(position, content);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ public:
|
||||||
IncrementalInserter(Editor& editor, InsertMode mode = InsertMode::Insert);
|
IncrementalInserter(Editor& editor, InsertMode mode = InsertMode::Insert);
|
||||||
~IncrementalInserter();
|
~IncrementalInserter();
|
||||||
|
|
||||||
void insert(const String& string);
|
void insert(String content);
|
||||||
void insert(const memoryview<String>& strings);
|
void insert(const memoryview<String>& strings);
|
||||||
void erase();
|
void erase();
|
||||||
void move_cursors(const BufferCoord& offset);
|
void move_cursors(const BufferCoord& offset);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define filter_hh_INCLUDED
|
#define filter_hh_INCLUDED
|
||||||
|
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
|
#include "selection.hh"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
|
@ -14,8 +15,8 @@ class BufferIterator;
|
||||||
// Modification in order to mutate the Buffer or the Modification
|
// Modification in order to mutate the Buffer or the Modification
|
||||||
// prior to it's application.
|
// prior to it's application.
|
||||||
|
|
||||||
typedef std::function<void (Buffer& buffer, BufferIterator& position, String& content)> FilterFunc;
|
using FilterFunc = std::function<void (Buffer& buffer, Selection& selection, String& content)>;
|
||||||
typedef std::pair<String, FilterFunc> FilterAndId;
|
using FilterAndId = std::pair<String, FilterFunc>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,10 @@ namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
void FilterGroup::operator()(Buffer& buffer,
|
void FilterGroup::operator()(Buffer& buffer,
|
||||||
BufferIterator& position, String& content)
|
Selection& selection, String& content)
|
||||||
{
|
{
|
||||||
for (auto& filter : m_filters)
|
for (auto& filter : m_filters)
|
||||||
filter.second(buffer, position, content);
|
filter.second(buffer, selection, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilterGroup::append(FilterAndId&& filter)
|
void FilterGroup::append(FilterAndId&& filter)
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace Kakoune
|
||||||
class FilterGroup
|
class FilterGroup
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void operator()(Buffer& buffer, BufferIterator& position, String& content);
|
void operator()(Buffer& buffer, Selection& selection, String& content);
|
||||||
|
|
||||||
void append(FilterAndId&& filter);
|
void append(FilterAndId&& filter);
|
||||||
void remove(const String& id);
|
void remove(const String& id);
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
void preserve_indent(Buffer& buffer, BufferIterator& position, String& content)
|
void preserve_indent(Buffer& buffer, Selection& selection, String& content)
|
||||||
{
|
{
|
||||||
if (content == "\n")
|
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;
|
BufferIterator first_non_white = line_begin;
|
||||||
while ((*first_non_white == '\t' or *first_non_white == ' ') and
|
while ((*first_non_white == '\t' or *first_non_white == ' ') and
|
||||||
not first_non_white.is_end())
|
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())
|
if (content[0] == '\n' and not position.is_begin())
|
||||||
{
|
{
|
||||||
BufferIterator whitespace_start = position-1;
|
BufferIterator whitespace_start = position-1;
|
||||||
|
@ -30,19 +31,17 @@ void cleanup_whitespaces(Buffer& buffer, BufferIterator& position, String& conte
|
||||||
--whitespace_start;
|
--whitespace_start;
|
||||||
++whitespace_start;
|
++whitespace_start;
|
||||||
if (whitespace_start!= position)
|
if (whitespace_start!= position)
|
||||||
{
|
|
||||||
buffer.erase(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();
|
const int tabstop = buffer.option_manager()["tabstop"].as_int();
|
||||||
if (content == "\t")
|
if (content == "\t")
|
||||||
{
|
{
|
||||||
int column = 0;
|
int column = 0;
|
||||||
|
const BufferIterator& position = selection.last();
|
||||||
for (auto line_it = buffer.iterator_at_line_begin(position);
|
for (auto line_it = buffer.iterator_at_line_begin(position);
|
||||||
line_it != position; ++line_it)
|
line_it != position; ++line_it)
|
||||||
{
|
{
|
||||||
|
@ -60,7 +59,7 @@ void expand_tabulations(Buffer& buffer, BufferIterator& position, String& conten
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<void (*filter_func)(Buffer&, BufferIterator&, String&)>
|
template<void (*filter_func)(Buffer&, Selection&, String&)>
|
||||||
class SimpleFilterFactory
|
class SimpleFilterFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user