aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/move.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/move.c')
-rw-r--r--src/nvim/move.c79
1 files changed, 41 insertions, 38 deletions
diff --git a/src/nvim/move.c b/src/nvim/move.c
index d80e63e79d..eda3298101 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -23,9 +23,9 @@
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/fold.h"
+#include "nvim/getchar.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
-#include "nvim/misc1.h"
#include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/plines.h"
@@ -95,33 +95,38 @@ static void comp_botline(win_T *wp)
win_check_anchored_floats(wp);
}
-void reset_cursorline(void)
+/// Redraw when w_cline_row changes and 'relativenumber' or 'cursorline' is set.
+/// Also when concealing is on and 'concealcursor' is not active.
+void redraw_for_cursorline(win_T *wp)
+ FUNC_ATTR_NONNULL_ALL
{
- curwin->w_last_cursorline = 0;
+ if ((wp->w_valid & VALID_CROW) == 0 && !pum_visible()
+ && (wp->w_p_rnu || win_cursorline_standout(wp))) {
+ // win_line() will redraw the number column and cursorline only.
+ redraw_later(wp, VALID);
+ }
}
-// Redraw when w_cline_row changes and 'relativenumber' or 'cursorline' is set.
-void redraw_for_cursorline(win_T *wp)
+/// Redraw when w_virtcol changes and 'cursorcolumn' is set or 'cursorlineopt'
+/// contains "screenline".
+/// Also when concealing is on and 'concealcursor' is active.
+static void redraw_for_cursorcolumn(win_T *wp)
FUNC_ATTR_NONNULL_ALL
{
- if ((wp->w_p_rnu || win_cursorline_standout(wp))
- && (wp->w_valid & VALID_CROW) == 0
- && !pum_visible()) {
- if (wp->w_p_rnu) {
- // win_line() will redraw the number column only.
+ if ((wp->w_valid & VALID_VIRTCOL) == 0 && !pum_visible()) {
+ if (wp->w_p_cuc) {
+ // When 'cursorcolumn' is set need to redraw with SOME_VALID.
+ redraw_later(wp, SOME_VALID);
+ } else if (wp->w_p_cul && (wp->w_p_culopt_flags & CULOPT_SCRLINE)) {
+ // When 'cursorlineopt' contains "screenline" need to redraw with VALID.
redraw_later(wp, VALID);
}
- if (win_cursorline_standout(wp)) {
- if (wp->w_redr_type <= VALID && wp->w_last_cursorline != 0) {
- // "w_last_cursorline" may be outdated, worst case we redraw
- // too much. This is optimized for moving the cursor around in
- // the current window.
- redrawWinline(wp, wp->w_last_cursorline);
- redrawWinline(wp, wp->w_cursor.lnum);
- } else {
- redraw_later(wp, SOME_VALID);
- }
- }
+ }
+ // If the cursor moves horizontally when 'concealcursor' is active, then the
+ // current line needs to be redrawn in order to calculate the correct
+ // cursor position.
+ if ((wp->w_valid & VALID_VIRTCOL) == 0 && wp->w_p_cole > 0 && conceal_cursor_line(wp)) {
+ redrawWinline(wp, wp->w_cursor.lnum);
}
}
@@ -346,10 +351,10 @@ void update_topline(win_T *wp)
*/
void update_topline_win(win_T *win)
{
- win_T *save_curwin;
- switch_win(&save_curwin, NULL, win, NULL, true);
+ switchwin_T switchwin;
+ switch_win(&switchwin, win, NULL, true);
update_topline(curwin);
- restore_win(save_curwin, NULL, true);
+ restore_win(&switchwin, true);
}
/*
@@ -641,11 +646,8 @@ void validate_virtcol_win(win_T *wp)
check_cursor_moved(wp);
if (!(wp->w_valid & VALID_VIRTCOL)) {
getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL);
+ redraw_for_cursorcolumn(wp);
wp->w_valid |= VALID_VIRTCOL;
- if (wp->w_p_cuc
- && !pum_visible()) {
- redraw_later(wp, SOME_VALID);
- }
}
}
@@ -776,8 +778,13 @@ void curs_columns(win_T *wp, int may_scroll)
int textwidth = wp->w_width_inner - extra;
if (textwidth <= 0) {
// No room for text, put cursor in last char of window.
+ // If not wrapping, the last non-empty line.
wp->w_wcol = wp->w_width_inner - 1;
- wp->w_wrow = wp->w_height_inner - 1;
+ if (wp->w_p_wrap) {
+ wp->w_wrow = wp->w_height_inner - 1;
+ } else {
+ wp->w_wrow = wp->w_height_inner - 1 - wp->w_empty_rows;
+ }
} else if (wp->w_p_wrap
&& wp->w_width_inner != 0) {
width = textwidth + win_col_off2(wp);
@@ -909,7 +916,7 @@ void curs_columns(win_T *wp, int may_scroll)
}
wp->w_skipcol = n * width;
} else if (extra == 1) {
- // less then 'scrolloff' lines above, decrease skipcol
+ // less than 'scrolloff' lines above, decrease skipcol
assert(so <= INT_MAX);
extra = (wp->w_skipcol + (int)so * width - wp->w_virtcol
+ width - 1) / width;
@@ -920,7 +927,7 @@ void curs_columns(win_T *wp, int may_scroll)
wp->w_skipcol -= extra * width;
}
} else if (extra == 2) {
- // less then 'scrolloff' lines below, increase skipcol
+ // less than 'scrolloff' lines below, increase skipcol
endcol = (n - wp->w_height_inner + 1) * width;
while (endcol > wp->w_virtcol) {
endcol -= width;
@@ -948,11 +955,7 @@ void curs_columns(win_T *wp, int may_scroll)
redraw_later(wp, NOT_VALID);
}
- // Redraw when w_virtcol changes and 'cursorcolumn' is set
- if (wp->w_p_cuc && (wp->w_valid & VALID_VIRTCOL) == 0
- && !pum_visible()) {
- redraw_later(wp, SOME_VALID);
- }
+ redraw_for_cursorcolumn(curwin);
// now w_leftcol is valid, avoid check_cursor_moved() thinking otherwise
wp->w_valid_leftcol = wp->w_leftcol;
@@ -1011,7 +1014,7 @@ void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp,
col -= wp->w_leftcol;
if (col >= 0 && col < wp->w_width) {
- coloff = col - scol + (local ? 0 : wp->w_wincol) + 1;
+ coloff = col - scol + (local ? 0 : wp->w_wincol + wp->w_border_adj[3]) + 1;
} else {
scol = ccol = ecol = 0;
// character is left or right of the window
@@ -1022,7 +1025,7 @@ void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp,
}
}
}
- *rowp = (local ? 0 : wp->w_winrow) + row + rowoff;
+ *rowp = (local ? 0 : wp->w_winrow + wp->w_border_adj[0]) + row + rowoff;
*scolp = scol + coloff;
*ccolp = ccol + coloff;
*ecolp = ecol + coloff;