annotate src/mouse.c @ 18135:1868ec23360e v8.1.2062

patch 8.1.2062: the mouse code is spread out Commit: https://github.com/vim/vim/commit/b20b9e14ddd8db111e886ad0494e15b955159426 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 21 20:48:04 2019 +0200 patch 8.1.2062: the mouse code is spread out Problem: The mouse code is spread out. Solution: Move all the mouse code to mouse.c. (Yegappan Lakshmanan, closes #4959)
author Bram Moolenaar <Bram@vim.org>
date Sat, 21 Sep 2019 21:00:07 +0200
parents
children 2cc67e54edf8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18135
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * mouse.c: mouse handling functions
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 #if defined(FEAT_MOUSE) || defined(PROTO)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 static int get_fpos_of_mouse(pos_T *mpos);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 * Get class of a character for selection: same class means same word.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 * 0: blank
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 * 1: punctuation groups
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 * 2: normal word character
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 * >2: multi-byte word character.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 static int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 get_mouse_class(char_u *p)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 int c;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 if (has_mbyte && MB_BYTE2LEN(p[0]) > 1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 return mb_get_class(p);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 c = *p;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 if (c == ' ' || c == '\t')
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 return 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 if (vim_iswordc(c))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 return 2;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 // There are a few special cases where we want certain combinations of
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 // characters to be considered as a single word. These are things like
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 // "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 // character is in its own class.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 return 1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 return c;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 * Move "pos" back to the start of the word it's in.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 static void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 find_start_of_word(pos_T *pos)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 char_u *line;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 int cclass;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 int col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 line = ml_get(pos->lnum);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 cclass = get_mouse_class(line + pos->col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 while (pos->col > 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 col = pos->col - 1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 col -= (*mb_head_off)(line, line + col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 if (get_mouse_class(line + col) != cclass)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 pos->col = col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 * Move "pos" forward to the end of the word it's in.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 * When 'selection' is "exclusive", the position is just after the word.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 static void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 find_end_of_word(pos_T *pos)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 char_u *line;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 int cclass;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 int col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 line = ml_get(pos->lnum);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 if (*p_sel == 'e' && pos->col > 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 --pos->col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 pos->col -= (*mb_head_off)(line, line + pos->col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 cclass = get_mouse_class(line + pos->col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 while (line[pos->col] != NUL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 col = pos->col + (*mb_ptr2len)(line + pos->col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 if (get_mouse_class(line + col) != cclass)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 if (*p_sel == 'e')
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 pos->col = col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 pos->col = col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 * Do the appropriate action for the current mouse click in the current mode.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 * Not used for Command-line mode.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 * Normal and Visual Mode:
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 * event modi- position visual change action
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 * fier cursor window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 * left press - yes end yes
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 * left press C yes end yes "^]" (2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 * left press S yes end (popup: extend) yes "*" (2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 * left drag - yes start if moved no
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 * left relse - yes start if moved no
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 * middle press - yes if not active no put register
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 * middle press - yes if active no yank and put
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 * right press - yes start or extend yes
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 * right press S yes no change yes "#" (2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 * right drag - yes extend no
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 * right relse - yes extend no
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 * Insert or Replace Mode:
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 * event modi- position visual change action
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 * fier cursor window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 * left press - yes (cannot be active) yes
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 * left press C yes (cannot be active) yes "CTRL-O^]" (2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 * left press S yes (cannot be active) yes "CTRL-O*" (2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 * left drag - yes start or extend (1) no CTRL-O (1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 * left relse - yes start or extend (1) no CTRL-O (1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 * middle press - no (cannot be active) no put register
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 * right press - yes start or extend yes CTRL-O
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 * right press S yes (cannot be active) yes "CTRL-O#" (2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 * (1) only if mouse pointer moved since press
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 * (2) only if click is in same buffer
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 * Return TRUE if start_arrow() should be called for edit mode.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 do_mouse(
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 oparg_T *oap, // operator argument, can be NULL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 int c, // K_LEFTMOUSE, etc
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 int dir, // Direction to 'put' if necessary
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 long count,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 int fixindent) // PUT_FIXINDENT if fixing indent necessary
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 static int do_always = FALSE; // ignore 'mouse' setting next time
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 static int got_click = FALSE; // got a click some time back
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 int which_button; // MOUSE_LEFT, _MIDDLE or _RIGHT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 int is_click = FALSE; // If FALSE it's a drag or release event
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 int is_drag = FALSE; // If TRUE it's a drag event
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 int jump_flags = 0; // flags for jump_to_mouse()
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 pos_T start_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 int moved; // Has cursor moved?
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 int in_status_line; // mouse in status line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 static int in_tab_line = FALSE; // mouse clicked in tab line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 int in_sep_line; // mouse in vertical separator line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 int c1, c2;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 #if defined(FEAT_FOLDING)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 pos_T save_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 win_T *old_curwin = curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 static pos_T orig_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 colnr_T leftcol, rightcol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 pos_T end_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 int diff;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 int old_active = VIsual_active;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 int old_mode = VIsual_mode;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 int regname;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 #if defined(FEAT_FOLDING)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 save_cursor = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 // When GUI is active, always recognize mouse events, otherwise:
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 // - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 // - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 // - For command line and insert mode 'mouse' is checked before calling
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 // do_mouse().
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 if (do_always)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 do_always = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 #ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 if (!gui.in_use)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 if (VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 if (!mouse_has(MOUSE_VISUAL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 else if (State == NORMAL && !mouse_has(MOUSE_NORMAL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 for (;;)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 if (is_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 // If the next character is the same mouse event then use that
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 // one. Speeds up dragging the status line.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 if (vpeekc() != NUL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 int nc;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 int save_mouse_row = mouse_row;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 int save_mouse_col = mouse_col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 // Need to get the character, peeking doesn't get the actual
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 // one.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 nc = safe_vgetc();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 if (c == nc)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 continue;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 vungetc(nc);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 mouse_row = save_mouse_row;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 mouse_col = save_mouse_col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 if (c == K_MOUSEMOVE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 // Mouse moved without a button pressed.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 #ifdef FEAT_BEVAL_TERM
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 ui_may_remove_balloon();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 if (p_bevalterm)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 profile_setlimit(p_bdlay, &bevalexpr_due);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 bevalexpr_due_set = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 popup_handle_mouse_moved();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 #ifdef FEAT_MOUSESHAPE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 // May have stopped dragging the status or separator line. The pointer is
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 // most likely still on the status or separator line.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 if (!is_drag && drag_status_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 drag_status_line = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 update_mouseshape(SHAPE_IDX_STATUS);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 if (!is_drag && drag_sep_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 drag_sep_line = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 update_mouseshape(SHAPE_IDX_VSEP);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 // Ignore drag and release events if we didn't get a click.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 if (is_click)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 got_click = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 if (!got_click) // didn't get click, ignore
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 if (!is_drag) // release, reset got_click
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 got_click = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 if (in_tab_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 in_tab_line = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 // CTRL right mouse button does CTRL-T
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 if (State & INSERT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 stuffcharReadbuff(Ctrl_O);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 if (count > 1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 stuffnumReadbuff(count);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 stuffcharReadbuff(Ctrl_T);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 got_click = FALSE; // ignore drag&release now
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 // CTRL only works with left mouse button
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 // When a modifier is down, ignore drag and release events, as well as
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 // multiple clicks and the middle mouse button.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 // Accept shift-leftmouse drags when 'mousemodel' is "popup.*".
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 if ((mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 | MOD_MASK_META))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 && (!is_click
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 || (mod_mask & MOD_MASK_MULTI_CLICK)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 || which_button == MOUSE_MIDDLE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 && !((mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 && mouse_model_popup()
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 && which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 && !((mod_mask & MOD_MASK_ALT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 && !mouse_model_popup()
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 && which_button == MOUSE_RIGHT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 )
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 // If the button press was used as the movement command for an operator
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 // (eg "d<MOUSE>"), or it is the middle button that is held down, ignore
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 // drag/release events.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 if (!is_click && which_button == MOUSE_MIDDLE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 if (oap != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 regname = oap->regname;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 regname = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 // Middle mouse button does a 'put' of the selected text
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 if (which_button == MOUSE_MIDDLE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 if (State == NORMAL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 // If an operator was pending, we don't know what the user wanted
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 // to do. Go back to normal mode: Clear the operator and beep().
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 if (oap != NULL && oap->op_type != OP_NOP)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 clearopbeep(oap);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 // If visual was active, yank the highlighted text and put it
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 // before the mouse pointer position.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 // In Select mode replace the highlighted text with the clipboard.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 if (VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 if (VIsual_select)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 stuffcharReadbuff(Ctrl_G);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 stuffReadbuff((char_u *)"\"+p");
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 stuffcharReadbuff('y');
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 stuffcharReadbuff(K_MIDDLEMOUSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 do_always = TRUE; // ignore 'mouse' setting next time
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 // The rest is below jump_to_mouse()
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 else if ((State & INSERT) == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 // Middle click in insert mode doesn't move the mouse, just insert the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 // contents of a register. '.' register is special, can't insert that
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 // with do_put().
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 // Also paste at the cursor if the current mode isn't in 'mouse' (only
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 // happens for the GUI).
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 if ((State & INSERT) || !mouse_has(MOUSE_NORMAL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 if (regname == '.')
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 insert_reg(regname, TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 #ifdef FEAT_CLIPBOARD
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 if (clip_star.available && regname == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 regname = '*';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 if ((State & REPLACE_FLAG) && !yank_register_mline(regname))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 insert_reg(regname, TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 do_put(regname, BACKWARD, 1L, fixindent | PUT_CURSEND);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 // Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 AppendCharToRedobuff(Ctrl_R);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 AppendCharToRedobuff(regname == 0 ? '"' : regname);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 // When dragging or button-up stay in the same window.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 if (!is_click)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 start_visual.lnum = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 // Check for clicking in the tab page line.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 if (mouse_row == 0 && firstwin->w_winrow > 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 if (is_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 if (in_tab_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 c1 = TabPageIdxs[mouse_col];
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 tabpage_move(c1 <= 0 ? 9999 : c1 < tabpage_index(curtab)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 ? c1 - 1 : c1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 // click in a tab selects that tab page
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 if (is_click
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 # ifdef FEAT_CMDWIN
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 && cmdwin_type == 0
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 && mouse_col < Columns)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 in_tab_line = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 c1 = TabPageIdxs[mouse_col];
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 if (c1 >= 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 // double click opens new page
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 end_visual_mode();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 tabpage_new();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 tabpage_move(c1 == 0 ? 9999 : c1 - 1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 // Go to specified tab page, or next one if not clicking
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 // on a label.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 goto_tabpage(c1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 // It's like clicking on the status line of a window.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 if (curwin != old_curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 end_visual_mode();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 tabpage_T *tp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 // Close the current or specified tab page.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 if (c1 == -999)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 tp = curtab;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 tp = find_tabpage(-c1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 if (tp == curtab)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 if (first_tabpage->tp_next != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 tabpage_close(FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 else if (tp != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 tabpage_close_other(tp, FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 return TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 else if (is_drag && in_tab_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 c1 = TabPageIdxs[mouse_col];
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 tabpage_move(c1 <= 0 ? 9999 : c1 - 1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 // When 'mousemodel' is "popup" or "popup_setpos", translate mouse events:
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 // right button up -> pop-up menu
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 // shift-left button -> right button
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 // alt-left button -> alt-right button
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 if (mouse_model_popup())
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 if (which_button == MOUSE_RIGHT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_PHOTON) \
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 || defined(FEAT_TERM_POPUP_MENU)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 # ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 if (gui.in_use)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 # if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 if (!is_click)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 // Ignore right button release events, only shows the popup
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 // menu on the button down event.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 # if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 if (is_click || is_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 // Ignore right button down and drag mouse events. Windows
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 // only shows the popup menu on the button up event.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 # if defined(FEAT_GUI) && defined(FEAT_TERM_POPUP_MENU)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 # if defined(FEAT_TERM_POPUP_MENU)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 if (!is_click)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 // Ignore right button release events, only shows the popup
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 // menu on the button down event.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 jump_flags = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 if (STRCMP(p_mousem, "popup_setpos") == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 // First set the cursor position before showing the popup
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 // menu.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 if (VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 pos_T m_pos;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 // set MOUSE_MAY_STOP_VIS if we are outside the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 // selection or the current window (might have false
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 // negative here)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 if (mouse_row < curwin->w_winrow
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 || mouse_row
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 > (curwin->w_winrow + curwin->w_height))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 jump_flags = MOUSE_MAY_STOP_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 else if (get_fpos_of_mouse(&m_pos) != IN_BUFFER)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 jump_flags = MOUSE_MAY_STOP_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 if ((LT_POS(curwin->w_cursor, VIsual)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 && (LT_POS(m_pos, curwin->w_cursor)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 || LT_POS(VIsual, m_pos)))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 || (LT_POS(VIsual, curwin->w_cursor)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 && (LT_POS(m_pos, VIsual)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 || LT_POS(curwin->w_cursor, m_pos))))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 jump_flags = MOUSE_MAY_STOP_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 else if (VIsual_mode == Ctrl_V)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 getvcols(curwin, &curwin->w_cursor, &VIsual,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 &leftcol, &rightcol);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 getvcol(curwin, &m_pos, NULL, &m_pos.col, NULL);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 if (m_pos.col < leftcol || m_pos.col > rightcol)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 jump_flags = MOUSE_MAY_STOP_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 jump_flags = MOUSE_MAY_STOP_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 if (jump_flags)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 jump_flags = jump_to_mouse(jump_flags, NULL, which_button);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 update_curbuf(VIsual_active ? INVERTED : VALID);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 setcursor();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 out_flush(); // Update before showing popup menu
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 # ifdef FEAT_MENU
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 show_popupmenu();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 got_click = FALSE; // ignore release events
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 return (jump_flags & CURSOR_MOVED) != 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 #else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 if (which_button == MOUSE_LEFT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 && (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT)))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 which_button = MOUSE_RIGHT;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 mod_mask &= ~MOD_MASK_SHIFT;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 if ((State & (NORMAL | INSERT))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 if (which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 if (is_click)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 // stop Visual mode for a left click in a window, but not when
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 // on a status line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 if (VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 jump_flags |= MOUSE_MAY_STOP_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 else if (mouse_has(MOUSE_VISUAL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 jump_flags |= MOUSE_MAY_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 else if (which_button == MOUSE_RIGHT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 if (is_click && VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 // Remember the start and end of visual before moving the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 // cursor.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 if (LT_POS(curwin->w_cursor, VIsual))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 start_visual = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 end_visual = VIsual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 start_visual = VIsual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 end_visual = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 jump_flags |= MOUSE_FOCUS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 if (mouse_has(MOUSE_VISUAL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 jump_flags |= MOUSE_MAY_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 // If an operator is pending, ignore all drags and releases until the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 // next mouse click.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 if (!is_drag && oap != NULL && oap->op_type != OP_NOP)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 got_click = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 oap->motion_type = MCHAR;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 // When releasing the button let jump_to_mouse() know.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 if (!is_click && !is_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 jump_flags |= MOUSE_RELEASED;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 // JUMP!
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 jump_flags = jump_to_mouse(jump_flags,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 oap == NULL ? NULL : &(oap->inclusive), which_button);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 #ifdef FEAT_MENU
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 // A click in the window toolbar has no side effects.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 if (jump_flags & MOUSE_WINBAR)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 moved = (jump_flags & CURSOR_MOVED);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 in_status_line = (jump_flags & IN_STATUS_LINE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 in_sep_line = (jump_flags & IN_SEP_LINE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 #ifdef FEAT_NETBEANS_INTG
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 if (isNetbeansBuffer(curbuf)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 && !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE)))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 int key = KEY2TERMCAP1(c);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 || key == (int)KE_RIGHTRELEASE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 netbeans_button_release(which_button);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 // When jumping to another window, clear a pending operator. That's a bit
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 // friendlier than beeping and not jumping to that window.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 clearop(oap);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 if (mod_mask == 0
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 && !is_drag
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 && (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 && which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 // open or close a fold at this line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 if (jump_flags & MOUSE_FOLD_OPEN)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 openFold(curwin->w_cursor.lnum, 1L);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 closeFold(curwin->w_cursor.lnum, 1L);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 // don't move the cursor if still in the same window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 if (curwin == old_curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 curwin->w_cursor = save_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 if ((jump_flags & IN_OTHER_WIN) && !VIsual_active && clip_star.available)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 clip_modeless(which_button, is_click, is_drag);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 // Set global flag that we are extending the Visual area with mouse
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 // dragging; temporarily minimize 'scrolloff'.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 if (VIsual_active && is_drag && get_scrolloff_value())
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 // In the very first line, allow scrolling one line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 if (mouse_row == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 mouse_dragging = 2;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 mouse_dragging = 1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 // When dragging the mouse above the window, scroll down.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 if (is_drag && mouse_row < 0 && !in_status_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 scroll_redraw(FALSE, 1L);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 mouse_row = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 if (start_visual.lnum) // right click in visual mode
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 // When ALT is pressed make Visual mode blockwise.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 if (mod_mask & MOD_MASK_ALT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 VIsual_mode = Ctrl_V;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 // In Visual-block mode, divide the area in four, pick up the corner
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 // that is in the quarter that the cursor is in.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 if (VIsual_mode == Ctrl_V)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 if (curwin->w_curswant > (leftcol + rightcol) / 2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 end_visual.col = leftcol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 end_visual.col = rightcol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 if (curwin->w_cursor.lnum >=
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 (start_visual.lnum + end_visual.lnum) / 2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 end_visual.lnum = start_visual.lnum;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 // move VIsual to the right column
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 start_visual = curwin->w_cursor; // save the cursor pos
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 curwin->w_cursor = end_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 coladvance(end_visual.col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 VIsual = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 curwin->w_cursor = start_visual; // restore the cursor
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 // If the click is before the start of visual, change the start.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 // If the click is after the end of visual, change the end. If
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 // the click is inside the visual, change the closest side.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 if (LT_POS(curwin->w_cursor, start_visual))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 VIsual = end_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 else if (LT_POS(end_visual, curwin->w_cursor))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 VIsual = start_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 // In the same line, compare column number
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 if (end_visual.lnum == start_visual.lnum)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 if (curwin->w_cursor.col - start_visual.col >
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 end_visual.col - curwin->w_cursor.col)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 VIsual = start_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 VIsual = end_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 // In different lines, compare line number
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 diff = (curwin->w_cursor.lnum - start_visual.lnum) -
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 (end_visual.lnum - curwin->w_cursor.lnum);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 if (diff > 0) // closest to end
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 VIsual = start_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 else if (diff < 0) // closest to start
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 VIsual = end_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 else // in the middle line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 if (curwin->w_cursor.col <
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 (start_visual.col + end_visual.col) / 2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 VIsual = end_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 VIsual = start_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 // If Visual mode started in insert mode, execute "CTRL-O"
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 else if ((State & INSERT) && VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 stuffcharReadbuff(Ctrl_O);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 // Middle mouse click: Put text before cursor.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 if (which_button == MOUSE_MIDDLE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 #ifdef FEAT_CLIPBOARD
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 if (clip_star.available && regname == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 regname = '*';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 if (yank_register_mline(regname))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 if (mouse_past_bottom)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 dir = FORWARD;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 else if (mouse_past_eol)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 dir = FORWARD;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 if (fixindent)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 c1 = (dir == BACKWARD) ? '[' : ']';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 c2 = 'p';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 c1 = (dir == FORWARD) ? 'p' : 'P';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 c2 = NUL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 prep_redo(regname, count, NUL, c1, NUL, c2, NUL);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 // Remember where the paste started, so in edit() Insstart can be set
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 // to this position
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 if (restart_edit != 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 where_paste_started = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 do_put(regname, dir, count, fixindent | PUT_CURSEND);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 #if defined(FEAT_QUICKFIX)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 // Ctrl-Mouse click or double click in a quickfix window jumps to the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 // error under the mouse pointer.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 else if (((mod_mask & MOD_MASK_CTRL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 || (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 && bt_quickfix(curbuf))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 if (curwin->w_llist_ref == NULL) // quickfix window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 do_cmdline_cmd((char_u *)".cc");
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 else // location list window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 do_cmdline_cmd((char_u *)".ll");
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 got_click = FALSE; // ignore drag&release now
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 // Ctrl-Mouse click (or double click in a help window) jumps to the tag
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 // under the mouse pointer.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 else if ((mod_mask & MOD_MASK_CTRL) || (curbuf->b_help
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 if (State & INSERT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 stuffcharReadbuff(Ctrl_O);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 stuffcharReadbuff(Ctrl_RSB);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 got_click = FALSE; // ignore drag&release now
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 // Shift-Mouse click searches for the next occurrence of the word under
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 // the mouse pointer
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 else if ((mod_mask & MOD_MASK_SHIFT))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 if ((State & INSERT) || (VIsual_active && VIsual_select))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 stuffcharReadbuff(Ctrl_O);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 if (which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 stuffcharReadbuff('*');
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 else // MOUSE_RIGHT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 stuffcharReadbuff('#');
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 // Handle double clicks, unless on status line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 else if (in_status_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 #ifdef FEAT_MOUSESHAPE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 if ((is_drag || is_click) && !drag_status_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 drag_status_line = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 update_mouseshape(-1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 else if (in_sep_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 #ifdef FEAT_MOUSESHAPE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 if ((is_drag || is_click) && !drag_sep_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 drag_sep_line = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 update_mouseshape(-1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 && mouse_has(MOUSE_VISUAL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 if (is_click || !VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 if (VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 orig_cursor = VIsual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 check_visual_highlight();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 VIsual = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 orig_cursor = VIsual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 VIsual_active = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 VIsual_reselect = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 // start Select mode if 'selectmode' contains "mouse"
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 may_start_select('o');
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 setmouse();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 // Double click with ALT pressed makes it blockwise.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 if (mod_mask & MOD_MASK_ALT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 VIsual_mode = Ctrl_V;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 VIsual_mode = 'v';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 VIsual_mode = 'V';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 VIsual_mode = Ctrl_V;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 #ifdef FEAT_CLIPBOARD
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 // Make sure the clipboard gets updated. Needed because start and
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 // end may still be the same, and the selection needs to be owned
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 clip_star.vmode = NUL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 // A double click selects a word or a block.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 pos_T *pos = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 int gc;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 if (is_click)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 // If the character under the cursor (skipping white space) is
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 // not a word character, try finding a match and select a (),
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 // {}, [], #if/#endif, etc. block.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 end_visual = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 while (gc = gchar_pos(&end_visual), VIM_ISWHITE(gc))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 inc(&end_visual);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 if (oap != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 oap->motion_type = MCHAR;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 if (oap != NULL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 && VIsual_mode == 'v'
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 && !vim_iswordc(gchar_pos(&end_visual))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 && EQUAL_POS(curwin->w_cursor, VIsual)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 && (pos = findmatch(oap, NUL)) != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 curwin->w_cursor = *pos;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 if (oap->motion_type == MLINE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 VIsual_mode = 'V';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 else if (*p_sel == 'e')
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 if (LT_POS(curwin->w_cursor, VIsual))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 ++VIsual.col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 ++curwin->w_cursor.col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 if (pos == NULL && (is_click || is_drag))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 // When not found a match or when dragging: extend to include
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 // a word.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 if (LT_POS(curwin->w_cursor, orig_cursor))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 find_start_of_word(&curwin->w_cursor);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 find_end_of_word(&VIsual);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 find_start_of_word(&VIsual);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 if (*p_sel == 'e' && *ml_get_cursor() != NUL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 curwin->w_cursor.col +=
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 (*mb_ptr2len)(ml_get_cursor());
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 find_end_of_word(&curwin->w_cursor);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 curwin->w_set_curswant = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 if (is_click)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 redraw_curbuf_later(INVERTED); // update the inversion
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 else if (VIsual_active && !old_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 if (mod_mask & MOD_MASK_ALT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 VIsual_mode = Ctrl_V;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 VIsual_mode = 'v';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 // If Visual mode changed show it later.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 if ((!VIsual_active && old_active && mode_displayed)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 || (VIsual_active && p_smd && msg_silent == 0
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 && (!old_active || VIsual_mode != old_mode)))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 redraw_cmdline = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 return moved;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 ins_mouse(int c)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 pos_T tpos;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 win_T *old_curwin = curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 # ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 // When GUI is active, also move/paste when 'mouse' is empty
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 if (!gui.in_use)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 if (!mouse_has(MOUSE_INSERT))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 return;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 undisplay_dollar();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 tpos = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 if (do_mouse(NULL, c, BACKWARD, 1L, 0))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 win_T *new_curwin = curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 if (curwin != old_curwin && win_valid(old_curwin))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 // Mouse took us to another window. We need to go back to the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 // previous one to stop insert there properly.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 curwin = old_curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 curbuf = curwin->w_buffer;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 #ifdef FEAT_JOB_CHANNEL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 if (bt_prompt(curbuf))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 // Restart Insert mode when re-entering the prompt buffer.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 curbuf->b_prompt_insert = 'A';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 start_arrow(curwin == old_curwin ? &tpos : NULL);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 if (curwin != new_curwin && win_valid(new_curwin))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 curwin = new_curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 curbuf = curwin->w_buffer;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 # ifdef FEAT_CINDENT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 set_can_cindent(TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 // redraw status lines (in case another window became active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 redraw_statuslines();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 ins_mousescroll(int dir)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 pos_T tpos;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 win_T *old_curwin = curwin, *wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 int did_scroll = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 tpos = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 if (mouse_row >= 0 && mouse_col >= 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 int row, col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 row = mouse_row;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 col = mouse_col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 // find the window at the pointer coordinates
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 wp = mouse_find_win(&row, &col, FIND_POPUP);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 if (wp == NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 return;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 curwin = wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 curbuf = curwin->w_buffer;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 if (curwin == old_curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 undisplay_dollar();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 // Don't scroll the window in which completion is being done.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 if (!pum_visible() || curwin != old_curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 if (dir == MSCR_DOWN || dir == MSCR_UP)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 scroll_redraw(dir,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 (long)(curwin->w_botline - curwin->w_topline));
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 scroll_redraw(dir, 3L);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 # ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 if (WIN_IS_POPUP(curwin))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 popup_set_firstline(curwin);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 #ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 int val, step = 6;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 step = curwin->w_width;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 val = curwin->w_leftcol + (dir == MSCR_RIGHT ? -step : step);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 if (val < 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 val = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 gui_do_horiz_scroll(val, TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 did_scroll = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 curwin->w_redr_status = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 curwin = old_curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 curbuf = curwin->w_buffer;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 // The popup menu may overlay the window, need to redraw it.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 // TODO: Would be more efficient to only redraw the windows that are
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 // overlapped by the popup menu.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 if (pum_visible() && did_scroll)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 redraw_all_later(NOT_VALID);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 ins_compl_show_pum();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 if (!EQUAL_POS(curwin->w_cursor, tpos))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 start_arrow(&tpos);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 # ifdef FEAT_CINDENT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 set_can_cindent(TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 * Return TRUE if "c" is a mouse key.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 is_mouse_key(int c)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 return c == K_LEFTMOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 || c == K_LEFTMOUSE_NM
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 || c == K_LEFTDRAG
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 || c == K_LEFTRELEASE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 || c == K_LEFTRELEASE_NM
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 || c == K_MOUSEMOVE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 || c == K_MIDDLEMOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 || c == K_MIDDLEDRAG
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 || c == K_MIDDLERELEASE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 || c == K_RIGHTMOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 || c == K_RIGHTDRAG
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 || c == K_RIGHTRELEASE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 || c == K_MOUSEDOWN
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 || c == K_MOUSEUP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 || c == K_MOUSELEFT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 || c == K_MOUSERIGHT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 || c == K_X1MOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 || c == K_X1DRAG
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 || c == K_X1RELEASE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 || c == K_X2MOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 || c == K_X2DRAG
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 || c == K_X2RELEASE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 static struct mousetable
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 int pseudo_code; // Code for pseudo mouse event
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 int button; // Which mouse button is it?
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 int is_click; // Is it a mouse button click event?
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 int is_drag; // Is it a mouse drag event?
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 } mouse_table[] =
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 {(int)KE_LEFTMOUSE, MOUSE_LEFT, TRUE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 #ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 {(int)KE_LEFTMOUSE_NM, MOUSE_LEFT, TRUE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 {(int)KE_LEFTDRAG, MOUSE_LEFT, FALSE, TRUE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 {(int)KE_LEFTRELEASE, MOUSE_LEFT, FALSE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 #ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 {(int)KE_LEFTRELEASE_NM, MOUSE_LEFT, FALSE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 {(int)KE_MIDDLEMOUSE, MOUSE_MIDDLE, TRUE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 {(int)KE_MIDDLEDRAG, MOUSE_MIDDLE, FALSE, TRUE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 {(int)KE_MIDDLERELEASE, MOUSE_MIDDLE, FALSE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 {(int)KE_RIGHTMOUSE, MOUSE_RIGHT, TRUE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 {(int)KE_RIGHTDRAG, MOUSE_RIGHT, FALSE, TRUE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 {(int)KE_RIGHTRELEASE, MOUSE_RIGHT, FALSE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 {(int)KE_X1MOUSE, MOUSE_X1, TRUE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 {(int)KE_X1DRAG, MOUSE_X1, FALSE, TRUE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 {(int)KE_X1RELEASE, MOUSE_X1, FALSE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 {(int)KE_X2MOUSE, MOUSE_X2, TRUE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 {(int)KE_X2DRAG, MOUSE_X2, FALSE, TRUE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 {(int)KE_X2RELEASE, MOUSE_X2, FALSE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 // DRAG without CLICK
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 {(int)KE_MOUSEMOVE, MOUSE_RELEASE, FALSE, TRUE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 // RELEASE without CLICK
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 {(int)KE_IGNORE, MOUSE_RELEASE, FALSE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 {0, 0, 0, 0},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 };
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 * Look up the given mouse code to return the relevant information in the other
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 * arguments. Return which button is down or was released.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 get_mouse_button(int code, int *is_click, int *is_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 int i;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 for (i = 0; mouse_table[i].pseudo_code; i++)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 if (code == mouse_table[i].pseudo_code)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 *is_click = mouse_table[i].is_click;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 *is_drag = mouse_table[i].is_drag;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 return mouse_table[i].button;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 return 0; // Shouldn't get here
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 * Return the appropriate pseudo mouse event token (KE_LEFTMOUSE etc) based on
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 * the given information about which mouse button is down, and whether the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 * mouse was clicked, dragged or released.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 get_pseudo_mouse_code(
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 int button, // eg MOUSE_LEFT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 int is_click,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 int is_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 int i;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 for (i = 0; mouse_table[i].pseudo_code; i++)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 if (button == mouse_table[i].button
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 && is_click == mouse_table[i].is_click
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 && is_drag == mouse_table[i].is_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 #ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 // Trick: a non mappable left click and release has mouse_col -1
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 // or added MOUSE_COLOFF. Used for 'mousefocus' in
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 // gui_mouse_moved()
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 if (mouse_col < 0 || mouse_col > MOUSE_COLOFF)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 if (mouse_col < 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 mouse_col = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 mouse_col -= MOUSE_COLOFF;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 if (mouse_table[i].pseudo_code == (int)KE_LEFTMOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 return (int)KE_LEFTMOUSE_NM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 if (mouse_table[i].pseudo_code == (int)KE_LEFTRELEASE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 return (int)KE_LEFTRELEASE_NM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 return mouse_table[i].pseudo_code;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 return (int)KE_IGNORE; // not recognized, ignore it
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 # ifdef FEAT_MOUSE_TTY
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 # define HMT_NORMAL 1
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 # define HMT_NETTERM 2
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 # define HMT_DEC 4
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 # define HMT_JSBTERM 8
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 # define HMT_PTERM 16
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 # define HMT_URXVT 32
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 # define HMT_GPM 64
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 # define HMT_SGR 128
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 # define HMT_SGR_REL 256
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 static int has_mouse_termcode = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 # if (!defined(UNIX) || defined(FEAT_MOUSE_TTY)) || defined(PROTO)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 set_mouse_termcode(
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 int n, // KS_MOUSE, KS_NETTERM_MOUSE or KS_DEC_MOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 char_u *s)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 char_u name[2];
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 name[0] = n;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 name[1] = KE_FILLER;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 add_termcode(name, s, FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 # ifdef FEAT_MOUSE_TTY
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 # ifdef FEAT_MOUSE_JSB
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 if (n == KS_JSBTERM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 has_mouse_termcode |= HMT_JSBTERM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250 # ifdef FEAT_MOUSE_NET
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 if (n == KS_NETTERM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 has_mouse_termcode |= HMT_NETTERM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 # ifdef FEAT_MOUSE_DEC
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 if (n == KS_DEC_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 has_mouse_termcode |= HMT_DEC;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 # ifdef FEAT_MOUSE_PTERM
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 if (n == KS_PTERM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 has_mouse_termcode |= HMT_PTERM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 # ifdef FEAT_MOUSE_URXVT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 if (n == KS_URXVT_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 has_mouse_termcode |= HMT_URXVT;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 # ifdef FEAT_MOUSE_GPM
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 if (n == KS_GPM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 has_mouse_termcode |= HMT_GPM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 if (n == KS_SGR_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 has_mouse_termcode |= HMT_SGR;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 else if (n == KS_SGR_MOUSE_RELEASE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 has_mouse_termcode |= HMT_SGR_REL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 has_mouse_termcode |= HMT_NORMAL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 # if ((defined(UNIX) || defined(VMS)) \
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 && defined(FEAT_MOUSE_TTY)) || defined(PROTO)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 del_mouse_termcode(
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 int n) // KS_MOUSE, KS_NETTERM_MOUSE or KS_DEC_MOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 char_u name[2];
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 name[0] = n;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 name[1] = KE_FILLER;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 del_termcode(name);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 # ifdef FEAT_MOUSE_TTY
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 # ifdef FEAT_MOUSE_JSB
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 if (n == KS_JSBTERM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 has_mouse_termcode &= ~HMT_JSBTERM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 # ifdef FEAT_MOUSE_NET
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 if (n == KS_NETTERM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 has_mouse_termcode &= ~HMT_NETTERM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 # ifdef FEAT_MOUSE_DEC
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 if (n == KS_DEC_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 has_mouse_termcode &= ~HMT_DEC;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 # ifdef FEAT_MOUSE_PTERM
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 if (n == KS_PTERM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 has_mouse_termcode &= ~HMT_PTERM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 # ifdef FEAT_MOUSE_URXVT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 if (n == KS_URXVT_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 has_mouse_termcode &= ~HMT_URXVT;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 # ifdef FEAT_MOUSE_GPM
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 if (n == KS_GPM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 has_mouse_termcode &= ~HMT_GPM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 if (n == KS_SGR_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 has_mouse_termcode &= ~HMT_SGR;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 else if (n == KS_SGR_MOUSE_RELEASE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 has_mouse_termcode &= ~HMT_SGR_REL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 has_mouse_termcode &= ~HMT_NORMAL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 * setmouse() - switch mouse on/off depending on current mode and 'mouse'
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 setmouse(void)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 # ifdef FEAT_MOUSE_TTY
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 int checkfor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 # ifdef FEAT_MOUSESHAPE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 update_mouseshape(-1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 # ifdef FEAT_MOUSE_TTY // Should be outside proc, but may break MOUSESHAPE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 # ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 // In the GUI the mouse is always enabled.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 if (gui.in_use)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 return;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 // be quick when mouse is off
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 if (*p_mouse == NUL || has_mouse_termcode == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 return;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 // don't switch mouse on when not in raw mode (Ex mode)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 if (cur_tmode != TMODE_RAW)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 mch_setmouse(FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 return;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 if (VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 checkfor = MOUSE_VISUAL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 else if (State == HITRETURN || State == ASKMORE || State == SETWSIZE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 checkfor = MOUSE_RETURN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 else if (State & INSERT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 checkfor = MOUSE_INSERT;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 else if (State & CMDLINE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 checkfor = MOUSE_COMMAND;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 else if (State == CONFIRM || State == EXTERNCMD)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 checkfor = ' '; // don't use mouse for ":confirm" or ":!cmd"
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 checkfor = MOUSE_NORMAL; // assume normal mode
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 if (mouse_has(checkfor))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 mch_setmouse(TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 mch_setmouse(FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 * Return TRUE if
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 * - "c" is in 'mouse', or
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 * - 'a' is in 'mouse' and "c" is in MOUSE_A, or
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 * - the current buffer is a help file and 'h' is in 'mouse' and we are in a
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 * normal editing mode (not at hit-return message).
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 mouse_has(int c)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 char_u *p;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 for (p = p_mouse; *p; ++p)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 switch (*p)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 case 'a': if (vim_strchr((char_u *)MOUSE_A, c) != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 return TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 case MOUSE_HELP: if (c != MOUSE_RETURN && curbuf->b_help)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 return TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 default: if (c == *p) return TRUE; break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 * Return TRUE when 'mousemodel' is set to "popup" or "popup_setpos".
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 mouse_model_popup(void)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 return (p_mousem[0] == 'p');
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 * Move the cursor to the specified row and column on the screen.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 * Change current window if necessary. Returns an integer with the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 * CURSOR_MOVED bit set if the cursor has moved or unset otherwise.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428 * The MOUSE_FOLD_CLOSE bit is set when clicked on the '-' in a fold column.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 * The MOUSE_FOLD_OPEN bit is set when clicked on the '+' in a fold column.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 * If flags has MOUSE_FOCUS, then the current window will not be changed, and
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 * if the mouse is outside the window then the text will scroll, or if the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 * mouse was previously on a status line, then the status line may be dragged.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 * If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 * cursor is moved unless the cursor was on a status line.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 * This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 * IN_SEP_LINE depending on where the cursor was clicked.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 * If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 * the mouse is on the status line of the same window.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 * If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 * the last call.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 * If flags has MOUSE_SETPOS, nothing is done, only the current position is
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 * remembered.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 jump_to_mouse(
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 int flags,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 int *inclusive, // used for inclusive operator, can be NULL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 int which_button) // MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 static int on_status_line = 0; // #lines below bottom of window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 static int on_sep_line = 0; // on separator right of window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 #ifdef FEAT_MENU
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458 static int in_winbar = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461 static int in_popup_win = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 static win_T *click_in_popup_win = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 static int prev_row = -1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 static int prev_col = -1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 static win_T *dragwin = NULL; // window being dragged
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 static int did_drag = FALSE; // drag was noticed
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 win_T *wp, *old_curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 pos_T old_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 int count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472 int first;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 int row = mouse_row;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 int col = mouse_col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 int mouse_char;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 mouse_past_bottom = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 mouse_past_eol = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 if (flags & MOUSE_RELEASED)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 // On button release we may change window focus if positioned on a
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 // status line and no dragging happened.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 if (dragwin != NULL && !did_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 flags &= ~(MOUSE_FOCUS | MOUSE_DID_MOVE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 dragwin = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 did_drag = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 if (click_in_popup_win != NULL && popup_dragwin == NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 popup_close_for_mouse_click(click_in_popup_win);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 popup_dragwin = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 click_in_popup_win = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 if ((flags & MOUSE_DID_MOVE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 && prev_row == mouse_row
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 && prev_col == mouse_col)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 retnomove:
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 // before moving the cursor for a left click which is NOT in a status
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 // line, stop Visual mode
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 if (on_status_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 return IN_STATUS_LINE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 if (on_sep_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 return IN_SEP_LINE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 #ifdef FEAT_MENU
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 if (in_winbar)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 // A quick second click may arrive as a double-click, but we use it
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514 // as a second click in the WinBar.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 if ((mod_mask & MOD_MASK_MULTI_CLICK) && !(flags & MOUSE_RELEASED))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 wp = mouse_find_win(&row, &col, FAIL_POPUP);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 if (wp == NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 winbar_click(wp, col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 return IN_OTHER_WIN | MOUSE_WINBAR;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 if (flags & MOUSE_MAY_STOP_VIS)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 end_visual_mode();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 redraw_curbuf_later(INVERTED); // delete the inversion
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 #if defined(FEAT_CMDWIN) && defined(FEAT_CLIPBOARD)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 // Continue a modeless selection in another window.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 if (cmdwin_type != 0 && row < curwin->w_winrow)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 return IN_OTHER_WIN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 // Continue a modeless selection in a popup window or dragging it.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 if (in_popup_win)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 click_in_popup_win = NULL; // don't close it on release
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 if (popup_dragwin != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 // dragging a popup window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 popup_drag(popup_dragwin);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 return IN_OTHER_WIN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 return IN_BUFFER;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 prev_row = mouse_row;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 prev_col = mouse_col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 if (flags & MOUSE_SETPOS)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 goto retnomove; // ugly goto...
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 // Remember the character under the mouse, it might be a '-' or '+' in the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 // fold column.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561 if (row >= 0 && row < Rows && col >= 0 && col <= Columns
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 && ScreenLines != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 mouse_char = ScreenLines[LineOffset[row] + col];
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 mouse_char = ' ';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 old_curwin = curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1569 old_cursor = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 if (!(flags & MOUSE_FOCUS))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 if (row < 0 || col < 0) // check if it makes sense
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 // find the window where the row is in and adjust "row" and "col" to be
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 // relative to top-left of the window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 wp = mouse_find_win(&row, &col, FIND_POPUP);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 if (wp == NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 dragwin = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 // Click in a popup window may start dragging or modeless selection,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585 // but not much else.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 if (WIN_IS_POPUP(wp))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 on_sep_line = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 in_popup_win = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 if (which_button == MOUSE_LEFT && popup_close_if_on_X(wp, row, col))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 else if ((wp->w_popup_flags & (POPF_DRAG | POPF_RESIZE))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 && popup_on_border(wp, row, col))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597 popup_dragwin = wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 popup_start_drag(wp, row, col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 // Only close on release, otherwise it's not possible to drag or do
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602 // modeless selection.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 else if (wp->w_popup_close == POPCLOSE_CLICK
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 && which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 click_in_popup_win = wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608 else if (which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 // If the click is in the scrollbar, may scroll up/down.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 popup_handle_scrollbar_click(wp, row, col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611 # ifdef FEAT_CLIPBOARD
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 return IN_OTHER_WIN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613 # else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617 in_popup_win = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618 popup_dragwin = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1619 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620 #ifdef FEAT_MENU
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 if (row == -1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623 // A click in the window toolbar does not enter another window or
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 // change Visual highlighting.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625 winbar_click(wp, col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 in_winbar = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 return IN_OTHER_WIN | MOUSE_WINBAR;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 in_winbar = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 // winpos and height may change in win_enter()!
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633 if (row >= wp->w_height) // In (or below) status line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635 on_status_line = row - wp->w_height + 1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636 dragwin = wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 on_status_line = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 if (col >= wp->w_width) // In separator line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 on_sep_line = col - wp->w_width + 1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 dragwin = wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1646 on_sep_line = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 // The rightmost character of the status line might be a vertical
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 // separator character if there is no connecting window to the right.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 if (on_status_line && on_sep_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 if (stl_connected(wp))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 on_sep_line = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 on_status_line = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 // Before jumping to another buffer, or moving the cursor for a left
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 // click, stop Visual mode.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 if (VIsual_active
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 && (wp->w_buffer != curwin->w_buffer
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 || (!on_status_line && !on_sep_line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 && (
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 # ifdef FEAT_RIGHTLEFT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 wp->w_p_rl ? col < wp->w_width - wp->w_p_fdc :
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 col >= wp->w_p_fdc
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 # ifdef FEAT_CMDWIN
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 + (cmdwin_type == 0 && wp == curwin ? 0 : 1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 )
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 && (flags & MOUSE_MAY_STOP_VIS))))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676 end_visual_mode();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 redraw_curbuf_later(INVERTED); // delete the inversion
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 #ifdef FEAT_CMDWIN
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 if (cmdwin_type != 0 && wp != curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 // A click outside the command-line window: Use modeless
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 // selection if possible. Allow dragging the status lines.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 on_sep_line = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 # ifdef FEAT_CLIPBOARD
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 if (on_status_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 return IN_STATUS_LINE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 return IN_OTHER_WIN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689 # else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690 row = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691 col += wp->w_wincol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 wp = curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 // Only change window focus when not clicking on or dragging the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 // status line. Do change focus when releasing the mouse button
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698 // (MOUSE_FOCUS was set above if we dragged first).
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 if (dragwin == NULL || (flags & MOUSE_RELEASED))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 win_enter(wp, TRUE); // can make wp invalid!
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 if (curwin != old_curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 #ifdef CHECK_DOUBLE_CLICK
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 // set topline, to be able to check for double click ourselves
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706 set_mouse_topline(curwin);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 #ifdef FEAT_TERMINAL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 // when entering a terminal window may change state
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 term_win_entered();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 if (on_status_line) // In (or below) status line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 // Don't use start_arrow() if we're in the same window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 if (curwin == old_curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 return IN_STATUS_LINE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 return IN_STATUS_LINE | CURSOR_MOVED;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 if (on_sep_line) // In (or below) status line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 // Don't use start_arrow() if we're in the same window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 if (curwin == old_curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 return IN_SEP_LINE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 return IN_SEP_LINE | CURSOR_MOVED;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1728 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730 curwin->w_cursor.lnum = curwin->w_topline;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 #ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1732 // remember topline, needed for double click
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1733 gui_prev_topline = curwin->w_topline;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1734 # ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1735 gui_prev_topfill = curwin->w_topfill;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739 else if (on_status_line && which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1741 if (dragwin != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1743 // Drag the status line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744 count = row - dragwin->w_winrow - dragwin->w_height + 1
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745 - on_status_line;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 win_drag_status_line(dragwin, count);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 did_drag |= count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 return IN_STATUS_LINE; // Cursor didn't move
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1751 else if (on_sep_line && which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753 if (dragwin != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 // Drag the separator column
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1756 count = col - dragwin->w_wincol - dragwin->w_width + 1
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 - on_sep_line;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758 win_drag_vsep_line(dragwin, count);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1759 did_drag |= count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1761 return IN_SEP_LINE; // Cursor didn't move
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 #ifdef FEAT_MENU
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1764 else if (in_winbar)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1765 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 // After a click on the window toolbar don't start Visual mode.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767 return IN_OTHER_WIN | MOUSE_WINBAR;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770 else // keep_window_focus must be TRUE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 // before moving the cursor for a left click, stop Visual mode
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773 if (flags & MOUSE_MAY_STOP_VIS)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1774 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1775 end_visual_mode();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776 redraw_curbuf_later(INVERTED); // delete the inversion
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1778
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 #if defined(FEAT_CMDWIN) && defined(FEAT_CLIPBOARD)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780 // Continue a modeless selection in another window.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1781 if (cmdwin_type != 0 && row < curwin->w_winrow)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1782 return IN_OTHER_WIN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1784 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785 if (in_popup_win)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787 if (popup_dragwin != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1788 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 // dragging a popup window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 popup_drag(popup_dragwin);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1792 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1793 // continue a modeless selection in a popup window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794 click_in_popup_win = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 return IN_OTHER_WIN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1796 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1797 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799 row -= W_WINROW(curwin);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1800 col -= curwin->w_wincol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1802 // When clicking beyond the end of the window, scroll the screen.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 // Scroll by however many rows outside the window we are.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1804 if (row < 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1805 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 count = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 for (first = TRUE; curwin->w_topline > 1; )
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1808 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811 ++count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1813 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1814 count += plines(curwin->w_topline - 1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1815 if (!first && count > -row)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1816 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1817 first = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1819 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1821 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1823 ++curwin->w_topfill;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1826 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827 --curwin->w_topline;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1828 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 curwin->w_topfill = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1831 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834 check_topfill(curwin, FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 curwin->w_valid &=
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1837 ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 redraw_later(VALID);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839 row = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841 else if (row >= curwin->w_height)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843 count = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1844 for (first = TRUE; curwin->w_topline < curbuf->b_ml.ml_line_count; )
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1847 if (curwin->w_topfill > 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1848 ++count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1851 count += plines(curwin->w_topline);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 if (!first && count > row - curwin->w_height + 1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 first = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856 if (hasFolding(curwin->w_topline, NULL, &curwin->w_topline)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1857 && curwin->w_topline == curbuf->b_ml.ml_line_count)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861 if (curwin->w_topfill > 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862 --curwin->w_topfill;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 ++curwin->w_topline;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 curwin->w_topfill =
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 diff_check_fill(curwin, curwin->w_topline);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 check_topfill(curwin, FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876 redraw_later(VALID);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 curwin->w_valid &=
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 row = curwin->w_height - 1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 else if (row == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 // When dragging the mouse, while the text has been scrolled up as
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 // far as it goes, moving the mouse in the top line should scroll
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 // the text down (done later when recomputing w_topline).
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 if (mouse_dragging > 0
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 && curwin->w_cursor.lnum
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 == curwin->w_buffer->b_ml.ml_line_count
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1889 && curwin->w_cursor.lnum == curwin->w_topline)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1890 curwin->w_valid &= ~(VALID_TOPLINE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1891 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895 // Check for position outside of the fold column.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896 if (
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1897 # ifdef FEAT_RIGHTLEFT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 curwin->w_p_rl ? col < curwin->w_width - curwin->w_p_fdc :
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1900 col >= curwin->w_p_fdc
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1901 # ifdef FEAT_CMDWIN
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1902 + (cmdwin_type == 0 ? 0 : 1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1904 )
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1905 mouse_char = ' ';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1907
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 // compute the position in the buffer line from the posn on the screen
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1909 if (mouse_comp_pos(curwin, &row, &col, &curwin->w_cursor.lnum, NULL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1910 mouse_past_bottom = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912 // Start Visual mode before coladvance(), for when 'sel' != "old"
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1913 if ((flags & MOUSE_MAY_VIS) && !VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1915 check_visual_highlight();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 VIsual = old_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 VIsual_active = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 VIsual_reselect = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919 // if 'selectmode' contains "mouse", start Select mode
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1920 may_start_select('o');
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921 setmouse();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1922 if (p_smd && msg_silent == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 redraw_cmdline = TRUE; // show visual mode later
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1925
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926 curwin->w_curswant = col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 curwin->w_set_curswant = FALSE; // May still have been TRUE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 if (coladvance(col) == FAIL) // Mouse click beyond end of line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 if (inclusive != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 *inclusive = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 mouse_past_eol = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 else if (inclusive != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 *inclusive = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937 count = IN_BUFFER;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 if (curwin != old_curwin || curwin->w_cursor.lnum != old_cursor.lnum
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1939 || curwin->w_cursor.col != old_cursor.col)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940 count |= CURSOR_MOVED; // Cursor has moved
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 # ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 if (mouse_char == '+')
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1944 count |= MOUSE_FOLD_OPEN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 else if (mouse_char != ' ')
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 count |= MOUSE_FOLD_CLOSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1947 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 return count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 * Mouse scroll wheel: Default action is to scroll three lines, or one page
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 * when Shift or Ctrl is used.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 * K_MOUSEUP (cap->arg == 1) or K_MOUSEDOWN (cap->arg == 0) or
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 * K_MOUSELEFT (cap->arg == -1) or K_MOUSERIGHT (cap->arg == -2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 nv_mousescroll(cmdarg_T *cap)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 win_T *old_curwin = curwin, *wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 if (mouse_row >= 0 && mouse_col >= 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 int row, col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 row = mouse_row;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 col = mouse_col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1969
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1970 // find the window at the pointer coordinates
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971 wp = mouse_find_win(&row, &col, FIND_POPUP);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1972 if (wp == NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973 return;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 if (WIN_IS_POPUP(wp) && !wp->w_has_scrollbar)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 return;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978 curwin = wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1979 curbuf = curwin->w_buffer;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1980 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1981
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1982 if (cap->arg == MSCR_UP || cap->arg == MSCR_DOWN)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1983 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1984 # ifdef FEAT_TERMINAL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 if (term_use_loop())
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986 // This window is a terminal window, send the mouse event there.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 // Set "typed" to FALSE to avoid an endless loop.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988 send_keys_to_term(curbuf->b_term, cap->cmdchar, FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1991 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 (void)onepage(cap->arg ? FORWARD : BACKWARD, 1L);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997 // Don't scroll more than half the window height.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 if (curwin->w_height < 6)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 cap->count1 = curwin->w_height / 2;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001 if (cap->count1 == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002 cap->count1 = 1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2004 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2005 cap->count1 = 3;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006 cap->count0 = cap->count1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007 nv_scroll_line(cap);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2008 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2010 if (WIN_IS_POPUP(curwin))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2011 popup_set_firstline(curwin);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2012 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2013 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2014 # ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2017 // Horizontal scroll - only allowed when 'wrap' is disabled
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2018 if (!curwin->w_p_wrap)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2019 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020 int val, step = 6;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2021
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2022 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 step = curwin->w_width;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2024 val = curwin->w_leftcol + (cap->arg == MSCR_RIGHT ? -step : +step);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2025 if (val < 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2026 val = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2027
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2028 gui_do_horiz_scroll(val, TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2029 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2030 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2031 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2032 # ifdef FEAT_SYN_HL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2033 if (curwin != old_curwin && curwin->w_p_cul)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2034 redraw_for_cursorline(curwin);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2036
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037 curwin->w_redr_status = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2039 curwin = old_curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 curbuf = curwin->w_buffer;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2042
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2043 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2044 * Mouse clicks and drags.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2045 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2046 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2047 nv_mouse(cmdarg_T *cap)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2048 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2049 (void)do_mouse(cap->oap, cap->cmdchar, BACKWARD, cap->count1, 0);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2050 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051 #endif // FEAT_MOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2053 // Functions also used for popup windows.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2054 #if defined(FEAT_MOUSE) || defined(FEAT_TEXT_PROP) || defined(PROTO)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2055
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2056 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2057 * Compute the buffer line position from the screen position "rowp" / "colp" in
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2058 * window "win".
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2059 * "plines_cache" can be NULL (no cache) or an array with "win->w_height"
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2060 * entries that caches the plines_win() result from a previous call. Entry is
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2061 * zero if not computed yet. There must be no text or setting changes since
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062 * the entry is put in the cache.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2063 * Returns TRUE if the position is below the last line.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2064 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2065 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2066 mouse_comp_pos(
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2067 win_T *win,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2068 int *rowp,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2069 int *colp,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2070 linenr_T *lnump,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2071 int *plines_cache)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2072 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2073 int col = *colp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2074 int row = *rowp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2075 linenr_T lnum;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2076 int retval = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2077 int off;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2078 int count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2079
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2080 #ifdef FEAT_RIGHTLEFT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2081 if (win->w_p_rl)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2082 col = win->w_width - 1 - col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2083 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2084
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2085 lnum = win->w_topline;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2086
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2087 while (row > 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2088 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2089 int cache_idx = lnum - win->w_topline;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2090
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 if (plines_cache != NULL && plines_cache[cache_idx] > 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2092 count = plines_cache[cache_idx];
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2093 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2094 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2095 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2096 // Don't include filler lines in "count"
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2097 if (win->w_p_diff
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2098 # ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2099 && !hasFoldingWin(win, lnum, NULL, NULL, TRUE, NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2100 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2101 )
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2102 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2103 if (lnum == win->w_topline)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2104 row -= win->w_topfill;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2105 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2106 row -= diff_check_fill(win, lnum);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107 count = plines_win_nofill(win, lnum, TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2109 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111 count = plines_win(win, lnum, TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2112 if (plines_cache != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2113 plines_cache[cache_idx] = count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 if (count > row)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2116 break; // Position is in this buffer line.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2118 (void)hasFoldingWin(win, lnum, NULL, &lnum, TRUE, NULL);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2119 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 if (lnum == win->w_buffer->b_ml.ml_line_count)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 retval = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123 break; // past end of file
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2124 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2125 row -= count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2126 ++lnum;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2127 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2128
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2129 if (!retval)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2130 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2131 // Compute the column without wrapping.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2132 off = win_col_off(win) - win_col_off2(win);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2133 if (col < off)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134 col = off;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2135 col += row * (win->w_width - off);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 // add skip column (for long wrapping line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2137 col += win->w_skipcol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2138 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2139
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2140 if (!win->w_p_wrap)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2141 col += win->w_leftcol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2142
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2143 // skip line number and fold column in front of the line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2144 col -= win_col_off(win);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2145 if (col < 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2146 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2147 #ifdef FEAT_NETBEANS_INTG
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2148 netbeans_gutter_click(lnum);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2149 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2150 col = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2151 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2152
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2153 *colp = col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2154 *rowp = row;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2155 *lnump = lnum;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2156 return retval;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2158
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 * Find the window at screen position "*rowp" and "*colp". The positions are
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 * updated to become relative to the top-left of the window.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2162 * When "popup" is FAIL_POPUP and the position is in a popup window then NULL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163 * is returned. When "popup" is IGNORE_POPUP then do not even check popup
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 * windows.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2165 * Returns NULL when something is wrong.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2166 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 win_T *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2168 mouse_find_win(int *rowp, int *colp, mouse_find_T popup UNUSED)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2169 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170 frame_T *fp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2171 win_T *wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 win_T *pwp = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2175
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2176 if (popup != IGNORE_POPUP)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2177 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2178 popup_reset_handled();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2179 while ((wp = find_next_popup(TRUE)) != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2180 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2181 if (*rowp >= wp->w_winrow && *rowp < wp->w_winrow + popup_height(wp)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2182 && *colp >= wp->w_wincol
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2183 && *colp < wp->w_wincol + popup_width(wp))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2184 pwp = wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2185 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2186 if (pwp != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2187 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2188 if (popup == FAIL_POPUP)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2189 return NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2190 *rowp -= pwp->w_winrow;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2191 *colp -= pwp->w_wincol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2192 return pwp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2193 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2194 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2195 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2196
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2197 fp = topframe;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2198 *rowp -= firstwin->w_winrow;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2199 for (;;)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2200 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2201 if (fp->fr_layout == FR_LEAF)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2202 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2203 if (fp->fr_layout == FR_ROW)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2204 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2205 for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2206 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2207 if (*colp < fp->fr_width)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2208 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2209 *colp -= fp->fr_width;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2210 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2211 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2212 else // fr_layout == FR_COL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2213 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2214 for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2215 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2216 if (*rowp < fp->fr_height)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2217 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2218 *rowp -= fp->fr_height;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2219 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2220 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2221 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2222 // When using a timer that closes a window the window might not actually
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2223 // exist.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2224 FOR_ALL_WINDOWS(wp)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2225 if (wp == fp->fr_win)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2226 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2227 #ifdef FEAT_MENU
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2228 *rowp -= wp->w_winbar_height;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2229 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2230 return wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2231 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2232 return NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2233 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2234
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2235 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MAC) \
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2236 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2237 || defined(FEAT_GUI_PHOTON) || defined(FEAT_TERM_POPUP_MENU) \
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2238 || defined(PROTO)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2239 # define NEED_VCOL2COL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2240
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2241 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2242 * Translate window coordinates to buffer position without any side effects
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2243 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2244 static int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2245 get_fpos_of_mouse(pos_T *mpos)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2246 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2247 win_T *wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2248 int row = mouse_row;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2249 int col = mouse_col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2250
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2251 if (row < 0 || col < 0) // check if it makes sense
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2252 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2253
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2254 // find the window where the row is in
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2255 wp = mouse_find_win(&row, &col, FAIL_POPUP);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2256 if (wp == NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2257 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2258 // winpos and height may change in win_enter()!
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2259 if (row >= wp->w_height) // In (or below) status line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2260 return IN_STATUS_LINE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2261 if (col >= wp->w_width) // In vertical separator line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2262 return IN_SEP_LINE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2263
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2264 if (wp != curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2265 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2266
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2267 // compute the position in the buffer line from the posn on the screen
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2268 if (mouse_comp_pos(curwin, &row, &col, &mpos->lnum, NULL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2269 return IN_STATUS_LINE; // past bottom
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2270
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2271 mpos->col = vcol2col(wp, mpos->lnum, col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2272
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2273 if (mpos->col > 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2274 --mpos->col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2275 mpos->coladd = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2276 return IN_BUFFER;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2277 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2278 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2279
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2280 #if defined(NEED_VCOL2COL) || defined(FEAT_BEVAL) || defined(FEAT_TEXT_PROP) \
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2281 || defined(PROTO)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2282 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2283 * Convert a virtual (screen) column to a character column.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2284 * The first column is one.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2285 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2286 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2287 vcol2col(win_T *wp, linenr_T lnum, int vcol)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2288 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2289 // try to advance to the specified column
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2290 int count = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2291 char_u *ptr;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2292 char_u *line;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2293
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2294 line = ptr = ml_get_buf(wp->w_buffer, lnum, FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2295 while (count < vcol && *ptr != NUL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2296 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2297 count += win_lbr_chartabsize(wp, line, ptr, count, NULL);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2298 MB_PTR_ADV(ptr);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2299 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2300 return (int)(ptr - line);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2301 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2302 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2303
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2304 #else // FEAT_MOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2305
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2306 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2307 * Dummy implementation of setmouse() to avoid lots of #ifdefs.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2308 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2309 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2310 setmouse(void)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2311 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2312 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2313
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2314 #endif // FEAT_MOUSE