forked from SeraphYuki/zimedit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_editor.h
More file actions
executable file
·197 lines (161 loc) · 5.48 KB
/
text_editor.h
File metadata and controls
executable file
·197 lines (161 loc) · 5.48 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#ifndef TEXT_EDITOR_DEF
#define TEXT_EDITOR_DEF
#include <sys/types.h>
#ifdef WINDOWS_COMPILE
#include <windows.h>
#endif
#include "types.h"
#include "config.h"
#ifndef SDL_COMPILE
#ifdef LINUX_COMPILE
#include "x11.h"
#endif
#else
#include "graphics.h"
#endif
#include "file_browser.h"
#define THOTH_CTRL_KEY (unsigned int)0x100
#define THOTH_ALT_KEY (unsigned int)0x200
#define THOTH_SHIFT_KEY (unsigned int)0x400
#define THOTH_ARROW_UP (unsigned int)0x800
#define THOTH_ARROW_DOWN (unsigned int)0x1000
#define THOTH_ARROW_LEFT (unsigned int)0x2000
#define THOTH_ARROW_RIGHT (unsigned int)0x4000
#define THOTH_ENTER_KEY (unsigned int)0x8000
// #include "window.h"
// #include "text.h"
// // { "keys": ["ctrl+h"], "command": "move", "args": {"by": "characters", "forward": false} },
// // { "keys": ["ctrl+l"], "command": "move", "args": {"by": "characters", "forward": true} },
// // { "keys": ["ctrl+j"], "command": "move", "args": {"by": "lines", "forward": false} },
// // { "keys": ["ctrl+k"], "command": "move", "args": {"by": "lines", "forward": true} },
// // { "keys": ["ctrl+alt+h"], "command": "move", "args": {"by": "words", "forward": false} },
// // { "keys": ["ctrl+alt+l"], "command": "move", "args": {"by": "word_ends", "forward": true} },
// // { "keys": ["ctrl+shift+l"], "command": "expand_selection", "args": {"to": "line"} },
// // // { "keys": ["ctrl+shift+m"], "command": "expand_selection", "args": {"to": "brackets"} },
// // // { "keys": ["ctrl+m"], "command": "move_to", "args": {"to": "brackets"} },
// // { "keys": ["shift+alt+ctrl+h"], "command": "move", "args": {"extend": true, "by": "words", "forward": false} },
// // { "keys": ["shift+alt+ctrl+l"], "command": "move", "args": {"extend": true, "by": "word_ends", "forward": true} },
enum {
THOTH_LOGMODE_NUM = 1,
THOTH_LOGMODE_TEXT,
THOTH_LOGMODE_TEXT_INSENSITIVE,
THOTH_LOGMODE_SAVE,
THOTH_LOGMODE_OPEN,
THOTH_LOGMODE_HELP,
THOTH_LOGMODE_SWITCH_FILE,
THOTH_LOGMODE_FILEBROWSER,
THOTH_LOGMODE_MODES_INPUTLESS,
THOTH_LOGMODE_ALERT,
THOTH_LOGMODE_CONSOLE,
THOTH_LOGMODE_IMAGE,
};
typedef struct {
int startCursorPos;
int len;
int dir;
} Thoth_EditorSelection;
typedef struct Thoth_Editor Thoth_Editor;
typedef struct Thoth_EditorCmd Thoth_EditorCmd;
typedef struct Thoth_EditorCur Thoth_EditorCur;
struct Thoth_EditorCmd {
unsigned int keyBinding[8];
char *keys;
int num;
unsigned char scroll;
Thoth_EditorCur *savedCursors;
int nSavedCursors;
Thoth_EditorCur *hiddenCursors;
int nHiddenCursors;
void (*Execute)(Thoth_Editor *, Thoth_EditorCmd *c);
void (*Undo)(Thoth_Editor *, Thoth_EditorCmd *s);
};
struct Thoth_EditorCur {
Thoth_EditorSelection selection;
//no longer used, now clipboard is from system, lines seperated by \n
int hiddenIndex;
char *clipboard;
int sClipboard;
char *savedText;
int addedLen;
int pos;
};
#define THOTH_MAX_AUTO_COMPLETE_STRLEN 35
#define THOTH_MAX_AUTO_COMPLETE 20
typedef struct {
int offset;
int len;
} Thoth_AutoCompleteOffset;
typedef struct {
char *text;
int scroll;
int unsaved;
int cursorPos;
int historyPos;
Thoth_EditorCmd **history;
int sHistory;
#ifndef SDL_COMPILE
#ifdef LINUX_COMPILE
Image img;
#endif
#endif
int textLen;
char name[MAX_FILENAME];
char path[MAX_PATH_LEN];
} Thoth_EditorFile;
struct Thoth_Editor {
Thoth_Config *cfg;
Thoth_EditorCmd **commands;
Thoth_AutoCompleteOffset autoComplete[THOTH_MAX_AUTO_COMPLETE];
Thoth_EditorCur *cursors;
Thoth_EditorFile **files;
Thoth_EditorFile *file;
Thoth_FileBrowser fileBrowser;
Thoth_EditorCmd **lastCmd;
int linesY;
int colsX;
int nCommands;
int selectNextWordTerminator; // "select" not get it in the phrase selecting
int autoCompleteSearchLen;
int autoCompleteLen;
int autoCompleteIndex;
int logging;
int logIndex;
char *loggingText;
int nFiles;
int mouseSelection;
int nCursors;
int logX;
int logY;
int quit;
int ttyPid;
int ttyMaster;
int ttySlave;
int _stdout;
int _stderr;
char *clipboard;
#ifdef SDL_COMPILE
Thoth_Graphics *graphics;
#endif
};
void Thoth_Editor_LoadFile(Thoth_Editor *t, char *path);
#ifdef SDL_COMPILE
void Thoth_Editor_Draw(Thoth_Editor *t, Thoth_Graphics *hdcMem);
#elif
#ifdef WINDOWS_COMPILE
void Thoth_Editor_Draw(Thoth_Editor *t,HWND hwnd);
#elif LINUX_COMPILE
void Thoth_Editor_Draw(Thoth_Editor *t);
#endif
#endif
void Thoth_Editor_Event(Thoth_Editor *t,unsigned int key);
int Thoth_Editor_Destroy(Thoth_Editor *t);
void Thoth_Editor_SetCursorPos(Thoth_Editor *t, int x, int y);
int Thoth_Editor_SetCursorPosSelection(Thoth_Editor *t, int x, int y);
int Thoth_Editor_Scroll(Thoth_Editor *t, int y);
void Thoth_Editor_SetCursorPosDoubleClick(Thoth_Editor *t, int x, int y);
#endif
#ifdef SDL_COMPILE
void Thoth_Editor_Init(Thoth_Editor *t, Thoth_Graphics *graphics, Thoth_Config *cfg);
#else
void Thoth_Editor_Init(Thoth_Editor *t, Thoth_Config *cfg);
#endif