aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/normal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/normal.c')
-rw-r--r--src/nvim/normal.c144
1 files changed, 72 insertions, 72 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 0293bb4a73..4e955667dc 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -168,7 +168,7 @@ static const struct nv_cmd {
{ NL, nv_down, 0, false },
{ Ctrl_K, nv_error, 0, 0 },
{ Ctrl_L, nv_clear, 0, 0 },
- { Ctrl_M, nv_down, 0, true },
+ { CAR, nv_down, 0, true },
{ Ctrl_N, nv_down, NV_STS, false },
{ Ctrl_O, nv_ctrlo, 0, 0 },
{ Ctrl_P, nv_up, NV_STS, false },
@@ -1261,7 +1261,7 @@ static void normal_redraw(NormalState *s)
{
// Before redrawing, make sure w_topline is correct, and w_leftcol
// if lines don't wrap, and w_skipcol if lines wrap.
- update_topline();
+ update_topline(curwin);
validate_cursor();
// If the cursor moves horizontally when 'concealcursor' is active, then the
@@ -1341,7 +1341,7 @@ static int normal_check(VimState *state)
} else if (do_redraw || stuff_empty()) {
// Need to make sure w_topline and w_leftcol are correct before
// normal_check_window_scrolled() is called.
- update_topline();
+ update_topline(curwin);
normal_check_cursor_moved(s);
normal_check_text_changed(s);
@@ -2375,10 +2375,10 @@ do_mouse (
* Also paste at the cursor if the current mode isn't in 'mouse' (only
* happens for the GUI).
*/
- if ((State & INSERT) || !mouse_has(MOUSE_NORMAL)) {
- if (regname == '.')
+ if ((State & INSERT)) {
+ if (regname == '.') {
insert_reg(regname, true);
- else {
+ } else {
if (regname == 0 && eval_has_provider("clipboard")) {
regname = '*';
}
@@ -2558,8 +2558,9 @@ do_mouse (
* on a status line */
if (VIsual_active)
jump_flags |= MOUSE_MAY_STOP_VIS;
- } else if (mouse_has(MOUSE_VISUAL))
+ } else {
jump_flags |= MOUSE_MAY_VIS;
+ }
} else if (which_button == MOUSE_RIGHT) {
if (is_click && VIsual_active) {
/*
@@ -2575,8 +2576,7 @@ do_mouse (
}
}
jump_flags |= MOUSE_FOCUS;
- if (mouse_has(MOUSE_VISUAL))
- jump_flags |= MOUSE_MAY_VIS;
+ jump_flags |= MOUSE_MAY_VIS;
}
}
@@ -2629,7 +2629,7 @@ do_mouse (
/* Set global flag that we are extending the Visual area with mouse
* dragging; temporarily minimize 'scrolloff'. */
- if (VIsual_active && is_drag && get_scrolloff_value()) {
+ if (VIsual_active && is_drag && get_scrolloff_value(curwin)) {
// In the very first line, allow scrolling one line
if (mouse_row == 0) {
mouse_dragging = 2;
@@ -2790,8 +2790,7 @@ do_mouse (
/* Handle double clicks, unless on status line */
else if (in_status_line) {
} else if (in_sep_line) {
- } else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT))
- && mouse_has(MOUSE_VISUAL)) {
+ } else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT))) {
if (is_click || !VIsual_active) {
if (VIsual_active) {
orig_cursor = VIsual;
@@ -3052,57 +3051,57 @@ static bool find_is_eval_item(
return false;
}
-/*
- * Find the identifier under or to the right of the cursor.
- * "find_type" can have one of three values:
- * FIND_IDENT: find an identifier (keyword)
- * FIND_STRING: find any non-white string
- * FIND_IDENT + FIND_STRING: find any non-white string, identifier preferred.
- * FIND_EVAL: find text useful for C program debugging
- *
- * There are three steps:
- * 1. Search forward for the start of an identifier/string. Doesn't move if
- * already on one.
- * 2. Search backward for the start of this identifier/string.
- * This doesn't match the real Vi but I like it a little better and it
- * shouldn't bother anyone.
- * 3. Search forward to the end of this identifier/string.
- * When FIND_IDENT isn't defined, we backup until a blank.
- *
- * Returns the length of the string, or zero if no string is found.
- * If a string is found, a pointer to the string is put in "*string". This
- * string is not always NUL terminated.
- */
-size_t find_ident_under_cursor(char_u **string, int find_type)
+// Find the identifier under or to the right of the cursor.
+// "find_type" can have one of three values:
+// FIND_IDENT: find an identifier (keyword)
+// FIND_STRING: find any non-white text
+// FIND_IDENT + FIND_STRING: find any non-white text, identifier preferred.
+// FIND_EVAL: find text useful for C program debugging
+//
+// There are three steps:
+// 1. Search forward for the start of an identifier/text. Doesn't move if
+// already on one.
+// 2. Search backward for the start of this identifier/text.
+// This doesn't match the real Vi but I like it a little better and it
+// shouldn't bother anyone.
+// 3. Search forward to the end of this identifier/text.
+// When FIND_IDENT isn't defined, we backup until a blank.
+//
+// Returns the length of the text, or zero if no text is found.
+// If text is found, a pointer to the text is put in "*text". This
+// points into the current buffer line and is not always NUL terminated.
+size_t find_ident_under_cursor(char_u **text, int find_type)
+ FUNC_ATTR_NONNULL_ARG(1)
{
return find_ident_at_pos(curwin, curwin->w_cursor.lnum,
- curwin->w_cursor.col, string, find_type);
+ curwin->w_cursor.col, text, NULL, find_type);
}
/*
* Like find_ident_under_cursor(), but for any window and any position.
* However: Uses 'iskeyword' from the current window!.
*/
-size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol,
- char_u **string, int find_type)
-{
- char_u *ptr;
- int col = 0; /* init to shut up GCC */
+size_t find_ident_at_pos(
+ win_T *wp,
+ linenr_T lnum,
+ colnr_T startcol,
+ char_u **text,
+ int *textcol, // column where "text" starts, can be NULL
+ int find_type)
+ FUNC_ATTR_NONNULL_ARG(1, 4)
+{
+ int col = 0; // init to shut up GCC
int i;
int this_class = 0;
int prev_class;
int prevcol;
int bn = 0; // bracket nesting
- /*
- * if i == 0: try to find an identifier
- * if i == 1: try to find any non-white string
- */
- ptr = ml_get_buf(wp->w_buffer, lnum, false);
- for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; ++i) {
- /*
- * 1. skip to start of identifier/string
- */
+ // if i == 0: try to find an identifier
+ // if i == 1: try to find any non-white text
+ char_u *ptr = ml_get_buf(wp->w_buffer, lnum, false);
+ for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; i++) {
+ // 1. skip to start of identifier/text
col = startcol;
while (ptr[col] != NUL) {
// Stop at a ']' to evaluate "a[x]".
@@ -3120,7 +3119,7 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol,
bn = ptr[col] == ']';
//
- // 2. Back up to start of identifier/string.
+ // 2. Back up to start of identifier/text.
//
// Remember class of character under cursor.
if ((find_type & FIND_EVAL) && ptr[col] == ']') {
@@ -3143,7 +3142,7 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol,
col = prevcol;
}
- // If we don't want just any old string, or we've found an
+ // If we don't want just any old text, or we've found an
// identifier, stop searching.
if (this_class > 2) {
this_class = 2;
@@ -3154,7 +3153,7 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol,
}
if (ptr[col] == NUL || (i == 0 && this_class != 2)) {
- // Didn't find an identifier or string.
+ // Didn't find an identifier or text.
if (find_type & FIND_STRING) {
EMSG(_("E348: No string under cursor"));
} else {
@@ -3163,11 +3162,12 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol,
return 0;
}
ptr += col;
- *string = ptr;
+ *text = ptr;
+ if (textcol != NULL) {
+ *textcol = col;
+ }
- /*
- * 3. Find the end if the identifier/string.
- */
+ // 3. Find the end if the identifier/text.
bn = 0;
startcol -= col;
col = 0;
@@ -4135,7 +4135,7 @@ void scroll_redraw(int up, long count)
scrollup(count, true) :
scrolldown(count, true);
- if (get_scrolloff_value()) {
+ if (get_scrolloff_value(curwin)) {
// Adjust the cursor position for 'scrolloff'. Mark w_topline as
// valid, otherwise the screen jumps back at the end of the file.
cursor_correct();
@@ -4185,7 +4185,7 @@ static void nv_zet(cmdarg_T *cap)
int old_fen = curwin->w_p_fen;
bool undo = false;
- int l_p_siso = (int)get_sidescrolloff_value();
+ int l_p_siso = (int)get_sidescrolloff_value(curwin);
assert(l_p_siso <= INT_MAX);
if (ascii_isdigit(nchar)) {
@@ -4253,12 +4253,13 @@ dozet:
/* "z+", "z<CR>" and "zt": put cursor at top of screen */
case '+':
if (cap->count0 == 0) {
- /* No count given: put cursor at the line below screen */
- validate_botline(); /* make sure w_botline is valid */
- if (curwin->w_botline > curbuf->b_ml.ml_line_count)
+ // No count given: put cursor at the line below screen
+ validate_botline(curwin); // make sure w_botline is valid
+ if (curwin->w_botline > curbuf->b_ml.ml_line_count) {
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
- else
+ } else {
curwin->w_cursor.lnum = curwin->w_botline;
+ }
}
FALLTHROUGH;
case NL:
@@ -5053,7 +5054,7 @@ static void nv_scroll(cmdarg_T *cap)
setpcmark();
if (cap->cmdchar == 'L') {
- validate_botline(); /* make sure curwin->w_botline is valid */
+ validate_botline(curwin); // make sure curwin->w_botline is valid
curwin->w_cursor.lnum = curwin->w_botline - 1;
if (cap->count1 - 1 >= curwin->w_cursor.lnum)
curwin->w_cursor.lnum = 1;
@@ -5074,7 +5075,7 @@ 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
+ validate_botline(curwin); // make sure w_empty_rows is valid
half = (curwin->w_height_inner - 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
@@ -6653,16 +6654,15 @@ static void nv_g_cmd(cmdarg_T *cap)
VIsual = curwin->w_cursor;
curwin->w_cursor = tpos;
check_cursor();
- update_topline();
- /*
- * When called from normal "g" command: start Select mode when
- * 'selectmode' contains "cmd". When called for K_SELECT, always
- * start Select mode.
- */
- if (cap->arg)
+ update_topline(curwin);
+ // When called from normal "g" command: start Select mode when
+ // 'selectmode' contains "cmd". When called for K_SELECT, always
+ // start Select mode.
+ if (cap->arg) {
VIsual_select = true;
- else
+ } else {
may_start_select('c');
+ }
setmouse();
redraw_curbuf_later(INVERTED);
showmode();