diff options
Diffstat (limited to 'src/nvim/normal.c')
-rw-r--r-- | src/nvim/normal.c | 91 |
1 files changed, 49 insertions, 42 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c index fd974d9c05..1692970a97 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -33,7 +33,7 @@ #include "nvim/getchar.h" #include "nvim/globals.h" #include "nvim/indent.h" -#include "nvim/keymap.h" +#include "nvim/keycodes.h" #include "nvim/log.h" #include "nvim/main.h" #include "nvim/mark.h" @@ -487,7 +487,7 @@ static void normal_prepare(NormalState *s) } s->mapped_len = typebuf_maplen(); - State = NORMAL_BUSY; + State = MODE_NORMAL_BUSY; // Set v:count here, when called from main() and not a stuffed command, so // that v:count can be used in an expression mapping when there is no count. @@ -594,7 +594,7 @@ static void normal_redraw_mode_message(NormalState *s) // Draw the cursor with the right shape here if (restart_edit != 0) { - State = INSERT; + State = MODE_INSERT; } // If need to redraw, and there is a "keep_msg", redraw before the @@ -671,7 +671,7 @@ static void normal_get_additional_char(NormalState *s) // Get a second or third character. if (cp != NULL) { if (repl) { - State = REPLACE; // pretend Replace mode + State = MODE_REPLACE; // pretend Replace mode ui_cursor_shape(); // show different cursor shape } if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) { @@ -679,9 +679,9 @@ static void normal_get_additional_char(NormalState *s) no_mapping--; allow_keys--; if (repl) { - State = LREPLACE; + State = MODE_LREPLACE; } else { - State = LANGMAP; + State = MODE_LANGMAP; } langmap_active = true; } @@ -693,7 +693,7 @@ static void normal_get_additional_char(NormalState *s) no_mapping++; allow_keys++; } - State = NORMAL_BUSY; + State = MODE_NORMAL_BUSY; s->need_flushbuf |= add_to_showcmd(*cp); if (!lit) { @@ -979,7 +979,7 @@ static int normal_execute(VimState *state, int key) s->old_col = curwin->w_curswant; s->c = key; - LANGMAP_ADJUST(s->c, get_real_state() != SELECTMODE); + LANGMAP_ADJUST(s->c, get_real_state() != MODE_SELECT); // If a mapping was started in Visual or Select mode, remember the length // of the mapping. This is used below to not return to Insert mode for as @@ -1122,7 +1122,7 @@ static int normal_execute(VimState *state, int key) did_cursorhold = false; } - State = NORMAL; + State = MODE_NORMAL; if (s->ca.nchar == ESC) { clearop(&s->oa); @@ -1202,7 +1202,7 @@ static void normal_check_interrupt(NormalState *s) // Typed two CTRL-C in a row: go back to ex mode as if "Q" was // used and keep "got_int" set, so that it aborts ":g". exmode_active = true; - State = NORMAL; + State = MODE_NORMAL; } else if (!global_busy || !exmode_active) { if (!quit_more) { // flush all buffers @@ -1280,7 +1280,8 @@ static void normal_redraw(NormalState *s) validate_cursor(); if (VIsual_active) { - update_curbuf(INVERTED); // update inverted part + redraw_curbuf_later(INVERTED); // update inverted part + update_screen(INVERTED); } else if (must_redraw) { update_screen(0); } else if (redraw_cmdline || clear_cmdline) { @@ -1559,7 +1560,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent) // CTRL right mouse button does CTRL-T if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) { - if (State & INSERT) { + if (State & MODE_INSERT) { stuffcharReadbuff(Ctrl_O); } if (count > 1) { @@ -1607,7 +1608,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent) // Middle mouse button does a 'put' of the selected text if (which_button == MOUSE_MIDDLE) { - if (State == NORMAL) { + if (State == MODE_NORMAL) { // If an operator was pending, we don't know what the user wanted to do. // Go back to normal mode: Clear the operator and beep(). if (oap != NULL && oap->op_type != OP_NOP) { @@ -1629,7 +1630,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent) return false; } // The rest is below jump_to_mouse() - } else if ((State & INSERT) == 0) { + } else if ((State & MODE_INSERT) == 0) { return false; } @@ -1638,7 +1639,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent) // with do_put(). // Also paste at the cursor if the current mode isn't in 'mouse' (only // happens for the GUI). - if ((State & INSERT)) { + if ((State & MODE_INSERT)) { if (regname == '.') { insert_reg(regname, true); } else { @@ -1807,7 +1808,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent) } } - if ((State & (NORMAL | INSERT)) + if ((State & (MODE_NORMAL | MODE_INSERT)) && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) { if (which_button == MOUSE_LEFT) { if (is_click) { @@ -1850,6 +1851,11 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent) oap == NULL ? NULL : &(oap->inclusive), which_button); + // A click in the window bar has no side effects. + if (jump_flags & MOUSE_WINBAR) { + return false; + } + moved = (jump_flags & CURSOR_MOVED); in_status_line = (jump_flags & IN_STATUS_LINE); in_sep_line = (jump_flags & IN_SEP_LINE); @@ -1958,7 +1964,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent) } } } - } else if ((State & INSERT) && VIsual_active) { + } else if ((State & MODE_INSERT) && VIsual_active) { // If Visual mode started in insert mode, execute "CTRL-O" stuffcharReadbuff(Ctrl_O); } @@ -2005,7 +2011,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent) || (curbuf->b_help && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)) { // Ctrl-Mouse click (or double click in a help window) jumps to the tag // under the mouse pointer. - if (State & INSERT) { + if (State & MODE_INSERT) { stuffcharReadbuff(Ctrl_O); } stuffcharReadbuff(Ctrl_RSB); @@ -2013,7 +2019,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent) } else if ((mod_mask & MOD_MASK_SHIFT)) { // Shift-Mouse click searches for the next occurrence of the word under // the mouse pointer - if (State & INSERT + if (State & MODE_INSERT || (VIsual_active && VIsual_select)) { stuffcharReadbuff(Ctrl_O); } @@ -2025,7 +2031,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent) } else if (in_status_line || in_sep_line) { // Do nothing if on status line or vertical separator // Handle double clicks otherwise - } else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT))) { + } else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (MODE_NORMAL | MODE_INSERT))) { if (is_click || !VIsual_active) { if (VIsual_active) { orig_cursor = VIsual; @@ -2191,7 +2197,7 @@ static int get_mouse_class(char_u *p) // characters to be considered as a single word. These are things like // "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each // character is in its own class. - if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL) { + if (c != NUL && vim_strchr("-+*/%<>&|^!=", c) != NULL) { return 1; } return c; @@ -3447,7 +3453,7 @@ dozet: // and "zC" only in Visual mode. "zj" and "zk" are motion // commands. if (cap->nchar != 'f' && cap->nchar != 'F' - && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) + && !(VIsual_active && vim_strchr("dcCoO", cap->nchar)) && cap->nchar != 'j' && cap->nchar != 'k' && checkclearop(cap->oap)) { return; @@ -3455,7 +3461,7 @@ dozet: // For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": // If line number given, set cursor. - if ((vim_strchr((char_u *)"+\r\nt.z^-b", nchar) != NULL) + if ((vim_strchr("+\r\nt.z^-b", nchar) != NULL) && cap->count0 && cap->count0 != curwin->w_cursor.lnum) { setpcmark(); @@ -3800,7 +3806,7 @@ dozet: no_mapping--; allow_keys--; (void)add_to_showcmd(nchar); - if (vim_strchr((char_u *)"gGwW", nchar) == NULL) { + if (vim_strchr("gGwW", nchar) == NULL) { clearopbeep(cap->oap); break; } @@ -4234,7 +4240,7 @@ static void nv_ident(cmdarg_T *cap) p = (char_u *)buf + STRLEN(buf); while (n-- > 0) { // put a backslash before \ and some others - if (vim_strchr(aux_ptr, *ptr) != NULL) { + if (vim_strchr((char *)aux_ptr, *ptr) != NULL) { *p++ = '\\'; } // When current byte is a part of multibyte character, copy all @@ -4268,7 +4274,7 @@ static void nv_ident(cmdarg_T *cap) // Start insert mode in terminal buffer restart_edit = 'i'; - add_map((char_u *)"<buffer> <esc> <Cmd>bdelete!<CR>", TERM_FOCUS, true); + add_map((char_u *)"<buffer> <esc> <Cmd>bdelete!<CR>", MODE_TERMINAL, true); } } @@ -4434,9 +4440,9 @@ static void nv_right(cmdarg_T *cap) // <Space> wraps to next line if 'whichwrap' has 's'. // 'l' wraps to next line if 'whichwrap' has 'l'. // CURS_RIGHT wraps to next line if 'whichwrap' has '>'. - if (((cap->cmdchar == ' ' && vim_strchr(p_ww, 's') != NULL) - || (cap->cmdchar == 'l' && vim_strchr(p_ww, 'l') != NULL) - || (cap->cmdchar == K_RIGHT && vim_strchr(p_ww, '>') != NULL)) + if (((cap->cmdchar == ' ' && vim_strchr((char *)p_ww, 's') != NULL) + || (cap->cmdchar == 'l' && vim_strchr((char *)p_ww, 'l') != NULL) + || (cap->cmdchar == K_RIGHT && vim_strchr((char *)p_ww, '>') != NULL)) && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) { // When deleting we also count the NL as a character. // Set cap->oap->inclusive when last char in the line is @@ -4504,9 +4510,9 @@ static void nv_left(cmdarg_T *cap) // 'h' wraps to previous line if 'whichwrap' has 'h'. // CURS_LEFT wraps to previous line if 'whichwrap' has '<'. if ((((cap->cmdchar == K_BS || cap->cmdchar == Ctrl_H) - && vim_strchr(p_ww, 'b') != NULL) - || (cap->cmdchar == 'h' && vim_strchr(p_ww, 'h') != NULL) - || (cap->cmdchar == K_LEFT && vim_strchr(p_ww, '<') != NULL)) + && vim_strchr((char *)p_ww, 'b') != NULL) + || (cap->cmdchar == 'h' && vim_strchr((char *)p_ww, 'h') != NULL) + || (cap->cmdchar == K_LEFT && vim_strchr((char *)p_ww, '<') != NULL)) && curwin->w_cursor.lnum > 1) { curwin->w_cursor.lnum--; coladvance(MAXCOL); @@ -4802,7 +4808,7 @@ static void nv_brackets(cmdarg_T *cap) // "[f" or "]f" : Edit file under the cursor (same as "gf") if (cap->nchar == 'f') { nv_gotofile(cap); - } else if (vim_strchr((char_u *)"iI\011dD\004", cap->nchar) != NULL) { + } else if (vim_strchr("iI\011dD\004", cap->nchar) != NULL) { // Find the occurrence(s) of the identifier or define under cursor // in current and included files or jump to the first occurrence. // @@ -4831,8 +4837,8 @@ static void nv_brackets(cmdarg_T *cap) MAXLNUM); curwin->w_set_curswant = true; } - } else if ((cap->cmdchar == '[' && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) - || (cap->cmdchar == ']' && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) { + } else if ((cap->cmdchar == '[' && vim_strchr("{(*/#mM", cap->nchar) != NULL) + || (cap->cmdchar == ']' && vim_strchr("})*/#mM", cap->nchar) != NULL)) { // "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')' // "[#", "]#": go to start/end of Nth innermost #if..#endif construct. // "[/", "[*", "]/", "]*": go to Nth comment start/end. @@ -5269,7 +5275,7 @@ static void nv_replace(cmdarg_T *cap) // multi-byte and the other way around. Also handles adding // composing characters for utf-8. for (long n = cap->count1; n > 0; n--) { - State = REPLACE; + State = MODE_REPLACE; if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) { int c = ins_copychar(curwin->w_cursor.lnum + (cap->nchar == Ctrl_Y ? -1 : 1)); @@ -5403,7 +5409,7 @@ static void n_swapchar(cmdarg_T *cap) return; } - if (LINEEMPTY(curwin->w_cursor.lnum) && vim_strchr(p_ww, '~') == NULL) { + if (LINEEMPTY(curwin->w_cursor.lnum) && vim_strchr((char *)p_ww, '~') == NULL) { clearopbeep(cap->oap); return; } @@ -5419,7 +5425,7 @@ static void n_swapchar(cmdarg_T *cap) did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor); inc_cursor(); if (gchar_cursor() == NUL) { - if (vim_strchr(p_ww, '~') != NULL + if (vim_strchr((char *)p_ww, '~') != NULL && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) { curwin->w_cursor.lnum++; curwin->w_cursor.col = 0; @@ -5491,7 +5497,7 @@ static void v_visop(cmdarg_T *cap) curwin->w_curswant = MAXCOL; } } - cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); + cap->cmdchar = (uint8_t)(*(vim_strchr((char *)trans, cap->cmdchar) + 1)); nv_operator(cap); } @@ -5754,7 +5760,8 @@ void start_selection(void) /// When "c" is 'o' (checking for "mouse") then also when mapped. void may_start_select(int c) { - VIsual_select = (c == 'o' || (stuff_empty() && typebuf_typed())) && vim_strchr(p_slm, c) != NULL; + VIsual_select = (c == 'o' || (stuff_empty() && typebuf_typed())) + && vim_strchr((char *)p_slm, c) != NULL; } /// Start Visual mode "c". @@ -6807,7 +6814,7 @@ void set_cursor_for_append_to_line(void) // Pretend Insert mode here to allow the cursor on the // character past the end of the line - State = INSERT; + State = MODE_INSERT; coladvance(MAXCOL); State = save_State; } else { @@ -6863,7 +6870,7 @@ static void nv_edit(cmdarg_T *cap) // Pretend Insert mode here to allow the cursor on the // character past the end of the line - State = INSERT; + State = MODE_INSERT; coladvance(getviscol()); State = save_State; } |