aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/mouse.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-07-01 10:49:14 +0800
committerGitHub <noreply@github.com>2022-07-01 10:49:14 +0800
commit2268a4147ec1e9f0236fd5eb56c1cc2b751eca05 (patch)
treee85448107d27109df805e865053468e199956dbe /src/nvim/mouse.c
parent5a490d838ed3288abcf45e16e6ab79c326a67c17 (diff)
parent5a62ad605e4945562d5defb5eb6a2e8a88107ebf (diff)
downloadrneovim-2268a4147ec1e9f0236fd5eb56c1cc2b751eca05.tar.gz
rneovim-2268a4147ec1e9f0236fd5eb56c1cc2b751eca05.tar.bz2
rneovim-2268a4147ec1e9f0236fd5eb56c1cc2b751eca05.zip
Merge pull request #19170 from zeertzjq/vim-8.0.1558
vim-patch:8.0.{1558,1570,1574,1588},8.1.{0487,0695,1274}: menu features
Diffstat (limited to 'src/nvim/mouse.c')
-rw-r--r--src/nvim/mouse.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c
index fc5ecbc6a0..3aee20dc7b 100644
--- a/src/nvim/mouse.c
+++ b/src/nvim/mouse.c
@@ -30,6 +30,49 @@
static linenr_T orig_topline = 0;
static int orig_topfill = 0;
+/// Translate window coordinates to buffer position without any side effects
+int get_fpos_of_mouse(pos_T *mpos)
+{
+ int grid = mouse_grid;
+ int row = mouse_row;
+ int col = mouse_col;
+
+ if (row < 0 || col < 0) { // check if it makes sense
+ return IN_UNKNOWN;
+ }
+
+ // find the window where the row is in
+ win_T *wp = mouse_find_win(&grid, &row, &col);
+ if (wp == NULL) {
+ return IN_UNKNOWN;
+ }
+
+ // winpos and height may change in win_enter()!
+ if (row + wp->w_winbar_height >= wp->w_height) { // In (or below) status line
+ return IN_STATUS_LINE;
+ }
+ if (col >= wp->w_width) { // In vertical separator line
+ return IN_SEP_LINE;
+ }
+
+ if (wp != curwin) {
+ return IN_UNKNOWN;
+ }
+
+ // compute the position in the buffer line from the posn on the screen
+ if (mouse_comp_pos(curwin, &row, &col, &mpos->lnum)) {
+ return IN_STATUS_LINE; // past bottom
+ }
+
+ mpos->col = vcol2col(wp, mpos->lnum, col);
+
+ if (mpos->col > 0) {
+ mpos->col--;
+ }
+ mpos->coladd = 0;
+ return IN_BUFFER;
+}
+
/// Return true if "c" is a mouse key.
bool is_mouse_key(int c)
{