2012-01-31 23:12:06 +04:00
|
|
|
#ifndef editor_hh_INCLUDED
|
|
|
|
#define editor_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "buffer.hh"
|
|
|
|
#include "selection.hh"
|
|
|
|
#include "filter.hh"
|
|
|
|
#include "idvaluemap.hh"
|
2012-02-10 03:47:55 +04:00
|
|
|
#include "memoryview.hh"
|
2012-06-12 22:24:29 +04:00
|
|
|
#include "filter_group.hh"
|
2012-01-31 23:12:06 +04:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2012-02-10 03:47:55 +04:00
|
|
|
class Register;
|
2012-01-31 23:12:06 +04:00
|
|
|
|
2012-09-07 16:29:29 +04:00
|
|
|
enum class SelectMode
|
|
|
|
{
|
|
|
|
Replace,
|
|
|
|
Extend,
|
|
|
|
Append,
|
|
|
|
};
|
|
|
|
|
2012-10-09 21:25:20 +04:00
|
|
|
enum class InsertMode : unsigned
|
|
|
|
{
|
|
|
|
Insert,
|
|
|
|
Append,
|
|
|
|
Replace,
|
|
|
|
InsertAtLineBegin,
|
2012-11-26 22:23:50 +04:00
|
|
|
InsertAtNextLineBegin,
|
2012-10-09 21:25:20 +04:00
|
|
|
AppendAtLineEnd,
|
|
|
|
OpenLineBelow,
|
|
|
|
OpenLineAbove
|
|
|
|
};
|
|
|
|
|
2012-01-31 23:12:06 +04: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.
|
2012-08-05 20:23:09 +04:00
|
|
|
class Editor : public SafeCountable
|
2012-01-31 23:12:06 +04:00
|
|
|
{
|
|
|
|
public:
|
2012-02-10 03:47:55 +04:00
|
|
|
typedef std::function<SelectionAndCaptures (const Selection&)> Selector;
|
|
|
|
typedef std::function<SelectionAndCapturesList (const Selection&)> MultiSelector;
|
2012-01-31 23:12:06 +04:00
|
|
|
|
|
|
|
Editor(Buffer& buffer);
|
|
|
|
virtual ~Editor() {}
|
|
|
|
|
2012-11-05 02:39:25 +04:00
|
|
|
Buffer& buffer() const { return *m_buffer; }
|
2012-01-31 23:12:06 +04:00
|
|
|
|
|
|
|
void erase();
|
2012-02-10 03:47:55 +04:00
|
|
|
|
2012-10-09 21:25:20 +04:00
|
|
|
void insert(const String& string,
|
|
|
|
InsertMode mode = InsertMode::Insert);
|
|
|
|
void insert(const memoryview<String>& strings,
|
|
|
|
InsertMode mode = InsertMode::Insert);
|
2012-01-31 23:12:06 +04:00
|
|
|
|
2012-10-02 16:10:00 +04:00
|
|
|
void move_selections(LineCount move,
|
|
|
|
SelectMode mode = SelectMode::Replace);
|
|
|
|
void move_selections(CharCount move,
|
2012-09-07 16:29:29 +04:00
|
|
|
SelectMode mode = SelectMode::Replace);
|
2012-01-31 23:12:06 +04:00
|
|
|
void clear_selections();
|
2012-11-19 22:03:56 +04:00
|
|
|
void flip_selections();
|
2012-01-31 23:12:06 +04:00
|
|
|
void keep_selection(int index);
|
2012-05-29 15:15:43 +04:00
|
|
|
void remove_selection(int index);
|
2012-01-31 23:12:06 +04:00
|
|
|
void select(const BufferIterator& iterator);
|
2012-09-07 16:29:29 +04:00
|
|
|
void select(const Selector& selector,
|
|
|
|
SelectMode mode = SelectMode::Replace);
|
2012-09-26 22:33:47 +04:00
|
|
|
void select(SelectionAndCapturesList selections);
|
2012-01-31 23:12:06 +04:00
|
|
|
void multi_select(const MultiSelector& selector);
|
|
|
|
|
2012-09-26 22:33:47 +04:00
|
|
|
const SelectionAndCapturesList& selections() const { return m_selections; }
|
2012-02-10 03:47:55 +04:00
|
|
|
std::vector<String> selections_content() const;
|
2012-01-31 23:12:06 +04:00
|
|
|
|
|
|
|
bool undo();
|
|
|
|
bool redo();
|
|
|
|
|
2012-06-12 22:24:29 +04:00
|
|
|
FilterGroup& filters() { return m_filters; }
|
2012-01-31 23:12:06 +04:00
|
|
|
|
2012-04-14 05:17:09 +04:00
|
|
|
CandidateList complete_filterid(const String& prefix,
|
|
|
|
size_t cursor_pos = String::npos);
|
2012-01-31 23:12:06 +04:00
|
|
|
|
2012-02-08 03:41:10 +04:00
|
|
|
bool is_editing() const { return m_edition_level!= 0; }
|
2012-01-31 23:12:06 +04:00
|
|
|
|
|
|
|
private:
|
2012-02-08 03:41:10 +04:00
|
|
|
friend class scoped_edition;
|
|
|
|
void begin_edition();
|
|
|
|
void end_edition();
|
|
|
|
|
|
|
|
int m_edition_level;
|
2012-01-31 23:12:06 +04:00
|
|
|
|
|
|
|
void check_invariant() const;
|
|
|
|
|
|
|
|
friend class IncrementalInserter;
|
2012-02-08 03:41:10 +04:00
|
|
|
virtual void on_incremental_insertion_begin() {}
|
|
|
|
virtual void on_incremental_insertion_end() {}
|
2012-01-31 23:12:06 +04:00
|
|
|
|
2012-11-05 02:39:25 +04:00
|
|
|
safe_ptr<Buffer> m_buffer;
|
2012-09-26 22:33:47 +04:00
|
|
|
SelectionAndCapturesList m_selections;
|
2012-09-24 22:47:06 +04:00
|
|
|
FilterGroup m_filters;
|
2012-01-31 23:12:06 +04:00
|
|
|
};
|
|
|
|
|
2012-02-08 03:41:10 +04: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 23:12:06 +04:00
|
|
|
// An IncrementalInserter manage insert mode
|
|
|
|
class IncrementalInserter
|
|
|
|
{
|
|
|
|
public:
|
2012-09-26 16:22:24 +04:00
|
|
|
IncrementalInserter(Editor& editor, InsertMode mode = InsertMode::Insert);
|
2012-01-31 23:12:06 +04:00
|
|
|
~IncrementalInserter();
|
|
|
|
|
2012-11-19 16:40:23 +04:00
|
|
|
void insert(String content);
|
2012-06-29 20:35:48 +04:00
|
|
|
void insert(const memoryview<String>& strings);
|
2012-01-31 23:12:06 +04:00
|
|
|
void erase();
|
2012-11-26 22:38:07 +04:00
|
|
|
void move_cursors(CharCount move);
|
|
|
|
void move_cursors(LineCount move);
|
2012-01-31 23:12:06 +04:00
|
|
|
|
2012-02-03 00:48:03 +04:00
|
|
|
Buffer& buffer() const { return m_editor.buffer(); }
|
2012-10-01 16:23:04 +04:00
|
|
|
Editor& editor() const { return m_editor; }
|
2012-02-03 00:48:03 +04:00
|
|
|
|
2012-01-31 23:12:06 +04:00
|
|
|
private:
|
2012-09-26 16:22:24 +04:00
|
|
|
InsertMode m_mode;
|
|
|
|
Editor& m_editor;
|
2012-02-08 03:41:10 +04:00
|
|
|
scoped_edition m_edition;
|
2012-01-31 23:12:06 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // editor_hh_INCLUDED
|
|
|
|
|