diff options
Diffstat (limited to 'src/nvim/normal.c')
-rw-r--r-- | src/nvim/normal.c | 123 |
1 files changed, 56 insertions, 67 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 38ee0936aa..29c5d27258 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1,11 +1,11 @@ // This is an open source non-commercial project. Dear PVS-Studio, please check // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com -/* - * normal.c: Contains the main routine for processing characters in command - * mode. Communicates closely with the code in ops.c to handle - * the operators. - */ +// +// normal.c: Contains the main routine for processing characters in command +// mode. Communicates closely with the code in ops.c to handle +// the operators. +// #include <assert.h> #include <inttypes.h> @@ -1445,8 +1445,10 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) oap->motion_type = kMTCharWise; } else if (oap->motion_force == Ctrl_V) { // Change line- or characterwise motion into Visual block mode. - VIsual_active = true; - VIsual = oap->start; + if (!VIsual_active) { + VIsual_active = true; + VIsual = oap->start; + } VIsual_mode = Ctrl_V; VIsual_select = false; VIsual_reselect = false; @@ -2039,6 +2041,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) curwin->w_cursor = old_cursor; } clearop(oap); + motion_force = NUL; } curwin->w_p_lbr = lbr_saved; } @@ -2761,10 +2764,9 @@ do_mouse ( } else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT)) && mouse_has(MOUSE_VISUAL)) { if (is_click || !VIsual_active) { - if (VIsual_active) + if (VIsual_active) { orig_cursor = VIsual; - else { - check_visual_highlight(); + } else { VIsual = curwin->w_cursor; orig_cursor = VIsual; VIsual_active = true; @@ -2935,22 +2937,6 @@ static int get_mouse_class(char_u *p) } /* - * Check if highlighting for visual mode is possible, give a warning message - * if not. - */ -void check_visual_highlight(void) -{ - static bool did_check = false; - - if (full_screen) { - if (!did_check && HL_ATTR(HLF_V) == 0) { - MSG(_("Warning: terminal cannot highlight")); - } - did_check = true; - } -} - -/* * End Visual mode. * This function should ALWAYS be called to end Visual mode, except from * do_pending_operator(). @@ -3466,10 +3452,10 @@ static void display_showcmd(void) int len; len = (int)STRLEN(showcmd_buf); - if (len == 0) + if (len == 0) { showcmd_is_clear = true; - else { - screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0); + } else { + grid_puts(&default_grid, showcmd_buf, (int)Rows - 1, sc_col, 0); showcmd_is_clear = false; } @@ -3477,7 +3463,8 @@ static void display_showcmd(void) * clear the rest of an old message by outputting up to SHOWCMD_COLS * spaces */ - screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); + grid_puts(&default_grid, (char_u *)" " + len, (int)Rows - 1, + sc_col + len, 0); setcursor(); /* put cursor back where it belongs */ } @@ -3905,18 +3892,16 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist) col_off1 = curwin_col_off(); col_off2 = col_off1 - curwin_col_off2(); - width1 = curwin->w_width - col_off1; - width2 = curwin->w_width - col_off2; + width1 = curwin->w_grid.Columns - col_off1; + width2 = curwin->w_grid.Columns - col_off2; if (width2 == 0) { width2 = 1; // Avoid divide by zero. } - if (curwin->w_width != 0) { - /* - * Instead of sticking at the last character of the buffer line we - * try to stick in the last column of the screen. - */ + if (curwin->w_grid.Columns != 0) { + // Instead of sticking at the last character of the buffer line we + // try to stick in the last column of the screen. if (curwin->w_curswant == MAXCOL) { atend = true; validate_virtcol(); @@ -3957,9 +3942,11 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist) (void)hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL); linelen = linetabsize(get_cursor_line_ptr()); - if (linelen > width1) - curwin->w_curswant += (((linelen - width1 - 1) / width2) - + 1) * width2; + if (linelen > width1) { + int w = (((linelen - width1 - 1) / width2) + 1) * width2; + assert(curwin->w_curswant <= INT_MAX - w); + curwin->w_curswant += w; + } } } else { /* dir == FORWARD */ if (linelen > width1) @@ -4255,7 +4242,7 @@ dozet: /* "zH" - scroll screen right half-page */ case 'H': - cap->count1 *= curwin->w_width / 2; + cap->count1 *= curwin->w_grid.Columns / 2; FALLTHROUGH; /* "zh" - scroll screen to the right */ @@ -4270,8 +4257,8 @@ dozet: } break; - /* "zL" - scroll screen left half-page */ - case 'L': cap->count1 *= curwin->w_width / 2; + // "zL" - scroll screen left half-page + case 'L': cap->count1 *= curwin->w_grid.Columns / 2; FALLTHROUGH; /* "zl" - scroll screen to the left */ @@ -4307,11 +4294,12 @@ dozet: col = 0; /* like the cursor is in col 0 */ else getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); - n = curwin->w_width - curwin_col_off(); - if (col + l_p_siso < n) + n = curwin->w_grid.Columns - curwin_col_off(); + if (col + l_p_siso < n) { col = 0; - else + } else { col = col + l_p_siso - n + 1; + } if (curwin->w_leftcol != col) { curwin->w_leftcol = col; redraw_later(NOT_VALID); @@ -5016,11 +5004,11 @@ static void nv_scroll(cmdarg_T *cap) /* Don't count filler lines above the window. */ used -= diff_check_fill(curwin, curwin->w_topline) - curwin->w_topfill; - validate_botline(); /* make sure w_empty_rows is valid */ - half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; - for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) { - /* Count half he number of filler lines to be "below this - * line" and half to be "above the next line". */ + validate_botline(); // make sure w_empty_rows is valid + half = (curwin->w_grid.Rows - curwin->w_empty_rows + 1) / 2; + for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; n++) { + // Count half he number of filler lines to be "below this + // line" and half to be "above the next line". if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline + n) / 2 >= half) { --n; @@ -5032,9 +5020,10 @@ static void nv_scroll(cmdarg_T *cap) if (hasFolding(curwin->w_topline + n, NULL, &lnum)) n = lnum - curwin->w_topline; } - if (n > 0 && used > curwin->w_height) - --n; - } else { /* (cap->cmdchar == 'H') */ + if (n > 0 && used > curwin->w_grid.Rows) { + n--; + } + } else { // (cap->cmdchar == 'H') n = cap->count1 - 1; if (hasAnyFolding(curwin)) { /* Count a fold for one screen line. */ @@ -6403,8 +6392,8 @@ static void nv_visual(cmdarg_T *cap) /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it * characterwise, linewise, or blockwise. */ if (cap->oap->op_type != OP_NOP) { - cap->oap->motion_force = cap->cmdchar; - finish_op = false; /* operator doesn't finish now but later */ + motion_force = cap->oap->motion_force = cap->cmdchar; + finish_op = false; // operator doesn't finish now but later return; } @@ -6417,9 +6406,8 @@ static void nv_visual(cmdarg_T *cap) VIsual_mode = cap->cmdchar; showmode(); } - redraw_curbuf_later(INVERTED); /* update the inversion */ - } else { /* start Visual mode */ - check_visual_highlight(); + redraw_curbuf_later(INVERTED); // update the inversion + } else { // start Visual mode if (cap->count0 > 0 && resel_VIsual_mode != NUL) { /* use previously selected part */ VIsual = curwin->w_cursor; @@ -6747,9 +6735,9 @@ static void nv_g_cmd(cmdarg_T *cap) oap->motion_type = kMTCharWise; oap->inclusive = false; if (curwin->w_p_wrap - && curwin->w_width != 0 + && curwin->w_grid.Columns != 0 ) { - int width1 = curwin->w_width - curwin_col_off(); + int width1 = curwin->w_grid.Columns - curwin_col_off(); int width2 = width1 + curwin_col_off2(); validate_virtcol(); @@ -6761,10 +6749,11 @@ static void nv_g_cmd(cmdarg_T *cap) /* Go to the middle of the screen line. When 'number' or * 'relativenumber' is on and lines are wrapping the middle can be more * to the left. */ - if (cap->nchar == 'm') - i += (curwin->w_width - curwin_col_off() + if (cap->nchar == 'm') { + i += (curwin->w_grid.Columns - curwin_col_off() + ((curwin->w_p_wrap && i > 0) ? curwin_col_off2() : 0)) / 2; + } coladvance((colnr_T)i); if (flag) { do @@ -6808,11 +6797,11 @@ static void nv_g_cmd(cmdarg_T *cap) oap->motion_type = kMTCharWise; oap->inclusive = true; if (curwin->w_p_wrap - && curwin->w_width != 0 + && curwin->w_grid.Columns != 0 ) { curwin->w_curswant = MAXCOL; /* so we stay at the end */ if (cap->count1 == 1) { - int width1 = curwin->w_width - col_off; + int width1 = curwin->w_grid.Columns - col_off; int width2 = width1 + curwin_col_off2(); validate_virtcol(); @@ -6838,7 +6827,7 @@ static void nv_g_cmd(cmdarg_T *cap) } else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == false) clearopbeep(oap); } else { - i = curwin->w_leftcol + curwin->w_width - col_off - 1; + i = curwin->w_leftcol + curwin->w_grid.Columns - col_off - 1; coladvance((colnr_T)i); /* Make sure we stick in this column. */ @@ -7953,7 +7942,7 @@ static void get_op_vcol( colnr_T end; if (VIsual_mode != Ctrl_V - || (!initial && oap->end.col < curwin->w_width)) { + || (!initial && oap->end.col < curwin->w_grid.Columns)) { return; } |