2012-01-31 20:12:06 +01:00
|
|
|
#ifndef editor_hh_INCLUDED
|
|
|
|
#define editor_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "buffer.hh"
|
|
|
|
#include "selection.hh"
|
|
|
|
#include "filter.hh"
|
|
|
|
#include "idvaluemap.hh"
|
2012-02-10 00:47:55 +01:00
|
|
|
#include "memoryview.hh"
|
2012-06-12 20:24:29 +02:00
|
|
|
#include "filter_group.hh"
|
2012-01-31 20:12:06 +01:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2012-02-10 00:47:55 +01:00
|
|
|
class Register;
|
2012-01-31 20:12:06 +01:00
|
|
|
|
|
|
|
// An Editor is a buffer mutator
|
|
|
|
//
|
|
|
|
// The Editor class provides methods to manipulate a set of selections
|
|
|
|
// and to use these selections to mutate it's buffer.
|
|
|
|
class Editor
|
|
|
|
{
|
|
|
|
public:
|
2012-02-10 00:47:55 +01:00
|
|
|
typedef std::function<SelectionAndCaptures (const Selection&)> Selector;
|
|
|
|
typedef std::function<SelectionAndCapturesList (const Selection&)> MultiSelector;
|
2012-01-31 20:12:06 +01:00
|
|
|
|
|
|
|
Editor(Buffer& buffer);
|
|
|
|
virtual ~Editor() {}
|
|
|
|
|
|
|
|
Buffer& buffer() const { return m_buffer; }
|
|
|
|
|
|
|
|
void erase();
|
2012-02-10 00:47:55 +01:00
|
|
|
|
2012-01-31 20:12:06 +01:00
|
|
|
void insert(const String& string);
|
2012-02-10 00:47:55 +01:00
|
|
|
void insert(const memoryview<String>& strings);
|
|
|
|
|
2012-01-31 20:12:06 +01:00
|
|
|
void append(const String& string);
|
2012-02-10 00:47:55 +01:00
|
|
|
void append(const memoryview<String>& strings);
|
|
|
|
|
2012-01-31 20:12:06 +01:00
|
|
|
void replace(const String& string);
|
2012-07-11 14:15:27 +02:00
|
|
|
void replace(const memoryview<String>& strings);
|
2012-01-31 20:12:06 +01:00
|
|
|
|
|
|
|
void push_selections();
|
|
|
|
void pop_selections();
|
|
|
|
|
|
|
|
void move_selections(const BufferCoord& offset, bool append = false);
|
|
|
|
void clear_selections();
|
|
|
|
void keep_selection(int index);
|
2012-05-29 13:15:43 +02:00
|
|
|
void remove_selection(int index);
|
2012-01-31 20:12:06 +01:00
|
|
|
void select(const BufferIterator& iterator);
|
|
|
|
void select(const Selector& selector, bool append = false);
|
|
|
|
void multi_select(const MultiSelector& selector);
|
|
|
|
|
|
|
|
const SelectionList& selections() const { return m_selections.back(); }
|
2012-02-10 00:47:55 +01:00
|
|
|
std::vector<String> selections_content() const;
|
2012-01-31 20:12:06 +01:00
|
|
|
|
|
|
|
bool undo();
|
|
|
|
bool redo();
|
|
|
|
|
2012-06-12 20:24:29 +02:00
|
|
|
FilterGroup& filters() { return m_filters; }
|
2012-01-31 20:12:06 +01:00
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
CandidateList complete_filterid(const String& prefix,
|
|
|
|
size_t cursor_pos = String::npos);
|
2012-01-31 20:12:06 +01:00
|
|
|
|
2012-02-08 00:41:10 +01:00
|
|
|
bool is_editing() const { return m_edition_level!= 0; }
|
2012-01-31 20:12:06 +01:00
|
|
|
|
|
|
|
private:
|
2012-02-08 00:41:10 +01:00
|
|
|
friend class scoped_edition;
|
|
|
|
void begin_edition();
|
|
|
|
void end_edition();
|
|
|
|
|
|
|
|
int m_edition_level;
|
2012-01-31 20:12:06 +01:00
|
|
|
|
|
|
|
void check_invariant() const;
|
|
|
|
|
|
|
|
friend class IncrementalInserter;
|
2012-02-08 00:41:10 +01:00
|
|
|
virtual void on_incremental_insertion_begin() {}
|
|
|
|
virtual void on_incremental_insertion_end() {}
|
2012-01-31 20:12:06 +01:00
|
|
|
|
|
|
|
Buffer& m_buffer;
|
|
|
|
std::vector<SelectionList> m_selections;
|
2012-06-12 20:24:29 +02:00
|
|
|
FilterGroup m_filters;
|
2012-01-31 20:12:06 +01:00
|
|
|
};
|
|
|
|
|
2012-02-08 00:41:10 +01:00
|
|
|
struct scoped_edition
|
|
|
|
{
|
|
|
|
scoped_edition(Editor& editor)
|
|
|
|
: m_editor(editor)
|
|
|
|
{ m_editor.begin_edition(); }
|
|
|
|
|
|
|
|
~scoped_edition()
|
|
|
|
{ m_editor.end_edition(); }
|
|
|
|
private:
|
|
|
|
Editor& m_editor;
|
|
|
|
};
|
|
|
|
|
2012-01-31 20:12:06 +01:00
|
|
|
// An IncrementalInserter manage insert mode
|
|
|
|
class IncrementalInserter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum class Mode
|
|
|
|
{
|
|
|
|
Insert,
|
|
|
|
Append,
|
|
|
|
Change,
|
|
|
|
InsertAtLineBegin,
|
|
|
|
AppendAtLineEnd,
|
|
|
|
OpenLineBelow,
|
|
|
|
OpenLineAbove
|
|
|
|
};
|
|
|
|
|
|
|
|
IncrementalInserter(Editor& editor, Mode mode = Mode::Insert);
|
|
|
|
~IncrementalInserter();
|
|
|
|
|
2012-03-08 22:23:29 +01:00
|
|
|
void insert(const String& string);
|
2012-06-29 18:35:48 +02:00
|
|
|
void insert(const memoryview<String>& strings);
|
2012-01-31 20:12:06 +01:00
|
|
|
void erase();
|
|
|
|
void move_cursors(const BufferCoord& offset);
|
|
|
|
|
2012-02-02 21:48:03 +01:00
|
|
|
Buffer& buffer() const { return m_editor.buffer(); }
|
|
|
|
|
2012-01-31 20:12:06 +01:00
|
|
|
private:
|
|
|
|
void apply(Modification&& modification) const;
|
|
|
|
|
2012-07-16 21:21:56 +02:00
|
|
|
Mode m_mode;
|
2012-01-31 20:12:06 +01:00
|
|
|
Editor& m_editor;
|
2012-02-08 00:41:10 +01:00
|
|
|
scoped_edition m_edition;
|
2012-01-31 20:12:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // editor_hh_INCLUDED
|
|
|
|
|