Skip to content

Commit ec6471e

Browse files
committed
UI: use edit marker for bookmarks
1 parent da24294 commit ec6471e

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

src/ui/textedit.cpp

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ const char *helpText =
6969
"C-y redo\n"
7070
"C-f find, find-next\n"
7171
"C-n find, replace\n"
72+
"C-t toggle marker\n"
73+
"C-g goto marker\n"
7274
"C-l outline\n"
7375
"C-o show output\n"
7476
"C-SPC auto-complete\n"
@@ -81,7 +83,6 @@ const char *helpText =
8183
"SHIFT-<arrow> select\n"
8284
"TAB indent line\n"
8385
"F1,A-h keyword help\n"
84-
"F4 toggle marker\n"
8586
"F5 debug\n"
8687
"F9, C-r run\n";
8788

@@ -100,6 +101,12 @@ inline bool is_comment(const char *str, int offs) {
100101
|| match(str + offs, "RrEeMm ", 3));
101102
}
102103

104+
int compareIntegers(const void *p1, const void *p2) {
105+
int i1 = *((int *)p1);
106+
int i2 = *((int *)p2);
107+
return i1 < i2 ? -1 : i1 == i2 ? 0 : 1;
108+
}
109+
103110
//
104111
// EditTheme
105112
//
@@ -254,6 +261,7 @@ TextEditInput::TextEditInput(const char *text, int chW, int chH,
254261
_marginWidth(0),
255262
_scroll(0),
256263
_cursorRow(0),
264+
_cursorLine(0),
257265
_indentLevel(INDENT_LEVEL),
258266
_matchingBrace(-1),
259267
_dirty(false) {
@@ -333,6 +341,8 @@ void TextEditInput::draw(int x, int y, int w, int h, int chw) {
333341
cursorX = x + ((_state.cursor - i) * chw);
334342
cursorY = y + baseY;
335343
}
344+
// the logical line, will be < _cursorRow when there are wrapped lines
345+
_cursorLine = line;
336346

337347
if (_marginWidth > 0 && selectStart == selectEnd) {
338348
maSetColor(_theme->_row_cursor);
@@ -539,9 +549,12 @@ bool TextEditInput::edit(int key, int screenWidth, int charWidth) {
539549
case SB_KEY_TAB:
540550
editTab();
541551
break;
542-
case SB_KEY_F(4):
552+
case SB_KEY_CTRL('t'):
543553
toggleMarker();
544554
break;
555+
case SB_KEY_CTRL('g'):
556+
gotoNextMarker();
557+
break;
545558
case SB_KEY_SHIFT(SB_KEY_PGUP):
546559
case SB_KEY_PGUP:
547560
pageNavigate(false, key == (int)SB_KEY_SHIFT(SB_KEY_PGUP));
@@ -1132,6 +1145,30 @@ bool TextEditInput::replaceNext(const char *buffer) {
11321145
return changed;
11331146
}
11341147

1148+
void TextEditInput::gotoNextMarker() {
1149+
int next = 0;
1150+
int first = -1;
1151+
for (int i = 0; i < MAX_MARKERS; i++) {
1152+
if (_lineMarker[i] != -1) {
1153+
if (first == -1) {
1154+
first = i;
1155+
}
1156+
if (_lineMarker[i] == _cursorLine) {
1157+
next = i + 1 == MAX_MARKERS ? first : i + 1;
1158+
break;
1159+
}
1160+
}
1161+
}
1162+
if (first != -1) {
1163+
if (_lineMarker[next] == -1) {
1164+
next = first;
1165+
}
1166+
if (_lineMarker[next] != -1) {
1167+
setCursorRow(_lineMarker[next] - 1);
1168+
}
1169+
}
1170+
}
1171+
11351172
void TextEditInput::lineNavigate(bool lineDown) {
11361173
if (lineDown) {
11371174
for (int i = _state.cursor; i < _buf._len; i++) {
@@ -1273,26 +1310,26 @@ void TextEditInput::setColor(SyntaxState &state) {
12731310
}
12741311

12751312
void TextEditInput::toggleMarker() {
1276-
_cursorRow = getCursorRow();
12771313
bool found = false;
12781314
for (int i = 0; i < MAX_MARKERS && !found; i++) {
1279-
if (_cursorRow == _lineMarker[i]) {
1315+
if (_cursorLine == _lineMarker[i]) {
12801316
_lineMarker[i] = -1;
12811317
found = true;
12821318
}
12831319
}
12841320
if (!found) {
12851321
for (int i = 0; i < MAX_MARKERS && !found; i++) {
12861322
if (_lineMarker[i] == -1) {
1287-
_lineMarker[i] = _cursorRow;
1323+
_lineMarker[i] = _cursorLine;
12881324
found = true;
12891325
break;
12901326
}
12911327
}
12921328
}
12931329
if (!found) {
1294-
_lineMarker[0] = _cursorRow;
1330+
_lineMarker[0] = _cursorLine;
12951331
}
1332+
qsort(_lineMarker, MAX_MARKERS, sizeof(int), compareIntegers);
12961333
}
12971334

12981335
void TextEditInput::updateScroll() {

src/ui/textedit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ struct TextEditInput : public FormEditInput {
127127
int getIndent(char *spaces, int len, int pos);
128128
int getLineChars(StbTexteditRow *row, int pos);
129129
char *getSelection(int *start, int *end);
130+
void gotoNextMarker();
130131
void lineNavigate(bool lineDown);
131132
char *lineText(int pos);
132133
int lineEnd(int pos) { return linePos(pos, true); }
@@ -149,6 +150,7 @@ struct TextEditInput : public FormEditInput {
149150
int _marginWidth;
150151
int _scroll;
151152
int _cursorRow;
153+
int _cursorLine;
152154
int _indentLevel;
153155
int _matchingBrace;
154156
int _lineMarker[MAX_MARKERS];

0 commit comments

Comments
 (0)