diff options
| -rw-r--r-- | ui-curses.c | 18 | ||||
| -rw-r--r-- | view.c | 16 | ||||
| -rw-r--r-- | view.h | 9 |
3 files changed, 17 insertions, 26 deletions
diff --git a/ui-curses.c b/ui-curses.c index 1de0f99..7be2930 100644 --- a/ui-curses.c +++ b/ui-curses.c @@ -606,7 +606,8 @@ static bool ui_window_draw_sidebar(UiCursesWin *win) { } else { int i = 0; size_t prev_lineno = 0; - size_t cursor_lineno = view_cursor_getpos(win->view).line; + const Line *cursor_line = view_line_get(win->view); + size_t cursor_lineno = cursor_line->lineno; werase(win->winside); wbkgd(win->winside, style_to_attr(&win->styles[UI_STYLE_DEFAULT])); wattrset(win->winside, style_to_attr(&win->styles[UI_STYLE_LINENUMBER])); @@ -656,8 +657,10 @@ static void ui_window_draw_status(UiWin *w) { } if (!(win->options & UI_OPTION_LARGE_FILE)) { - CursorPos pos = view_cursor_getpos(win->view); - msg += sprintf(msg, "%zd, %zd", pos.line, pos.col); + Cursor *cur = view_cursors_primary_get(win->view); + size_t line = view_cursors_line(cur); + size_t col = view_cursors_col(cur); + msg += sprintf(msg, "%zu, %zu", line, col); } if (buf[0]) @@ -676,10 +679,11 @@ static void ui_window_draw(UiWin *w) { size_t cursor_lineno = -1; if (win->options & UI_OPTION_CURSOR_LINE && win->ui->selwin == win) { - Cursor *cursor = view_cursors(win->view); - Filerange selection = view_cursors_selection_get(cursor); - if (!view_cursors_next(cursor) && !text_range_valid(&selection)) - cursor_lineno = view_cursor_getpos(win->view).line; + Filerange selection = view_selection_get(win->view); + if (!view_cursors_multiple(win->view) && !text_range_valid(&selection)) { + const Line *line = view_line_get(win->view); + cursor_lineno = line->lineno; + } } short selection_bg = win->styles[UI_STYLE_SELECTION].bg; @@ -432,18 +432,6 @@ static bool view_addch(View *view, Cell *cell) { } } -CursorPos view_cursor_getpos(View *view) { - Cursor *cursor = view->cursor; - Line *line = cursor->line; - CursorPos pos = { .line = line->lineno, .col = cursor->col }; - while (line->prev && line->prev->lineno == pos.line) { - line = line->prev; - pos.col += line->width; - } - pos.col++; - return pos; -} - static void cursor_to(Cursor *c, size_t pos) { Text *txt = c->view->text; c->mark = text_mark_set(txt, pos); @@ -1011,6 +999,10 @@ const Line *view_lines_get(View *view) { return view->topline; } +const Line *view_line_get(View *view) { + return view->cursor->line; +} + void view_scroll_to(View *view, size_t pos) { view_cursors_scroll_to(view->cursor, pos); } @@ -40,11 +40,6 @@ struct Line { /* a line on the screen, *not* in the file */ Cell cells[]; /* win->width cells storing information about the displayed characters */ }; -typedef struct { - size_t line; - size_t col; -} CursorPos; - View *view_new(Text*, lua_State*); void view_ui(View*, UiWin*); /* change associated text displayed in this window */ @@ -68,6 +63,7 @@ size_t view_screenline_up(Cursor*); size_t view_screenline_begin(Cursor*); size_t view_screenline_middle(Cursor*); size_t view_screenline_end(Cursor*); + /* move window content up/down, but keep cursor position unchanged unless it is * on a now invisible line in which case we try to preserve the column position */ size_t view_slide_up(View*, int lines); @@ -80,6 +76,7 @@ size_t view_scroll_down(View*, int lines); size_t view_screenline_goto(View*, int n); const Line *view_lines_get(View*); +const Line *view_line_get(View*); /* redraw current cursor line at top/center/bottom of window */ void view_redraw_top(View*); void view_redraw_center(View*); @@ -108,8 +105,6 @@ size_t view_horizon_get(View*); * on this cursor. Additional cursor can be created and manipulated using the * functions named view_cursors_* */ -/* get main cursor position in terms of screen coordinates */ -CursorPos view_cursor_getpos(View*); /* get main cursor position in bytes from start of the file */ size_t view_cursor_get(View*); /* get selection associated with primary cursor */ |
