forked from mika314/texteditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_text_buffer.hpp
51 lines (49 loc) · 1.5 KB
/
base_text_buffer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once
#include "coord.hpp"
#include "cpp_highlighter.hpp"
#include "undo_stack.hpp"
#include <string>
#include <vector>
class Screen;
class BaseTextBuffer
{
public:
BaseTextBuffer();
virtual ~BaseTextBuffer();
const std::wstring &operator[](int line) const;
std::wstring &operator[](int line);
int size() const;
void undo(Coord &cursor);
void redo(Coord &cursor);
bool canUndo() const;
bool canRedo() const;
bool isModified() const;
void clearModified();
void render(Screen *) const;
void insert(Coord &cursor, std::wstring);
void del(Coord &cursor, int = 1);
void backspace(Coord &cursor, int = 1);
bool isReadOnly() const;
void setReadOnly(bool);
std::wstring name() const;
void setName(std::wstring);
Coord cursor() const;
void setCursor(Coord);
protected:
std::vector<std::wstring> buffer_;
bool isReadOnly_;
UndoStack undoStack_;
std::wstring name_;
Coord cursor_;
CppHighlighter *highlighter_;
virtual std::wstring preInsert(Coord &cursor, std::wstring);
virtual void postInsert(Coord &cursor, std::wstring);
virtual int preDel(Coord &cursor, int = 1);
virtual void postDel(Coord &cursor, int = 1);
virtual int preBackspace(Coord &cursor, int = 1);
virtual void postBackspace(Coord &cursor, int = 1);
private:
void internalInsert(Coord &cursor, std::wstring);
std::wstring internalDelete(const Coord cursor, int = 1);
std::wstring internalBackspace(Coord &cursor, int = 1);
};