diff options
| -rw-r--r-- | config.def.h | 5 | ||||
| -rw-r--r-- | window.c | 12 | ||||
| -rw-r--r-- | window.h | 7 |
3 files changed, 14 insertions, 10 deletions
diff --git a/config.def.h b/config.def.h index cfd1771..0ca896b 100644 --- a/config.def.h +++ b/config.def.h @@ -69,9 +69,8 @@ static Command cmds[] = { /* draw a statubar, do whatever you want with win->statuswin curses window */ static void statusbar(EditorWin *win) { - size_t line, col; bool focused = vis->win == win || vis->prompt->editor == win; - window_cursor_getxy(win->win, &line, &col); + CursorPos pos = window_cursor_getpos(win->win); wattrset(win->statuswin, focused ? A_REVERSE|A_BOLD : A_REVERSE); mvwhline(win->statuswin, 0, 0, ' ', win->width); mvwprintw(win->statuswin, 0, 0, "%s %s %s %s", @@ -80,7 +79,7 @@ static void statusbar(EditorWin *win) { text_modified(win->text) ? "[+]" : "", vis->recording ? "recording": ""); char buf[win->width + 1]; - int len = snprintf(buf, win->width, "%zd, %zd", line, col); + int len = snprintf(buf, win->width, "%zd, %zd", pos.line, pos.col); if (len > 0) { buf[len] = '\0'; mvwaddstr(win->statuswin, 0, win->width - len - 1, buf); @@ -296,16 +296,16 @@ static bool window_addch(Win *win, Char *c) { } } -void window_cursor_getxy(Win *win, size_t *lineno, size_t *col) { +CursorPos window_cursor_getpos(Win *win) { Cursor *cursor = &win->cursor; Line *line = cursor->line; - *lineno = line->lineno; - *col = cursor->col; - while (line->prev && line->prev->lineno == *lineno) { + CursorPos pos = { .line = line->lineno, .col = cursor->col }; + while (line->prev && line->prev->lineno == pos.line) { line = line->prev; - *col += line->width; + pos.col += line->width; } - *col += 1; + pos.col++; + return pos; } /* place the cursor according to the screen coordinates in win->{row,col} and @@ -8,6 +8,11 @@ typedef struct Win Win; +typedef struct { + size_t line; + size_t col; +} CursorPos; + Win *window_new(Text*); /* change associated text displayed in this window */ void window_reload(Win*, Text*); @@ -50,7 +55,7 @@ size_t window_line_goto(Win*, int n); /* get cursor position in bytes from start of the file */ size_t window_cursor_get(Win*); /* get cursor position in terms of screen coordinates */ -void window_cursor_getxy(Win*, size_t *lineno, size_t *col); +CursorPos window_cursor_getpos(Win*); /* moves window viewport in direction until pos is visible. should only be * used for short distances between current cursor position and destination */ void window_scroll_to(Win*, size_t pos); |
