Skip to content

Commit ddc4029

Browse files
committed
UI: display markers
1 parent 2ff3bc4 commit ddc4029

File tree

5 files changed

+56
-8
lines changed

5 files changed

+56
-8
lines changed

src/platform/sdl/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void setupAppPath(const char *path) {
219219
char cwd[OS_PATHNAME_SIZE + 1];
220220
cwd[0] = '\0';
221221
getcwd(cwd, sizeof(cwd) - 1);
222-
strcat(g_appPath, cwd);
222+
strcpy(g_appPath, cwd);
223223
strcat(g_appPath, "/");
224224
strcat(g_appPath, path);
225225
}

src/platform/sdl/runtime.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ void Runtime::debugStart(TextEditInput *editWidget, const char *file) {
177177
net_print(g_debugee, "l\n");
178178
size = net_input(g_debugee, buf, sizeof(buf), "\n");
179179
if (size > 0) {
180+
int *marker = editWidget->getMarkers();
181+
for (int i = 0; i < MAX_MARKERS; i++) {
182+
if (marker[i] != -1) {
183+
net_printf(g_debugee, "b %d\n", marker[i]);
184+
}
185+
}
180186
editWidget->gotoLine(buf);
181187
appLog("Debug session ready");
182188
}

src/ui/editor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ void System::editSource(strlib::String &loadPath) {
9494
switch (event.key) {
9595
case SB_KEY_F(2):
9696
case SB_KEY_F(3):
97-
case SB_KEY_F(4):
9897
case SB_KEY_F(8):
9998
case SB_KEY_F(10):
10099
case SB_KEY_F(11):

src/ui/textedit.cpp

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ int g_themeId = 0;
3131
const int theme1[] = {
3232
0xc8cedb, 0xa7aebc, 0x484f5f, 0xa7aebc, 0xa7aebc, 0x00bb00,
3333
0x272b33, 0x3d4350, 0x2b3039, 0x3875ed, 0x373b88, 0x2b313a,
34-
0x0083f8, 0xff9d00, 0x31ccac, 0xc679dd
34+
0x0083f8, 0xff9d00, 0x31ccac, 0xc679dd, 0x0083f8
3535
};
3636

3737
const int theme2[] = {
3838
0xc8cedb, 0x002b36, 0x3d4350, 0xa7aebc, 0xa7aebc, 0x00bb00,
3939
0x002b36, 0x657b83, 0x073642, 0x9f7d18, 0x2b313a, 0x073642,
40-
0x0083f8, 0xff9d00, 0x31ccac, 0xc679dd
40+
0x0083f8, 0xff9d00, 0x31ccac, 0xc679dd, 0x0083f8
4141
};
4242

4343
const int theme3[] = {
4444
0xc8cedb, 0xd7decc, 0x484f5f, 0xa7aebc, 0xa7aebc, 0x00bb00,
4545
0x001b33, 0x0088ff, 0x000d1a, 0x0051b1, 0x373b88, 0x022444,
46-
0x0083f8, 0xff9d00, 0x31ccac, 0xc679dd
46+
0x0083f8, 0xff9d00, 0x31ccac, 0xc679dd, 0x0083f8
4747
};
4848

4949
const int theme4[] = {
5050
0xc8cedb, 0xa7aebc, 0x484f5f, 0xa7aebc, 0xa7aebc, 0x00bb00,
5151
0x2e3436, 0x888a85, 0x000000, 0x4d483b, 0x000000, 0x2b313a,
52-
0x0083f8, 0xff9d00, 0x31ccac, 0xc679dd
52+
0x0083f8, 0xff9d00, 0x31ccac, 0xc679dd, 0x0083f8
5353
};
5454

5555
const int* themes[] = {
@@ -81,6 +81,7 @@ const char *helpText =
8181
"SHIFT-<arrow> select\n"
8282
"TAB indent line\n"
8383
"F1,A-h keyword help\n"
84+
"F4 toggle marker\n"
8485
"F5 debug\n"
8586
"F9, C-r run\n";
8687

@@ -119,7 +120,8 @@ EditTheme::EditTheme(int fg, int bg) :
119120
_syntax_text(fg),
120121
_syntax_command(fg),
121122
_syntax_statement(fg),
122-
_syntax_digit(fg) {
123+
_syntax_digit(fg),
124+
_row_marker(fg) {
123125
}
124126

125127
void EditTheme::selectTheme(const int theme[]) {
@@ -139,6 +141,7 @@ void EditTheme::selectTheme(const int theme[]) {
139141
_syntax_command = theme[13];
140142
_syntax_statement = theme[14];
141143
_syntax_digit = theme[15];
144+
_row_marker = theme[16];
142145
}
143146

144147
//
@@ -255,6 +258,7 @@ TextEditInput::TextEditInput(const char *text, int chW, int chH,
255258
_matchingBrace(-1),
256259
_dirty(false) {
257260
stb_textedit_initialize_state(&_state, false);
261+
memset(_lineMarker, -1, sizeof(_lineMarker));
258262
}
259263

260264
TextEditInput::~TextEditInput() {
@@ -535,6 +539,9 @@ bool TextEditInput::edit(int key, int screenWidth, int charWidth) {
535539
case SB_KEY_TAB:
536540
editTab();
537541
break;
542+
case SB_KEY_F(4):
543+
toggleMarker();
544+
break;
538545
case SB_KEY_SHIFT(SB_KEY_PGUP):
539546
case SB_KEY_PGUP:
540547
pageNavigate(false, key == (int)SB_KEY_SHIFT(SB_KEY_PGUP));
@@ -799,7 +806,15 @@ void TextEditInput::cycleTheme() {
799806

800807
void TextEditInput::drawLineNumber(int x, int y, int row, bool selected) {
801808
if (_marginWidth > 0) {
802-
if (selected) {
809+
bool markerRow = false;
810+
for (int i = 0; i < MAX_MARKERS && !markerRow; i++) {
811+
if (row == _lineMarker[i]) {
812+
markerRow = true;
813+
}
814+
}
815+
if (markerRow) {
816+
maSetColor(_theme->_row_marker);
817+
} else if (selected) {
803818
maSetColor(_theme->_number_selection_background);
804819
maFillRect(x, y, _marginWidth, _charHeight);
805820
maSetColor(_theme->_number_selection_color);
@@ -1257,6 +1272,29 @@ void TextEditInput::setColor(SyntaxState &state) {
12571272
}
12581273
}
12591274

1275+
void TextEditInput::toggleMarker() {
1276+
_cursorRow = getCursorRow();
1277+
bool found = false;
1278+
for (int i = 0; i < MAX_MARKERS && !found; i++) {
1279+
if (_cursorRow == _lineMarker[i]) {
1280+
_lineMarker[i] = -1;
1281+
found = true;
1282+
}
1283+
}
1284+
if (!found) {
1285+
for (int i = 0; i < MAX_MARKERS && !found; i++) {
1286+
if (_lineMarker[i] == -1) {
1287+
_lineMarker[i] = _cursorRow;
1288+
found = true;
1289+
break;
1290+
}
1291+
}
1292+
}
1293+
if (!found) {
1294+
_lineMarker[0] = _cursorRow;
1295+
}
1296+
}
1297+
12601298
void TextEditInput::updateScroll() {
12611299
int pageRows = _height / _charHeight;
12621300
if (_cursorRow + 1 < pageRows) {

src/ui/textedit.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define STB_TEXTEDIT_CHARTYPE char
1313
#define STB_TEXTEDIT_UNDOCHARCOUNT 2000
1414
#define MARGIN_CHARS 4
15+
#define MAX_MARKERS 10
1516

1617
#include <config.h>
1718
#include <stdlib.h>
@@ -45,6 +46,7 @@ struct EditTheme {
4546
int _syntax_command;
4647
int _syntax_statement;
4748
int _syntax_digit;
49+
int _row_marker;
4850
};
4951

5052
struct EditBuffer {
@@ -77,6 +79,7 @@ struct TextEditInput : public FormEditInput {
7779
int getCursorPos() const { return _state.cursor; }
7880
const char *getText() const { return _buf._buffer; }
7981
int getTextLength() const { return _buf._len; }
82+
int *getMarkers() { return _lineMarker; }
8083
void gotoLine(const char *buffer);
8184
void reload(const char *text);
8285
bool save(const char *filePath);
@@ -134,6 +137,7 @@ struct TextEditInput : public FormEditInput {
134137
void pageNavigate(bool pageDown, bool shift);
135138
void removeTrailingSpaces();
136139
void setColor(SyntaxState &state);
140+
void toggleMarker();
137141
void updateScroll();
138142
int wordStart();
139143

@@ -147,6 +151,7 @@ struct TextEditInput : public FormEditInput {
147151
int _cursorRow;
148152
int _indentLevel;
149153
int _matchingBrace;
154+
int _lineMarker[MAX_MARKERS];
150155
bool _dirty;
151156
};
152157

0 commit comments

Comments
 (0)