diff options
Diffstat (limited to 'src/nvim/mouse.c')
-rw-r--r-- | src/nvim/mouse.c | 67 |
1 files changed, 23 insertions, 44 deletions
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 506a428243..f393b0fd0f 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -467,7 +467,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent) if (regname == '.') { insert_reg(regname, true); } else { - if (regname == 0 && eval_has_provider("clipboard")) { + if (regname == 0 && eval_has_provider("clipboard", false)) { regname = '*'; } if ((State & REPLACE_FLAG) && !yank_register_mline(regname)) { @@ -771,7 +771,7 @@ popupexit: // move VIsual to the right column start_visual = curwin->w_cursor; // save the cursor pos curwin->w_cursor = end_visual; - coladvance(end_visual.col); + coladvance(curwin, end_visual.col); VIsual = curwin->w_cursor; curwin->w_cursor = start_visual; // restore the cursor } else { @@ -819,7 +819,7 @@ popupexit: // Middle mouse click: Put text before cursor. if (which_button == MOUSE_MIDDLE) { int c2; - if (regname == 0 && eval_has_provider("clipboard")) { + if (regname == 0 && eval_has_provider("clipboard", false)) { regname = '*'; } if (yank_register_mline(regname)) { @@ -1024,7 +1024,7 @@ void do_mousescroll(cmdarg_T *cap) // Vertical scrolling if ((State & MODE_NORMAL) && shift_or_ctrl) { // whole page up or down - onepage(cap->arg ? FORWARD : BACKWARD, 1); + pagescroll(cap->arg ? FORWARD : BACKWARD, 1, false); } else { if (shift_or_ctrl) { // whole page up or down @@ -1430,7 +1430,7 @@ retnomove: break; } first = false; - hasFolding(curwin->w_topline, &curwin->w_topline, NULL); + hasFolding(curwin, curwin->w_topline, &curwin->w_topline, NULL); if (curwin->w_topfill < win_get_fill(curwin, curwin->w_topline)) { curwin->w_topfill++; } else { @@ -1460,7 +1460,7 @@ retnomove: if (curwin->w_topfill > 0) { curwin->w_topfill--; } else { - if (hasFolding(curwin->w_topline, NULL, &curwin->w_topline) + if (hasFolding(curwin, curwin->w_topline, NULL, &curwin->w_topline) && curwin->w_topline == curbuf->b_ml.ml_line_count) { break; } @@ -1515,7 +1515,7 @@ retnomove: curwin->w_curswant = col; curwin->w_set_curswant = false; // May still have been true - if (coladvance(col) == FAIL) { // Mouse click beyond end of line + if (coladvance(curwin, col) == FAIL) { // Mouse click beyond end of line if (inclusive != NULL) { *inclusive = true; } @@ -1548,7 +1548,7 @@ static bool do_mousescroll_horiz(colnr_T leftcol) // When the line of the cursor is too short, move the cursor to the // longest visible line. - if (!virtual_active() + if (!virtual_active(curwin) && leftcol > scroll_line_len(curwin->w_cursor.lnum)) { curwin->w_cursor.lnum = find_longest_lnum(); curwin->w_cursor.col = 0; @@ -1621,23 +1621,28 @@ bool mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump) } if (win->w_skipcol > 0 && lnum == win->w_topline) { - // Adjust for 'smoothscroll' clipping the top screen lines. - // A similar formula is used in curs_columns(). int width1 = win->w_width_inner - win_col_off(win); - int skip_lines = 0; - if (win->w_skipcol > width1) { - skip_lines = (win->w_skipcol - width1) / (width1 + win_col_off2(win)) + 1; - } else if (win->w_skipcol > 0) { - skip_lines = 1; + + if (width1 > 0) { + int skip_lines = 0; + + // Adjust for 'smoothscroll' clipping the top screen lines. + // A similar formula is used in curs_columns(). + if (win->w_skipcol > width1) { + skip_lines = (win->w_skipcol - width1) / (width1 + win_col_off2(win)) + 1; + } else if (win->w_skipcol > 0) { + skip_lines = 1; + } + + count -= skip_lines; } - count -= skip_lines; } if (count > row) { break; // Position is in this buffer line. } - hasFoldingWin(win, lnum, NULL, &lnum, true, NULL); + hasFolding(win, lnum, NULL, &lnum); if (lnum == win->w_buffer->b_ml.ml_line_count) { retval = true; @@ -1883,33 +1888,7 @@ static void mouse_check_grid(colnr_T *vcolp, int *flagsp) const size_t off = gp->line_offset[click_row] + (size_t)click_col; colnr_T col_from_screen = gp->vcols[off]; - if (col_from_screen == MAXCOL) { - // When clicking after end of line, still need to set correct curswant - size_t off_l = gp->line_offset[click_row] + (size_t)start_col; - if (gp->vcols[off_l] < MAXCOL) { - // Binary search to find last char in line - size_t off_r = off; - while (off_l < off_r) { - size_t off_m = (off_l + off_r + 1) / 2; - if (gp->vcols[off_m] < MAXCOL) { - off_l = off_m; - } else { - off_r = off_m - 1; - } - } - colnr_T eol_vcol = gp->vcols[off_r]; - assert(eol_vcol < MAXCOL); - if (eol_vcol < 0) { - // Empty line or whole line before w_leftcol, - // with columns before buffer text - eol_vcol = curwin->w_leftcol - 1; - } - *vcolp = eol_vcol + (int)(off - off_r); - } else { - // Empty line or whole line before w_leftcol - *vcolp = click_col - start_col + curwin->w_leftcol; - } - } else if (col_from_screen >= 0) { + if (col_from_screen >= 0) { // Use the virtual column from vcols[], it is accurate also after // concealed characters. *vcolp = col_from_screen; |