diff options
| -rw-r--r-- | editor.c | 2 | ||||
| -rw-r--r-- | text.c | 8 | ||||
| -rw-r--r-- | text.h | 4 | ||||
| -rw-r--r-- | vis.c | 12 | ||||
| -rw-r--r-- | window.c | 14 |
5 files changed, 21 insertions, 19 deletions
@@ -493,7 +493,7 @@ static void editor_prompt_update(Prompt *prompt) { static void editor_prompt_clear(Prompt *prompt) { Text *text = prompt->win->text; - while (text_undo(text) != (size_t)-1); + while (text_undo(text) != EPOS); window_cursor_to(prompt->win->win, 0); } @@ -1087,8 +1087,8 @@ int text_search_range_forward(Text *txt, size_t pos, size_t len, Regex *r, size_ int ret = regexec(&r->regex, buf, nmatch, match, eflags); if (!ret) { for (size_t i = 0; i < nmatch; i++) { - pmatch[i].start = match[i].rm_so == -1 ? (size_t)-1 : pos + match[i].rm_so; - pmatch[i].end = match[i].rm_eo == -1 ? (size_t)-1 : pos + match[i].rm_eo; + pmatch[i].start = match[i].rm_so == -1 ? EPOS : pos + match[i].rm_so; + pmatch[i].end = match[i].rm_eo == -1 ? EPOS : pos + match[i].rm_eo; } } free(buf); @@ -1107,8 +1107,8 @@ int text_search_range_backward(Text *txt, size_t pos, size_t len, Regex *r, size while (!regexec(&r->regex, cur, nmatch, match, eflags)) { ret = 0; for (size_t i = 0; i < nmatch; i++) { - pmatch[i].start = match[i].rm_so == -1 ? (size_t)-1 : pos + (size_t)(cur - buf) + match[i].rm_so; - pmatch[i].end = match[i].rm_eo == -1 ? (size_t)-1 : pos + (size_t)(cur - buf) + match[i].rm_eo; + pmatch[i].start = match[i].rm_so == -1 ? EPOS : pos + (size_t)(cur - buf) + match[i].rm_so; + pmatch[i].end = match[i].rm_eo == -1 ? EPOS : pos + (size_t)(cur - buf) + match[i].rm_eo; } cur += match[0].rm_eo; } @@ -4,6 +4,8 @@ #include <stdbool.h> #include <stddef.h> +#define EPOS ((size_t)-1) /* invalid position */ + typedef size_t Filepos; typedef struct { @@ -36,7 +38,7 @@ bool text_insert_raw(Text*, size_t pos, const char *data, size_t len); bool text_delete(Text*, size_t pos, size_t len); void text_snapshot(Text*); /* undo/redos to the last snapshoted state. returns the position where - * the change occured or (size_t)-1 if nothing could be undo/redo. */ + * the change occured or EPOS if nothing could be undo/redo. */ size_t text_undo(Text*); size_t text_redo(Text*); @@ -621,7 +621,7 @@ static void mark_line(const Arg *arg) { static void undo(const Arg *arg) { size_t pos = text_undo(vis->win->text); - if (pos != (size_t)-1) { + if (pos != EPOS) { window_cursor_to(vis->win->win, pos); /* redraw all windows in case some display the same file */ editor_draw(vis); @@ -630,7 +630,7 @@ static void undo(const Arg *arg) { static void redo(const Arg *arg) { size_t pos = text_redo(vis->win->text); - if (pos != (size_t)-1) { + if (pos != EPOS) { window_cursor_to(vis->win->win, pos); /* redraw all windows in case some display the same file */ editor_draw(vis); @@ -804,11 +804,11 @@ static void action_do(Action *a) { pos = a->movement->win(win); else pos = a->movement->cmd(&a->arg); - if (pos == (size_t)-1) + if (pos == EPOS) break; } - if (pos == (size_t)-1) { + if (pos == EPOS) { c.range.start = start; c.range.end = start; } else { @@ -832,7 +832,7 @@ static void action_do(Action *a) { for (int i = 0; i < a->count; i++) { r = a->textobj->range(txt, pos); // TODO range_valid? - if (r.start == (size_t)-1 || r.end == (size_t)-1) + if (r.start == EPOS || r.end == EPOS) break; if (a->textobj->type == OUTER) { r.start--; @@ -851,7 +851,7 @@ static void action_do(Action *a) { } } else if (mode == &vis_modes[VIS_MODE_VISUAL]) { c.range = window_selection_get(win); - if (c.range.start == (size_t)-1 || c.range.end == (size_t)-1) + if (c.range.start == EPOS || c.range.end == EPOS) c.range.start = c.range.end = pos; } @@ -84,7 +84,7 @@ static bool window_scroll_lines_down(Win *win, int n); static bool window_scroll_lines_up(Win *win, int n); void window_selection_clear(Win *win) { - win->sel.start = win->sel.end = (size_t)-1; + win->sel.start = win->sel.end = EPOS; window_draw(win); window_cursor_update(win); curs_set(1); @@ -113,11 +113,11 @@ static void window_clear(Win *win) { Filerange window_selection_get(Win *win) { Filerange sel = win->sel; - if (sel.start == (size_t)-1) { - sel.end = (size_t)-1; - } else if (sel.end == (size_t)-1) { - sel.start = (size_t)-1; - } else if (sel.start > sel.end) { + if (sel.start == EPOS || sel.end == EPOS) { + sel.start = sel.end = EPOS; + return sel; + } + if (sel.start > sel.end) { size_t tmp = sel.start; sel.start = sel.end; sel.end = tmp; @@ -254,7 +254,7 @@ void window_cursor_getxy(Win *win, size_t *lineno, size_t *col) { * its changes. */ static size_t window_cursor_update(Win *win) { Cursor *cursor = &win->cursor; - if (win->sel.start != (size_t)-1) { + if (win->sel.start != EPOS) { win->sel.end = cursor->pos; window_draw(win); } |
