Mercurial > vim
annotate src/ui.c @ 15052:35c2d164a630 v8.1.0537
patch 8.1.0537: ui_breakcheck() may be called recursively
commit https://github.com/vim/vim/commit/48d23bb4de3dd37ba0d0b22e7c39d6b894cb1f75
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Nov 20 02:42:43 2018 +0100
patch 8.1.0537: ui_breakcheck() may be called recursively
Problem: ui_breakcheck() may be called recursively, which doesn't work.
Solution: When called recursively, just return. (James McCoy, closes https://github.com/vim/vim/issues/3617)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 20 Nov 2018 02:45:06 +0100 |
parents | 27b9a84395b5 |
children | fd9c4b1a71aa |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ui.c: functions that handle the user interface. | |
12 * 1. Keyboard input stuff, and a bit of windowing stuff. These are called | |
13 * before the machine specific stuff (mch_*) so that we can call the GUI | |
14 * stuff instead if the GUI is running. | |
15 * 2. Clipboard stuff. | |
16 * 3. Input buffer stuff. | |
17 */ | |
18 | |
19 #include "vim.h" | |
20 | |
5136
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
21 #ifdef FEAT_CYGWIN_WIN32_CLIPBOARD |
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
22 # define WIN32_LEAN_AND_MEAN |
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
23 # include <windows.h> |
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
24 # include "winclip.pro" |
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
25 #endif |
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
26 |
7 | 27 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
28 ui_write(char_u *s, int len) |
7 | 29 { |
30 #ifdef FEAT_GUI | |
31 if (gui.in_use && !gui.dying && !gui.starting) | |
32 { | |
33 gui_write(s, len); | |
34 if (p_wd) | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
35 gui_wait_for_chars(p_wd, typebuf.tb_change_cnt); |
7 | 36 return; |
37 } | |
38 #endif | |
39 #ifndef NO_CONSOLE | |
40 /* Don't output anything in silent mode ("ex -s") unless 'verbose' set */ | |
41 if (!(silent_mode && p_verbose == 0)) | |
42 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
43 #if defined(FEAT_MBYTE) && !defined(WIN3264) |
7 | 44 char_u *tofree = NULL; |
45 | |
46 if (output_conv.vc_type != CONV_NONE) | |
47 { | |
48 /* Convert characters from 'encoding' to 'termencoding'. */ | |
49 tofree = string_convert(&output_conv, s, &len); | |
50 if (tofree != NULL) | |
51 s = tofree; | |
52 } | |
53 #endif | |
54 | |
55 mch_write(s, len); | |
56 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
57 #if defined(FEAT_MBYTE) && !defined(WIN3264) |
7 | 58 if (output_conv.vc_type != CONV_NONE) |
59 vim_free(tofree); | |
60 #endif | |
61 } | |
62 #endif | |
63 } | |
64 | |
2935 | 65 #if defined(UNIX) || defined(VMS) || defined(PROTO) || defined(WIN3264) |
7 | 66 /* |
67 * When executing an external program, there may be some typed characters that | |
68 * are not consumed by it. Give them back to ui_inchar() and they are stored | |
69 * here for the next call. | |
70 */ | |
71 static char_u *ta_str = NULL; | |
72 static int ta_off; /* offset for next char to use when ta_str != NULL */ | |
73 static int ta_len; /* length of ta_str when it's not NULL*/ | |
74 | |
75 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
76 ui_inchar_undo(char_u *s, int len) |
7 | 77 { |
78 char_u *new; | |
79 int newlen; | |
80 | |
81 newlen = len; | |
82 if (ta_str != NULL) | |
83 newlen += ta_len - ta_off; | |
84 new = alloc(newlen); | |
85 if (new != NULL) | |
86 { | |
87 if (ta_str != NULL) | |
88 { | |
89 mch_memmove(new, ta_str + ta_off, (size_t)(ta_len - ta_off)); | |
90 mch_memmove(new + ta_len - ta_off, s, (size_t)len); | |
91 vim_free(ta_str); | |
92 } | |
93 else | |
94 mch_memmove(new, s, (size_t)len); | |
95 ta_str = new; | |
96 ta_len = newlen; | |
97 ta_off = 0; | |
98 } | |
99 } | |
100 #endif | |
101 | |
102 /* | |
3877 | 103 * ui_inchar(): low level input function. |
7 | 104 * Get characters from the keyboard. |
105 * Return the number of characters that are available. | |
106 * If "wtime" == 0 do not wait for characters. | |
107 * If "wtime" == -1 wait forever for characters. | |
108 * If "wtime" > 0 wait "wtime" milliseconds for a character. | |
109 * | |
110 * "tb_change_cnt" is the value of typebuf.tb_change_cnt if "buf" points into | |
111 * it. When typebuf.tb_change_cnt changes (e.g., when a message is received | |
112 * from a remote client) "buf" can no longer be used. "tb_change_cnt" is NULL | |
113 * otherwise. | |
114 */ | |
115 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
116 ui_inchar( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
117 char_u *buf, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
118 int maxlen, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
119 long wtime, /* don't use "time", MIPS cannot handle it */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
120 int tb_change_cnt) |
7 | 121 { |
122 int retval = 0; | |
123 | |
124 #if defined(FEAT_GUI) && (defined(UNIX) || defined(VMS)) | |
125 /* | |
126 * Use the typeahead if there is any. | |
127 */ | |
128 if (ta_str != NULL) | |
129 { | |
130 if (maxlen >= ta_len - ta_off) | |
131 { | |
132 mch_memmove(buf, ta_str + ta_off, (size_t)ta_len); | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
133 VIM_CLEAR(ta_str); |
7 | 134 return ta_len; |
135 } | |
136 mch_memmove(buf, ta_str + ta_off, (size_t)maxlen); | |
137 ta_off += maxlen; | |
138 return maxlen; | |
139 } | |
140 #endif | |
141 | |
170 | 142 #ifdef FEAT_PROFILE |
791 | 143 if (do_profiling == PROF_YES && wtime != 0) |
170 | 144 prof_inchar_enter(); |
145 #endif | |
146 | |
7 | 147 #ifdef NO_CONSOLE_INPUT |
148 /* Don't wait for character input when the window hasn't been opened yet. | |
149 * Do try reading, this works when redirecting stdin from a file. | |
150 * Must return something, otherwise we'll loop forever. If we run into | |
151 * this very often we probably got stuck, exit Vim. */ | |
152 if (no_console_input()) | |
153 { | |
154 static int count = 0; | |
155 | |
156 # ifndef NO_CONSOLE | |
228 | 157 retval = mch_inchar(buf, maxlen, (wtime >= 0 && wtime < 10) |
158 ? 10L : wtime, tb_change_cnt); | |
159 if (retval > 0 || typebuf_changed(tb_change_cnt) || wtime >= 0) | |
170 | 160 goto theend; |
7 | 161 # endif |
162 if (wtime == -1 && ++count == 1000) | |
163 read_error_exit(); | |
164 buf[0] = CAR; | |
170 | 165 retval = 1; |
166 goto theend; | |
7 | 167 } |
168 #endif | |
169 | |
1086 | 170 /* If we are going to wait for some time or block... */ |
171 if (wtime == -1 || wtime > 100L) | |
172 { | |
173 /* ... allow signals to kill us. */ | |
174 (void)vim_handle_signal(SIGNAL_UNBLOCK); | |
175 | |
176 /* ... there is no need for CTRL-C to interrupt something, don't let | |
177 * it set got_int when it was mapped. */ | |
6491 | 178 if ((mapped_ctrl_c | curbuf->b_mapped_ctrl_c) & get_real_state()) |
1086 | 179 ctrl_c_interrupts = FALSE; |
180 } | |
7 | 181 |
182 #ifdef FEAT_GUI | |
183 if (gui.in_use) | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
184 retval = gui_inchar(buf, maxlen, wtime, tb_change_cnt); |
7 | 185 #endif |
186 #ifndef NO_CONSOLE | |
187 # ifdef FEAT_GUI | |
188 else | |
189 # endif | |
190 retval = mch_inchar(buf, maxlen, wtime, tb_change_cnt); | |
191 #endif | |
192 | |
1086 | 193 if (wtime == -1 || wtime > 100L) |
194 /* block SIGHUP et al. */ | |
195 (void)vim_handle_signal(SIGNAL_BLOCK); | |
196 | |
7 | 197 ctrl_c_interrupts = TRUE; |
198 | |
170 | 199 #ifdef NO_CONSOLE_INPUT |
200 theend: | |
201 #endif | |
202 #ifdef FEAT_PROFILE | |
791 | 203 if (do_profiling == PROF_YES && wtime != 0) |
170 | 204 prof_inchar_exit(); |
205 #endif | |
7 | 206 return retval; |
207 } | |
208 | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
209 #if defined(FEAT_TIMERS) || defined(PROT) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
210 /* |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
211 * Wait for a timer to fire or "wait_func" to return non-zero. |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
212 * Returns OK when something was read. |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
213 * Returns FAIL when it timed out or was interrupted. |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
214 */ |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
215 int |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
216 ui_wait_for_chars_or_timer( |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
217 long wtime, |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
218 int (*wait_func)(long wtime, int *interrupted, int ignore_input), |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
219 int *interrupted, |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
220 int ignore_input) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
221 { |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
222 int due_time; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
223 long remaining = wtime; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
224 int tb_change_cnt = typebuf.tb_change_cnt; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
225 |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
226 /* When waiting very briefly don't trigger timers. */ |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
227 if (wtime >= 0 && wtime < 10L) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
228 return wait_func(wtime, NULL, ignore_input); |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
229 |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
230 while (wtime < 0 || remaining > 0) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
231 { |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
232 /* Trigger timers and then get the time in wtime until the next one is |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
233 * due. Wait up to that time. */ |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
234 due_time = check_due_timer(); |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
235 if (typebuf.tb_change_cnt != tb_change_cnt) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
236 { |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
237 /* timer may have used feedkeys() */ |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
238 return FAIL; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
239 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
240 if (due_time <= 0 || (wtime > 0 && due_time > remaining)) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
241 due_time = remaining; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
242 if (wait_func(due_time, interrupted, ignore_input)) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
243 return OK; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
244 if (interrupted != NULL && *interrupted) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
245 /* Nothing available, but need to return so that side effects get |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
246 * handled, such as handling a message on a channel. */ |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
247 return FAIL; |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
248 if (wtime > 0) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
249 remaining -= due_time; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
250 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
251 return FAIL; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
252 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
253 #endif |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
254 |
7 | 255 /* |
256 * return non-zero if a character is available | |
257 */ | |
258 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
259 ui_char_avail(void) |
7 | 260 { |
261 #ifdef FEAT_GUI | |
262 if (gui.in_use) | |
263 { | |
264 gui_mch_update(); | |
265 return input_available(); | |
266 } | |
267 #endif | |
268 #ifndef NO_CONSOLE | |
269 # ifdef NO_CONSOLE_INPUT | |
270 if (no_console_input()) | |
271 return 0; | |
272 # endif | |
273 return mch_char_avail(); | |
274 #else | |
275 return 0; | |
276 #endif | |
277 } | |
278 | |
279 /* | |
280 * Delay for the given number of milliseconds. If ignoreinput is FALSE then we | |
281 * cancel the delay if a key is hit. | |
282 */ | |
283 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
284 ui_delay(long msec, int ignoreinput) |
7 | 285 { |
286 #ifdef FEAT_GUI | |
287 if (gui.in_use && !ignoreinput) | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
288 gui_wait_for_chars(msec, typebuf.tb_change_cnt); |
7 | 289 else |
290 #endif | |
291 mch_delay(msec, ignoreinput); | |
292 } | |
293 | |
294 /* | |
295 * If the machine has job control, use it to suspend the program, | |
296 * otherwise fake it by starting a new shell. | |
297 * When running the GUI iconify the window. | |
298 */ | |
299 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
300 ui_suspend(void) |
7 | 301 { |
302 #ifdef FEAT_GUI | |
303 if (gui.in_use) | |
304 { | |
305 gui_mch_iconify(); | |
306 return; | |
307 } | |
308 #endif | |
309 mch_suspend(); | |
310 } | |
311 | |
312 #if !defined(UNIX) || !defined(SIGTSTP) || defined(PROTO) || defined(__BEOS__) | |
313 /* | |
314 * When the OS can't really suspend, call this function to start a shell. | |
315 * This is never called in the GUI. | |
316 */ | |
317 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
318 suspend_shell(void) |
7 | 319 { |
320 if (*p_sh == NUL) | |
321 EMSG(_(e_shellempty)); | |
322 else | |
323 { | |
324 MSG_PUTS(_("new shell started\n")); | |
325 do_shell(NULL, 0); | |
326 } | |
327 } | |
328 #endif | |
329 | |
330 /* | |
331 * Try to get the current Vim shell size. Put the result in Rows and Columns. | |
332 * Use the new sizes as defaults for 'columns' and 'lines'. | |
333 * Return OK when size could be determined, FAIL otherwise. | |
334 */ | |
335 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
336 ui_get_shellsize(void) |
7 | 337 { |
338 int retval; | |
339 | |
340 #ifdef FEAT_GUI | |
341 if (gui.in_use) | |
342 retval = gui_get_shellsize(); | |
343 else | |
344 #endif | |
345 retval = mch_get_shellsize(); | |
346 | |
347 check_shellsize(); | |
348 | |
349 /* adjust the default for 'lines' and 'columns' */ | |
350 if (retval == OK) | |
351 { | |
352 set_number_default("lines", Rows); | |
353 set_number_default("columns", Columns); | |
354 } | |
355 return retval; | |
356 } | |
357 | |
358 /* | |
359 * Set the size of the Vim shell according to Rows and Columns, if possible. | |
360 * The gui_set_shellsize() or mch_set_shellsize() function will try to set the | |
361 * new size. If this is not possible, it will adjust Rows and Columns. | |
362 */ | |
363 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
364 ui_set_shellsize( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
365 int mustset UNUSED) /* set by the user */ |
7 | 366 { |
367 #ifdef FEAT_GUI | |
368 if (gui.in_use) | |
5106
c3a82208e143
updated for version 7.3.1296
Bram Moolenaar <bram@vim.org>
parents:
5037
diff
changeset
|
369 gui_set_shellsize(mustset, TRUE, RESIZE_BOTH); |
7 | 370 else |
371 #endif | |
372 mch_set_shellsize(); | |
373 } | |
374 | |
375 /* | |
376 * Called when Rows and/or Columns changed. Adjust scroll region and mouse | |
377 * region. | |
378 */ | |
379 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
380 ui_new_shellsize(void) |
7 | 381 { |
382 if (full_screen && !exiting) | |
383 { | |
384 #ifdef FEAT_GUI | |
385 if (gui.in_use) | |
386 gui_new_shellsize(); | |
387 else | |
388 #endif | |
389 mch_new_shellsize(); | |
390 } | |
391 } | |
392 | |
393 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
394 ui_breakcheck(void) |
7 | 395 { |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
396 ui_breakcheck_force(FALSE); |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
397 } |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
398 |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
399 /* |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
400 * When "force" is true also check when the terminal is not in raw mode. |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
401 * This is useful to read input on channels. |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
402 */ |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
403 void |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
404 ui_breakcheck_force(int force) |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
405 { |
15052
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
406 static int recursive = FALSE; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
407 int save_updating_screen = updating_screen; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
408 |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
409 // We could be called recursively if stderr is redirected, calling |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
410 // fill_input_buf() calls settmode() when stdin isn't a tty. settmode() |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
411 // calls vgetorpeek() which calls ui_breakcheck() again. |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
412 if (recursive) |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
413 return; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
414 recursive = TRUE; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
415 |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
416 // We do not want gui_resize_shell() to redraw the screen here. |
10771
abc27e523e2a
patch 8.0.0275: the screen may be updated at the wrong time
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
417 ++updating_screen; |
abc27e523e2a
patch 8.0.0275: the screen may be updated at the wrong time
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
418 |
7 | 419 #ifdef FEAT_GUI |
420 if (gui.in_use) | |
421 gui_mch_update(); | |
422 else | |
423 #endif | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
424 mch_breakcheck(force); |
10771
abc27e523e2a
patch 8.0.0275: the screen may be updated at the wrong time
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
425 |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
426 if (save_updating_screen) |
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
427 updating_screen = TRUE; |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13876
diff
changeset
|
428 else |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13876
diff
changeset
|
429 reset_updating_screen(FALSE); |
15052
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
430 |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
431 recursive = FALSE; |
7 | 432 } |
433 | |
434 /***************************************************************************** | |
435 * Functions for copying and pasting text between applications. | |
436 * This is always included in a GUI version, but may also be included when the | |
437 * clipboard and mouse is available to a terminal version such as xterm. | |
438 * Note: there are some more functions in ops.c that handle selection stuff. | |
439 * | |
440 * Also note that the majority of functions here deal with the X 'primary' | |
441 * (visible - for Visual mode use) selection, and only that. There are no | |
442 * versions of these for the 'clipboard' selection, as Visual mode has no use | |
443 * for them. | |
444 */ | |
445 | |
446 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
447 | |
448 /* | |
449 * Selection stuff using Visual mode, for cutting and pasting text to other | |
450 * windows. | |
451 */ | |
452 | |
453 /* | |
454 * Call this to initialise the clipboard. Pass it FALSE if the clipboard code | |
455 * is included, but the clipboard can not be used, or TRUE if the clipboard can | |
456 * be used. Eg unix may call this with FALSE, then call it again with TRUE if | |
457 * the GUI starts. | |
458 */ | |
459 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
460 clip_init(int can_use) |
7 | 461 { |
462 VimClipboard *cb; | |
463 | |
464 cb = &clip_star; | |
465 for (;;) | |
466 { | |
467 cb->available = can_use; | |
468 cb->owned = FALSE; | |
469 cb->start.lnum = 0; | |
470 cb->start.col = 0; | |
471 cb->end.lnum = 0; | |
472 cb->end.col = 0; | |
473 cb->state = SELECT_CLEARED; | |
474 | |
475 if (cb == &clip_plus) | |
476 break; | |
477 cb = &clip_plus; | |
478 } | |
479 } | |
480 | |
481 /* | |
482 * Check whether the VIsual area has changed, and if so try to become the owner | |
483 * of the selection, and free any old converted selection we may still have | |
484 * lying around. If the VIsual mode has ended, make a copy of what was | |
485 * selected so we can still give it to others. Will probably have to make sure | |
486 * this is called whenever VIsual mode is ended. | |
487 */ | |
488 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
489 clip_update_selection(VimClipboard *clip) |
7 | 490 { |
3674 | 491 pos_T start, end; |
7 | 492 |
493 /* If visual mode is only due to a redo command ("."), then ignore it */ | |
494 if (!redo_VIsual_busy && VIsual_active && (State & NORMAL)) | |
495 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10771
diff
changeset
|
496 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 497 { |
498 start = VIsual; | |
499 end = curwin->w_cursor; | |
500 #ifdef FEAT_MBYTE | |
501 if (has_mbyte) | |
474 | 502 end.col += (*mb_ptr2len)(ml_get_cursor()) - 1; |
7 | 503 #endif |
504 } | |
505 else | |
506 { | |
507 start = curwin->w_cursor; | |
508 end = VIsual; | |
509 } | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10771
diff
changeset
|
510 if (!EQUAL_POS(clip->start, start) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10771
diff
changeset
|
511 || !EQUAL_POS(clip->end, end) |
3674 | 512 || clip->vmode != VIsual_mode) |
7 | 513 { |
3674 | 514 clip_clear_selection(clip); |
515 clip->start = start; | |
516 clip->end = end; | |
517 clip->vmode = VIsual_mode; | |
518 clip_free_selection(clip); | |
519 clip_own_selection(clip); | |
520 clip_gen_set_selection(clip); | |
7 | 521 } |
522 } | |
523 } | |
524 | |
525 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
526 clip_own_selection(VimClipboard *cbd) |
7 | 527 { |
528 /* | |
529 * Also want to check somehow that we are reading from the keyboard rather | |
530 * than a mapping etc. | |
531 */ | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
532 #ifdef FEAT_X11 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
533 /* Always own the selection, we might have lost it without being |
2586 | 534 * notified, e.g. during a ":sh" command. */ |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
535 if (cbd->available) |
7 | 536 { |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
537 int was_owned = cbd->owned; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
538 |
7 | 539 cbd->owned = (clip_gen_own_selection(cbd) == OK); |
3674 | 540 if (!was_owned && (cbd == &clip_star || cbd == &clip_plus)) |
7 | 541 { |
620 | 542 /* May have to show a different kind of highlighting for the |
543 * selected area. There is no specific redraw command for this, | |
544 * just redraw all windows on the current buffer. */ | |
7 | 545 if (cbd->owned |
791 | 546 && (get_real_state() == VISUAL |
547 || get_real_state() == SELECTMODE) | |
3674 | 548 && (cbd == &clip_star ? clip_isautosel_star() |
549 : clip_isautosel_plus()) | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
550 && HL_ATTR(HLF_V) != HL_ATTR(HLF_VNC)) |
7 | 551 redraw_curbuf_later(INVERTED_ALL); |
552 } | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
553 } |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
554 #else |
3877 | 555 /* Only own the clipboard when we didn't own it yet. */ |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
556 if (!cbd->owned && cbd->available) |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
557 cbd->owned = (clip_gen_own_selection(cbd) == OK); |
7 | 558 #endif |
559 } | |
560 | |
561 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
562 clip_lose_selection(VimClipboard *cbd) |
7 | 563 { |
564 #ifdef FEAT_X11 | |
565 int was_owned = cbd->owned; | |
566 #endif | |
3674 | 567 int visual_selection = FALSE; |
568 | |
569 if (cbd == &clip_star || cbd == &clip_plus) | |
570 visual_selection = TRUE; | |
7 | 571 |
572 clip_free_selection(cbd); | |
573 cbd->owned = FALSE; | |
574 if (visual_selection) | |
3674 | 575 clip_clear_selection(cbd); |
7 | 576 clip_gen_lose_selection(cbd); |
577 #ifdef FEAT_X11 | |
578 if (visual_selection) | |
579 { | |
580 /* May have to show a different kind of highlighting for the selected | |
581 * area. There is no specific redraw command for this, just redraw all | |
582 * windows on the current buffer. */ | |
583 if (was_owned | |
791 | 584 && (get_real_state() == VISUAL |
585 || get_real_state() == SELECTMODE) | |
3674 | 586 && (cbd == &clip_star ? |
587 clip_isautosel_star() : clip_isautosel_plus()) | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
588 && HL_ATTR(HLF_V) != HL_ATTR(HLF_VNC)) |
7 | 589 { |
590 update_curbuf(INVERTED_ALL); | |
591 setcursor(); | |
592 cursor_on(); | |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
593 out_flush_cursor(TRUE, FALSE); |
7 | 594 } |
595 } | |
596 #endif | |
597 } | |
598 | |
3674 | 599 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
600 clip_copy_selection(VimClipboard *clip) |
7 | 601 { |
3674 | 602 if (VIsual_active && (State & NORMAL) && clip->available) |
7 | 603 { |
3674 | 604 clip_update_selection(clip); |
605 clip_free_selection(clip); | |
606 clip_own_selection(clip); | |
607 if (clip->owned) | |
608 clip_get_selection(clip); | |
609 clip_gen_set_selection(clip); | |
7 | 610 } |
611 } | |
612 | |
613 /* | |
6116 | 614 * Save and restore clip_unnamed before doing possibly many changes. This |
615 * prevents accessing the clipboard very often which might slow down Vim | |
616 * considerably. | |
617 */ | |
6561 | 618 static int global_change_count = 0; /* if set, inside a start_global_changes */ |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
619 static int clipboard_needs_update = FALSE; /* clipboard needs to be updated */ |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
620 static int clip_did_set_selection = TRUE; |
6116 | 621 |
622 /* | |
623 * Save clip_unnamed and reset it. | |
624 */ | |
625 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
626 start_global_changes(void) |
6116 | 627 { |
6543 | 628 if (++global_change_count > 1) |
629 return; | |
6116 | 630 clip_unnamed_saved = clip_unnamed; |
6543 | 631 clipboard_needs_update = FALSE; |
6116 | 632 |
6543 | 633 if (clip_did_set_selection) |
6116 | 634 { |
635 clip_unnamed = FALSE; | |
636 clip_did_set_selection = FALSE; | |
637 } | |
638 } | |
639 | |
640 /* | |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
641 * Return TRUE if setting the clipboard was postponed, it already contains the |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
642 * right text. |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
643 */ |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
644 int |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
645 is_clipboard_needs_update() |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
646 { |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
647 return clipboard_needs_update; |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
648 } |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
649 |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
650 /* |
6116 | 651 * Restore clip_unnamed and set the selection when needed. |
652 */ | |
653 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
654 end_global_changes(void) |
6116 | 655 { |
6543 | 656 if (--global_change_count > 0) |
657 /* recursive */ | |
658 return; | |
659 if (!clip_did_set_selection) | |
6116 | 660 { |
661 clip_did_set_selection = TRUE; | |
662 clip_unnamed = clip_unnamed_saved; | |
6543 | 663 clip_unnamed_saved = FALSE; |
664 if (clipboard_needs_update) | |
6116 | 665 { |
6543 | 666 /* only store something in the clipboard, |
667 * if we have yanked anything to it */ | |
668 if (clip_unnamed & CLIP_UNNAMED) | |
669 { | |
670 clip_own_selection(&clip_star); | |
671 clip_gen_set_selection(&clip_star); | |
672 } | |
673 if (clip_unnamed & CLIP_UNNAMED_PLUS) | |
674 { | |
675 clip_own_selection(&clip_plus); | |
676 clip_gen_set_selection(&clip_plus); | |
677 } | |
6116 | 678 } |
679 } | |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
680 clipboard_needs_update = FALSE; |
6116 | 681 } |
682 | |
683 /* | |
7 | 684 * Called when Visual mode is ended: update the selection. |
685 */ | |
686 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
687 clip_auto_select(void) |
7 | 688 { |
3674 | 689 if (clip_isautosel_star()) |
690 clip_copy_selection(&clip_star); | |
691 if (clip_isautosel_plus()) | |
692 clip_copy_selection(&clip_plus); | |
7 | 693 } |
694 | |
695 /* | |
3674 | 696 * Return TRUE if automatic selection of Visual area is desired for the * |
697 * register. | |
7 | 698 */ |
699 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
700 clip_isautosel_star(void) |
7 | 701 { |
702 return ( | |
703 #ifdef FEAT_GUI | |
704 gui.in_use ? (vim_strchr(p_go, GO_ASEL) != NULL) : | |
705 #endif | |
3674 | 706 clip_autoselect_star); |
707 } | |
708 | |
709 /* | |
710 * Return TRUE if automatic selection of Visual area is desired for the + | |
711 * register. | |
712 */ | |
713 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
714 clip_isautosel_plus(void) |
3674 | 715 { |
716 return ( | |
717 #ifdef FEAT_GUI | |
718 gui.in_use ? (vim_strchr(p_go, GO_ASELPLUS) != NULL) : | |
719 #endif | |
720 clip_autoselect_plus); | |
7 | 721 } |
722 | |
723 | |
724 /* | |
725 * Stuff for general mouse selection, without using Visual mode. | |
726 */ | |
727 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
728 static void clip_invert_area(int, int, int, int, int how); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
729 static void clip_invert_rectangle(int row, int col, int height, int width, int invert); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
730 static void clip_get_word_boundaries(VimClipboard *, int, int); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
731 static int clip_get_line_end(int); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
732 static void clip_update_modeless_selection(VimClipboard *, int, int, |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
733 int, int); |
7 | 734 |
735 /* flags for clip_invert_area() */ | |
736 #define CLIP_CLEAR 1 | |
737 #define CLIP_SET 2 | |
738 #define CLIP_TOGGLE 3 | |
739 | |
740 /* | |
741 * Start, continue or end a modeless selection. Used when editing the | |
742 * command-line and in the cmdline window. | |
743 */ | |
744 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
745 clip_modeless(int button, int is_click, int is_drag) |
7 | 746 { |
747 int repeat; | |
748 | |
749 repeat = ((clip_star.mode == SELECT_MODE_CHAR | |
750 || clip_star.mode == SELECT_MODE_LINE) | |
751 && (mod_mask & MOD_MASK_2CLICK)) | |
752 || (clip_star.mode == SELECT_MODE_WORD | |
753 && (mod_mask & MOD_MASK_3CLICK)); | |
754 if (is_click && button == MOUSE_RIGHT) | |
755 { | |
756 /* Right mouse button: If there was no selection, start one. | |
757 * Otherwise extend the existing selection. */ | |
758 if (clip_star.state == SELECT_CLEARED) | |
759 clip_start_selection(mouse_col, mouse_row, FALSE); | |
760 clip_process_selection(button, mouse_col, mouse_row, repeat); | |
761 } | |
762 else if (is_click) | |
763 clip_start_selection(mouse_col, mouse_row, repeat); | |
764 else if (is_drag) | |
765 { | |
766 /* Don't try extending a selection if there isn't one. Happens when | |
767 * button-down is in the cmdline and them moving mouse upwards. */ | |
768 if (clip_star.state != SELECT_CLEARED) | |
769 clip_process_selection(button, mouse_col, mouse_row, repeat); | |
770 } | |
771 else /* release */ | |
772 clip_process_selection(MOUSE_RELEASE, mouse_col, mouse_row, FALSE); | |
773 } | |
774 | |
775 /* | |
776 * Compare two screen positions ala strcmp() | |
777 */ | |
778 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
779 clip_compare_pos( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
780 int row1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
781 int col1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
782 int row2, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
783 int col2) |
7 | 784 { |
785 if (row1 > row2) return(1); | |
786 if (row1 < row2) return(-1); | |
787 if (col1 > col2) return(1); | |
788 if (col1 < col2) return(-1); | |
8236
6d221d623c8e
commit https://github.com/vim/vim/commit/9e34110816522b081feb65ed5b2f4ec03d290e30
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
789 return(0); |
7 | 790 } |
791 | |
792 /* | |
793 * Start the selection | |
794 */ | |
795 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
796 clip_start_selection(int col, int row, int repeated_click) |
7 | 797 { |
798 VimClipboard *cb = &clip_star; | |
799 | |
800 if (cb->state == SELECT_DONE) | |
3674 | 801 clip_clear_selection(cb); |
7 | 802 |
803 row = check_row(row); | |
804 col = check_col(col); | |
805 #ifdef FEAT_MBYTE | |
806 col = mb_fix_col(col, row); | |
807 #endif | |
808 | |
809 cb->start.lnum = row; | |
810 cb->start.col = col; | |
811 cb->end = cb->start; | |
812 cb->origin_row = (short_u)cb->start.lnum; | |
813 cb->state = SELECT_IN_PROGRESS; | |
814 | |
815 if (repeated_click) | |
816 { | |
817 if (++cb->mode > SELECT_MODE_LINE) | |
818 cb->mode = SELECT_MODE_CHAR; | |
819 } | |
820 else | |
821 cb->mode = SELECT_MODE_CHAR; | |
822 | |
823 #ifdef FEAT_GUI | |
824 /* clear the cursor until the selection is made */ | |
825 if (gui.in_use) | |
826 gui_undraw_cursor(); | |
827 #endif | |
828 | |
829 switch (cb->mode) | |
830 { | |
831 case SELECT_MODE_CHAR: | |
832 cb->origin_start_col = cb->start.col; | |
833 cb->word_end_col = clip_get_line_end((int)cb->start.lnum); | |
834 break; | |
835 | |
836 case SELECT_MODE_WORD: | |
837 clip_get_word_boundaries(cb, (int)cb->start.lnum, cb->start.col); | |
838 cb->origin_start_col = cb->word_start_col; | |
839 cb->origin_end_col = cb->word_end_col; | |
840 | |
841 clip_invert_area((int)cb->start.lnum, cb->word_start_col, | |
842 (int)cb->end.lnum, cb->word_end_col, CLIP_SET); | |
843 cb->start.col = cb->word_start_col; | |
844 cb->end.col = cb->word_end_col; | |
845 break; | |
846 | |
847 case SELECT_MODE_LINE: | |
848 clip_invert_area((int)cb->start.lnum, 0, (int)cb->start.lnum, | |
849 (int)Columns, CLIP_SET); | |
850 cb->start.col = 0; | |
851 cb->end.col = Columns; | |
852 break; | |
853 } | |
854 | |
855 cb->prev = cb->start; | |
856 | |
857 #ifdef DEBUG_SELECTION | |
858 printf("Selection started at (%u,%u)\n", cb->start.lnum, cb->start.col); | |
859 #endif | |
860 } | |
861 | |
862 /* | |
863 * Continue processing the selection | |
864 */ | |
865 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
866 clip_process_selection( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
867 int button, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
868 int col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
869 int row, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
870 int_u repeated_click) |
7 | 871 { |
872 VimClipboard *cb = &clip_star; | |
873 int diff; | |
874 int slen = 1; /* cursor shape width */ | |
875 | |
876 if (button == MOUSE_RELEASE) | |
877 { | |
878 /* Check to make sure we have something selected */ | |
879 if (cb->start.lnum == cb->end.lnum && cb->start.col == cb->end.col) | |
880 { | |
881 #ifdef FEAT_GUI | |
882 if (gui.in_use) | |
883 gui_update_cursor(FALSE, FALSE); | |
884 #endif | |
885 cb->state = SELECT_CLEARED; | |
886 return; | |
887 } | |
888 | |
889 #ifdef DEBUG_SELECTION | |
890 printf("Selection ended: (%u,%u) to (%u,%u)\n", cb->start.lnum, | |
891 cb->start.col, cb->end.lnum, cb->end.col); | |
892 #endif | |
3674 | 893 if (clip_isautosel_star() |
7 | 894 || ( |
895 #ifdef FEAT_GUI | |
896 gui.in_use ? (vim_strchr(p_go, GO_ASELML) != NULL) : | |
897 #endif | |
898 clip_autoselectml)) | |
899 clip_copy_modeless_selection(FALSE); | |
900 #ifdef FEAT_GUI | |
901 if (gui.in_use) | |
902 gui_update_cursor(FALSE, FALSE); | |
903 #endif | |
904 | |
905 cb->state = SELECT_DONE; | |
906 return; | |
907 } | |
908 | |
909 row = check_row(row); | |
910 col = check_col(col); | |
911 #ifdef FEAT_MBYTE | |
912 col = mb_fix_col(col, row); | |
913 #endif | |
914 | |
915 if (col == (int)cb->prev.col && row == cb->prev.lnum && !repeated_click) | |
916 return; | |
917 | |
918 /* | |
919 * When extending the selection with the right mouse button, swap the | |
920 * start and end if the position is before half the selection | |
921 */ | |
922 if (cb->state == SELECT_DONE && button == MOUSE_RIGHT) | |
923 { | |
924 /* | |
925 * If the click is before the start, or the click is inside the | |
926 * selection and the start is the closest side, set the origin to the | |
927 * end of the selection. | |
928 */ | |
929 if (clip_compare_pos(row, col, (int)cb->start.lnum, cb->start.col) < 0 | |
930 || (clip_compare_pos(row, col, | |
931 (int)cb->end.lnum, cb->end.col) < 0 | |
932 && (((cb->start.lnum == cb->end.lnum | |
933 && cb->end.col - col > col - cb->start.col)) | |
934 || ((diff = (cb->end.lnum - row) - | |
935 (row - cb->start.lnum)) > 0 | |
936 || (diff == 0 && col < (int)(cb->start.col + | |
937 cb->end.col) / 2))))) | |
938 { | |
939 cb->origin_row = (short_u)cb->end.lnum; | |
940 cb->origin_start_col = cb->end.col - 1; | |
941 cb->origin_end_col = cb->end.col; | |
942 } | |
943 else | |
944 { | |
945 cb->origin_row = (short_u)cb->start.lnum; | |
946 cb->origin_start_col = cb->start.col; | |
947 cb->origin_end_col = cb->start.col; | |
948 } | |
949 if (cb->mode == SELECT_MODE_WORD && !repeated_click) | |
950 cb->mode = SELECT_MODE_CHAR; | |
951 } | |
952 | |
953 /* set state, for when using the right mouse button */ | |
954 cb->state = SELECT_IN_PROGRESS; | |
955 | |
956 #ifdef DEBUG_SELECTION | |
957 printf("Selection extending to (%d,%d)\n", row, col); | |
958 #endif | |
959 | |
960 if (repeated_click && ++cb->mode > SELECT_MODE_LINE) | |
961 cb->mode = SELECT_MODE_CHAR; | |
962 | |
963 switch (cb->mode) | |
964 { | |
965 case SELECT_MODE_CHAR: | |
966 /* If we're on a different line, find where the line ends */ | |
967 if (row != cb->prev.lnum) | |
968 cb->word_end_col = clip_get_line_end(row); | |
969 | |
970 /* See if we are before or after the origin of the selection */ | |
971 if (clip_compare_pos(row, col, cb->origin_row, | |
972 cb->origin_start_col) >= 0) | |
973 { | |
974 if (col >= (int)cb->word_end_col) | |
975 clip_update_modeless_selection(cb, cb->origin_row, | |
976 cb->origin_start_col, row, (int)Columns); | |
977 else | |
978 { | |
979 #ifdef FEAT_MBYTE | |
980 if (has_mbyte && mb_lefthalve(row, col)) | |
981 slen = 2; | |
982 #endif | |
983 clip_update_modeless_selection(cb, cb->origin_row, | |
984 cb->origin_start_col, row, col + slen); | |
985 } | |
986 } | |
987 else | |
988 { | |
989 #ifdef FEAT_MBYTE | |
990 if (has_mbyte | |
991 && mb_lefthalve(cb->origin_row, cb->origin_start_col)) | |
992 slen = 2; | |
993 #endif | |
994 if (col >= (int)cb->word_end_col) | |
995 clip_update_modeless_selection(cb, row, cb->word_end_col, | |
996 cb->origin_row, cb->origin_start_col + slen); | |
997 else | |
998 clip_update_modeless_selection(cb, row, col, | |
999 cb->origin_row, cb->origin_start_col + slen); | |
1000 } | |
1001 break; | |
1002 | |
1003 case SELECT_MODE_WORD: | |
1004 /* If we are still within the same word, do nothing */ | |
1005 if (row == cb->prev.lnum && col >= (int)cb->word_start_col | |
1006 && col < (int)cb->word_end_col && !repeated_click) | |
1007 return; | |
1008 | |
1009 /* Get new word boundaries */ | |
1010 clip_get_word_boundaries(cb, row, col); | |
1011 | |
1012 /* Handle being after the origin point of selection */ | |
1013 if (clip_compare_pos(row, col, cb->origin_row, | |
1014 cb->origin_start_col) >= 0) | |
1015 clip_update_modeless_selection(cb, cb->origin_row, | |
1016 cb->origin_start_col, row, cb->word_end_col); | |
1017 else | |
1018 clip_update_modeless_selection(cb, row, cb->word_start_col, | |
1019 cb->origin_row, cb->origin_end_col); | |
1020 break; | |
1021 | |
1022 case SELECT_MODE_LINE: | |
1023 if (row == cb->prev.lnum && !repeated_click) | |
1024 return; | |
1025 | |
1026 if (clip_compare_pos(row, col, cb->origin_row, | |
1027 cb->origin_start_col) >= 0) | |
1028 clip_update_modeless_selection(cb, cb->origin_row, 0, row, | |
1029 (int)Columns); | |
1030 else | |
1031 clip_update_modeless_selection(cb, row, 0, cb->origin_row, | |
1032 (int)Columns); | |
1033 break; | |
1034 } | |
1035 | |
1036 cb->prev.lnum = row; | |
1037 cb->prev.col = col; | |
1038 | |
1039 #ifdef DEBUG_SELECTION | |
1040 printf("Selection is: (%u,%u) to (%u,%u)\n", cb->start.lnum, | |
1041 cb->start.col, cb->end.lnum, cb->end.col); | |
1042 #endif | |
1043 } | |
1044 | |
1045 # if defined(FEAT_GUI) || defined(PROTO) | |
1046 /* | |
1047 * Redraw part of the selection if character at "row,col" is inside of it. | |
1048 * Only used for the GUI. | |
1049 */ | |
1050 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1051 clip_may_redraw_selection(int row, int col, int len) |
7 | 1052 { |
1053 int start = col; | |
1054 int end = col + len; | |
1055 | |
1056 if (clip_star.state != SELECT_CLEARED | |
1057 && row >= clip_star.start.lnum | |
1058 && row <= clip_star.end.lnum) | |
1059 { | |
1060 if (row == clip_star.start.lnum && start < (int)clip_star.start.col) | |
1061 start = clip_star.start.col; | |
1062 if (row == clip_star.end.lnum && end > (int)clip_star.end.col) | |
1063 end = clip_star.end.col; | |
1064 if (end > start) | |
1065 clip_invert_area(row, start, row, end, 0); | |
1066 } | |
1067 } | |
1068 # endif | |
1069 | |
1070 /* | |
1071 * Called from outside to clear selected region from the display | |
1072 */ | |
1073 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1074 clip_clear_selection(VimClipboard *cbd) |
7 | 1075 { |
1076 | |
3674 | 1077 if (cbd->state == SELECT_CLEARED) |
7 | 1078 return; |
1079 | |
3674 | 1080 clip_invert_area((int)cbd->start.lnum, cbd->start.col, (int)cbd->end.lnum, |
1081 cbd->end.col, CLIP_CLEAR); | |
1082 cbd->state = SELECT_CLEARED; | |
7 | 1083 } |
1084 | |
1085 /* | |
1086 * Clear the selection if any lines from "row1" to "row2" are inside of it. | |
1087 */ | |
1088 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1089 clip_may_clear_selection(int row1, int row2) |
7 | 1090 { |
1091 if (clip_star.state == SELECT_DONE | |
1092 && row2 >= clip_star.start.lnum | |
1093 && row1 <= clip_star.end.lnum) | |
3674 | 1094 clip_clear_selection(&clip_star); |
7 | 1095 } |
1096 | |
1097 /* | |
1098 * Called before the screen is scrolled up or down. Adjusts the line numbers | |
1099 * of the selection. Call with big number when clearing the screen. | |
1100 */ | |
1101 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1102 clip_scroll_selection( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1103 int rows) /* negative for scroll down */ |
7 | 1104 { |
1105 int lnum; | |
1106 | |
1107 if (clip_star.state == SELECT_CLEARED) | |
1108 return; | |
1109 | |
1110 lnum = clip_star.start.lnum - rows; | |
1111 if (lnum <= 0) | |
1112 clip_star.start.lnum = 0; | |
1113 else if (lnum >= screen_Rows) /* scrolled off of the screen */ | |
1114 clip_star.state = SELECT_CLEARED; | |
1115 else | |
1116 clip_star.start.lnum = lnum; | |
1117 | |
1118 lnum = clip_star.end.lnum - rows; | |
1119 if (lnum < 0) /* scrolled off of the screen */ | |
1120 clip_star.state = SELECT_CLEARED; | |
1121 else if (lnum >= screen_Rows) | |
1122 clip_star.end.lnum = screen_Rows - 1; | |
1123 else | |
1124 clip_star.end.lnum = lnum; | |
1125 } | |
1126 | |
1127 /* | |
1128 * Invert a region of the display between a starting and ending row and column | |
1129 * Values for "how": | |
1130 * CLIP_CLEAR: undo inversion | |
1131 * CLIP_SET: set inversion | |
1132 * CLIP_TOGGLE: set inversion if pos1 < pos2, undo inversion otherwise. | |
1133 * 0: invert (GUI only). | |
1134 */ | |
1135 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1136 clip_invert_area( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1137 int row1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1138 int col1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1139 int row2, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1140 int col2, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1141 int how) |
7 | 1142 { |
1143 int invert = FALSE; | |
1144 | |
1145 if (how == CLIP_SET) | |
1146 invert = TRUE; | |
1147 | |
1148 /* Swap the from and to positions so the from is always before */ | |
1149 if (clip_compare_pos(row1, col1, row2, col2) > 0) | |
1150 { | |
1151 int tmp_row, tmp_col; | |
1152 | |
1153 tmp_row = row1; | |
1154 tmp_col = col1; | |
1155 row1 = row2; | |
1156 col1 = col2; | |
1157 row2 = tmp_row; | |
1158 col2 = tmp_col; | |
1159 } | |
1160 else if (how == CLIP_TOGGLE) | |
1161 invert = TRUE; | |
1162 | |
1163 /* If all on the same line, do it the easy way */ | |
1164 if (row1 == row2) | |
1165 { | |
1166 clip_invert_rectangle(row1, col1, 1, col2 - col1, invert); | |
1167 } | |
1168 else | |
1169 { | |
1170 /* Handle a piece of the first line */ | |
1171 if (col1 > 0) | |
1172 { | |
1173 clip_invert_rectangle(row1, col1, 1, (int)Columns - col1, invert); | |
1174 row1++; | |
1175 } | |
1176 | |
1177 /* Handle a piece of the last line */ | |
1178 if (col2 < Columns - 1) | |
1179 { | |
1180 clip_invert_rectangle(row2, 0, 1, col2, invert); | |
1181 row2--; | |
1182 } | |
1183 | |
1184 /* Handle the rectangle thats left */ | |
1185 if (row2 >= row1) | |
1186 clip_invert_rectangle(row1, 0, row2 - row1 + 1, (int)Columns, | |
1187 invert); | |
1188 } | |
1189 } | |
1190 | |
1191 /* | |
1192 * Invert or un-invert a rectangle of the screen. | |
1193 * "invert" is true if the result is inverted. | |
1194 */ | |
1195 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1196 clip_invert_rectangle( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1197 int row, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1198 int col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1199 int height, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1200 int width, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1201 int invert) |
7 | 1202 { |
1203 #ifdef FEAT_GUI | |
1204 if (gui.in_use) | |
1205 gui_mch_invert_rectangle(row, col, height, width); | |
1206 else | |
1207 #endif | |
1208 screen_draw_rectangle(row, col, height, width, invert); | |
1209 } | |
1210 | |
1211 /* | |
1212 * Copy the currently selected area into the '*' register so it will be | |
1213 * available for pasting. | |
1214 * When "both" is TRUE also copy to the '+' register. | |
1215 */ | |
1216 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1217 clip_copy_modeless_selection(int both UNUSED) |
7 | 1218 { |
1219 char_u *buffer; | |
1220 char_u *bufp; | |
1221 int row; | |
1222 int start_col; | |
1223 int end_col; | |
1224 int line_end_col; | |
1225 int add_newline_flag = FALSE; | |
1226 int len; | |
1227 #ifdef FEAT_MBYTE | |
1228 char_u *p; | |
1229 #endif | |
1230 int row1 = clip_star.start.lnum; | |
1231 int col1 = clip_star.start.col; | |
1232 int row2 = clip_star.end.lnum; | |
1233 int col2 = clip_star.end.col; | |
1234 | |
534 | 1235 /* Can't use ScreenLines unless initialized */ |
1236 if (ScreenLines == NULL) | |
1237 return; | |
1238 | |
7 | 1239 /* |
1240 * Make sure row1 <= row2, and if row1 == row2 that col1 <= col2. | |
1241 */ | |
1242 if (row1 > row2) | |
1243 { | |
1244 row = row1; row1 = row2; row2 = row; | |
1245 row = col1; col1 = col2; col2 = row; | |
1246 } | |
1247 else if (row1 == row2 && col1 > col2) | |
1248 { | |
1249 row = col1; col1 = col2; col2 = row; | |
1250 } | |
1251 #ifdef FEAT_MBYTE | |
1252 /* correct starting point for being on right halve of double-wide char */ | |
1253 p = ScreenLines + LineOffset[row1]; | |
1254 if (enc_dbcs != 0) | |
1255 col1 -= (*mb_head_off)(p, p + col1); | |
1256 else if (enc_utf8 && p[col1] == 0) | |
1257 --col1; | |
1258 #endif | |
1259 | |
1260 /* Create a temporary buffer for storing the text */ | |
1261 len = (row2 - row1 + 1) * Columns + 1; | |
1262 #ifdef FEAT_MBYTE | |
1263 if (enc_dbcs != 0) | |
1264 len *= 2; /* max. 2 bytes per display cell */ | |
1265 else if (enc_utf8) | |
714 | 1266 len *= MB_MAXBYTES; |
7 | 1267 #endif |
1268 buffer = lalloc((long_u)len, TRUE); | |
1269 if (buffer == NULL) /* out of memory */ | |
1270 return; | |
1271 | |
1272 /* Process each row in the selection */ | |
1273 for (bufp = buffer, row = row1; row <= row2; row++) | |
1274 { | |
1275 if (row == row1) | |
1276 start_col = col1; | |
1277 else | |
1278 start_col = 0; | |
1279 | |
1280 if (row == row2) | |
1281 end_col = col2; | |
1282 else | |
1283 end_col = Columns; | |
1284 | |
1285 line_end_col = clip_get_line_end(row); | |
1286 | |
1287 /* See if we need to nuke some trailing whitespace */ | |
1288 if (end_col >= Columns && (row < row2 || end_col > line_end_col)) | |
1289 { | |
1290 /* Get rid of trailing whitespace */ | |
1291 end_col = line_end_col; | |
1292 if (end_col < start_col) | |
1293 end_col = start_col; | |
1294 | |
1295 /* If the last line extended to the end, add an extra newline */ | |
1296 if (row == row2) | |
1297 add_newline_flag = TRUE; | |
1298 } | |
1299 | |
1300 /* If after the first row, we need to always add a newline */ | |
1301 if (row > row1 && !LineWraps[row - 1]) | |
1302 *bufp++ = NL; | |
1303 | |
1304 if (row < screen_Rows && end_col <= screen_Columns) | |
1305 { | |
1306 #ifdef FEAT_MBYTE | |
1307 if (enc_dbcs != 0) | |
1308 { | |
944 | 1309 int i; |
1310 | |
7 | 1311 p = ScreenLines + LineOffset[row]; |
1312 for (i = start_col; i < end_col; ++i) | |
1313 if (enc_dbcs == DBCS_JPNU && p[i] == 0x8e) | |
1314 { | |
1315 /* single-width double-byte char */ | |
1316 *bufp++ = 0x8e; | |
1317 *bufp++ = ScreenLines2[LineOffset[row] + i]; | |
1318 } | |
1319 else | |
1320 { | |
1321 *bufp++ = p[i]; | |
1322 if (MB_BYTE2LEN(p[i]) == 2) | |
1323 *bufp++ = p[++i]; | |
1324 } | |
1325 } | |
1326 else if (enc_utf8) | |
1327 { | |
1328 int off; | |
714 | 1329 int i; |
761 | 1330 int ci; |
7 | 1331 |
1332 off = LineOffset[row]; | |
1333 for (i = start_col; i < end_col; ++i) | |
1334 { | |
1335 /* The base character is either in ScreenLinesUC[] or | |
1336 * ScreenLines[]. */ | |
1337 if (ScreenLinesUC[off + i] == 0) | |
1338 *bufp++ = ScreenLines[off + i]; | |
1339 else | |
1340 { | |
1341 bufp += utf_char2bytes(ScreenLinesUC[off + i], bufp); | |
761 | 1342 for (ci = 0; ci < Screen_mco; ++ci) |
7 | 1343 { |
714 | 1344 /* Add a composing character. */ |
761 | 1345 if (ScreenLinesC[ci][off + i] == 0) |
714 | 1346 break; |
761 | 1347 bufp += utf_char2bytes(ScreenLinesC[ci][off + i], |
7 | 1348 bufp); |
1349 } | |
1350 } | |
1351 /* Skip right halve of double-wide character. */ | |
1352 if (ScreenLines[off + i + 1] == 0) | |
1353 ++i; | |
1354 } | |
1355 } | |
1356 else | |
1357 #endif | |
1358 { | |
1359 STRNCPY(bufp, ScreenLines + LineOffset[row] + start_col, | |
1360 end_col - start_col); | |
1361 bufp += end_col - start_col; | |
1362 } | |
1363 } | |
1364 } | |
1365 | |
1366 /* Add a newline at the end if the selection ended there */ | |
1367 if (add_newline_flag) | |
1368 *bufp++ = NL; | |
1369 | |
1370 /* First cleanup any old selection and become the owner. */ | |
1371 clip_free_selection(&clip_star); | |
1372 clip_own_selection(&clip_star); | |
1373 | |
1374 /* Yank the text into the '*' register. */ | |
1375 clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), &clip_star); | |
1376 | |
1377 /* Make the register contents available to the outside world. */ | |
1378 clip_gen_set_selection(&clip_star); | |
1379 | |
1380 #ifdef FEAT_X11 | |
1381 if (both) | |
1382 { | |
1383 /* Do the same for the '+' register. */ | |
1384 clip_free_selection(&clip_plus); | |
1385 clip_own_selection(&clip_plus); | |
1386 clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), &clip_plus); | |
1387 clip_gen_set_selection(&clip_plus); | |
1388 } | |
1389 #endif | |
1390 vim_free(buffer); | |
1391 } | |
1392 | |
1393 /* | |
1394 * Find the starting and ending positions of the word at the given row and | |
1395 * column. Only white-separated words are recognized here. | |
1396 */ | |
1397 #define CHAR_CLASS(c) (c <= ' ' ? ' ' : vim_iswordc(c)) | |
1398 | |
1399 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1400 clip_get_word_boundaries(VimClipboard *cb, int row, int col) |
7 | 1401 { |
1402 int start_class; | |
1403 int temp_col; | |
1404 char_u *p; | |
1405 #ifdef FEAT_MBYTE | |
1406 int mboff; | |
1407 #endif | |
1408 | |
534 | 1409 if (row >= screen_Rows || col >= screen_Columns || ScreenLines == NULL) |
7 | 1410 return; |
1411 | |
1412 p = ScreenLines + LineOffset[row]; | |
1413 #ifdef FEAT_MBYTE | |
1414 /* Correct for starting in the right halve of a double-wide char */ | |
1415 if (enc_dbcs != 0) | |
1416 col -= dbcs_screen_head_off(p, p + col); | |
1417 else if (enc_utf8 && p[col] == 0) | |
1418 --col; | |
1419 #endif | |
1420 start_class = CHAR_CLASS(p[col]); | |
1421 | |
1422 temp_col = col; | |
1423 for ( ; temp_col > 0; temp_col--) | |
1424 #ifdef FEAT_MBYTE | |
1425 if (enc_dbcs != 0 | |
1426 && (mboff = dbcs_screen_head_off(p, p + temp_col - 1)) > 0) | |
1427 temp_col -= mboff; | |
1428 else | |
1429 #endif | |
1430 if (CHAR_CLASS(p[temp_col - 1]) != start_class | |
1431 #ifdef FEAT_MBYTE | |
1432 && !(enc_utf8 && p[temp_col - 1] == 0) | |
1433 #endif | |
1434 ) | |
1435 break; | |
1436 cb->word_start_col = temp_col; | |
1437 | |
1438 temp_col = col; | |
1439 for ( ; temp_col < screen_Columns; temp_col++) | |
1440 #ifdef FEAT_MBYTE | |
1441 if (enc_dbcs != 0 && dbcs_ptr2cells(p + temp_col) == 2) | |
1442 ++temp_col; | |
1443 else | |
1444 #endif | |
1445 if (CHAR_CLASS(p[temp_col]) != start_class | |
1446 #ifdef FEAT_MBYTE | |
1447 && !(enc_utf8 && p[temp_col] == 0) | |
1448 #endif | |
1449 ) | |
1450 break; | |
1451 cb->word_end_col = temp_col; | |
1452 } | |
1453 | |
1454 /* | |
1455 * Find the column position for the last non-whitespace character on the given | |
1456 * line. | |
1457 */ | |
1458 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1459 clip_get_line_end(int row) |
7 | 1460 { |
1461 int i; | |
1462 | |
534 | 1463 if (row >= screen_Rows || ScreenLines == NULL) |
7 | 1464 return 0; |
1465 for (i = screen_Columns; i > 0; i--) | |
1466 if (ScreenLines[LineOffset[row] + i - 1] != ' ') | |
1467 break; | |
1468 return i; | |
1469 } | |
1470 | |
1471 /* | |
1472 * Update the currently selected region by adding and/or subtracting from the | |
1473 * beginning or end and inverting the changed area(s). | |
1474 */ | |
1475 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1476 clip_update_modeless_selection( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1477 VimClipboard *cb, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1478 int row1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1479 int col1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1480 int row2, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1481 int col2) |
7 | 1482 { |
1483 /* See if we changed at the beginning of the selection */ | |
1484 if (row1 != cb->start.lnum || col1 != (int)cb->start.col) | |
1485 { | |
1486 clip_invert_area(row1, col1, (int)cb->start.lnum, cb->start.col, | |
1487 CLIP_TOGGLE); | |
1488 cb->start.lnum = row1; | |
1489 cb->start.col = col1; | |
1490 } | |
1491 | |
1492 /* See if we changed at the end of the selection */ | |
1493 if (row2 != cb->end.lnum || col2 != (int)cb->end.col) | |
1494 { | |
1495 clip_invert_area((int)cb->end.lnum, cb->end.col, row2, col2, | |
1496 CLIP_TOGGLE); | |
1497 cb->end.lnum = row2; | |
1498 cb->end.col = col2; | |
1499 } | |
1500 } | |
1501 | |
1502 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1503 clip_gen_own_selection(VimClipboard *cbd) |
7 | 1504 { |
1505 #ifdef FEAT_XCLIPBOARD | |
1506 # ifdef FEAT_GUI | |
1507 if (gui.in_use) | |
1508 return clip_mch_own_selection(cbd); | |
1509 else | |
1510 # endif | |
1511 return clip_xterm_own_selection(cbd); | |
1512 #else | |
1513 return clip_mch_own_selection(cbd); | |
1514 #endif | |
1515 } | |
1516 | |
1517 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1518 clip_gen_lose_selection(VimClipboard *cbd) |
7 | 1519 { |
1520 #ifdef FEAT_XCLIPBOARD | |
1521 # ifdef FEAT_GUI | |
1522 if (gui.in_use) | |
1523 clip_mch_lose_selection(cbd); | |
1524 else | |
1525 # endif | |
1526 clip_xterm_lose_selection(cbd); | |
1527 #else | |
1528 clip_mch_lose_selection(cbd); | |
1529 #endif | |
1530 } | |
1531 | |
1532 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1533 clip_gen_set_selection(VimClipboard *cbd) |
7 | 1534 { |
6116 | 1535 if (!clip_did_set_selection) |
1536 { | |
1537 /* Updating postponed, so that accessing the system clipboard won't | |
1538 * hang Vim when accessing it many times (e.g. on a :g comand). */ | |
6543 | 1539 if ((cbd == &clip_plus && (clip_unnamed_saved & CLIP_UNNAMED_PLUS)) |
1540 || (cbd == &clip_star && (clip_unnamed_saved & CLIP_UNNAMED))) | |
1541 { | |
1542 clipboard_needs_update = TRUE; | |
6116 | 1543 return; |
6543 | 1544 } |
6116 | 1545 } |
7 | 1546 #ifdef FEAT_XCLIPBOARD |
1547 # ifdef FEAT_GUI | |
1548 if (gui.in_use) | |
1549 clip_mch_set_selection(cbd); | |
1550 else | |
1551 # endif | |
1552 clip_xterm_set_selection(cbd); | |
1553 #else | |
1554 clip_mch_set_selection(cbd); | |
1555 #endif | |
1556 } | |
1557 | |
1558 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1559 clip_gen_request_selection(VimClipboard *cbd) |
7 | 1560 { |
1561 #ifdef FEAT_XCLIPBOARD | |
1562 # ifdef FEAT_GUI | |
1563 if (gui.in_use) | |
1564 clip_mch_request_selection(cbd); | |
1565 else | |
1566 # endif | |
1567 clip_xterm_request_selection(cbd); | |
1568 #else | |
1569 clip_mch_request_selection(cbd); | |
1570 #endif | |
1571 } | |
1572 | |
4209 | 1573 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1574 clip_gen_owner_exists(VimClipboard *cbd UNUSED) |
4209 | 1575 { |
1576 #ifdef FEAT_XCLIPBOARD | |
1577 # ifdef FEAT_GUI_GTK | |
1578 if (gui.in_use) | |
1579 return clip_gtk_owner_exists(cbd); | |
1580 else | |
1581 # endif | |
1582 return clip_x11_owner_exists(cbd); | |
5184
c6dd0c545e5c
updated for version 7.4a.018
Bram Moolenaar <bram@vim.org>
parents:
5136
diff
changeset
|
1583 #else |
c6dd0c545e5c
updated for version 7.4a.018
Bram Moolenaar <bram@vim.org>
parents:
5136
diff
changeset
|
1584 return TRUE; |
4209 | 1585 #endif |
1586 } | |
1587 | |
7 | 1588 #endif /* FEAT_CLIPBOARD */ |
1589 | |
1590 /***************************************************************************** | |
1591 * Functions that handle the input buffer. | |
1592 * This is used for any GUI version, and the unix terminal version. | |
1593 * | |
1594 * For Unix, the input characters are buffered to be able to check for a | |
1595 * CTRL-C. This should be done with signals, but I don't know how to do that | |
1596 * in a portable way for a tty in RAW mode. | |
1597 * | |
1598 * For the client-server code in the console the received keys are put in the | |
1599 * input buffer. | |
1600 */ | |
1601 | |
1602 #if defined(USE_INPUT_BUF) || defined(PROTO) | |
1603 | |
1604 /* | |
1605 * Internal typeahead buffer. Includes extra space for long key code | |
1606 * descriptions which would otherwise overflow. The buffer is considered full | |
1607 * when only this extra space (or part of it) remains. | |
1608 */ | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8393
diff
changeset
|
1609 #if defined(FEAT_SUN_WORKSHOP) || defined(FEAT_JOB_CHANNEL) \ |
7 | 1610 || defined(FEAT_CLIENTSERVER) |
1611 /* | |
1612 * Sun WorkShop and NetBeans stuff debugger commands into the input buffer. | |
1613 * This requires a larger buffer... | |
1614 * (Madsen) Go with this for remote input as well ... | |
1615 */ | |
1616 # define INBUFLEN 4096 | |
1617 #else | |
1618 # define INBUFLEN 250 | |
1619 #endif | |
1620 | |
1621 static char_u inbuf[INBUFLEN + MAX_KEY_CODE_LEN]; | |
1622 static int inbufcount = 0; /* number of chars in inbuf[] */ | |
1623 | |
1624 /* | |
1625 * vim_is_input_buf_full(), vim_is_input_buf_empty(), add_to_input_buf(), and | |
1626 * trash_input_buf() are functions for manipulating the input buffer. These | |
1627 * are used by the gui_* calls when a GUI is used to handle keyboard input. | |
1628 */ | |
1629 | |
1630 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1631 vim_is_input_buf_full(void) |
7 | 1632 { |
1633 return (inbufcount >= INBUFLEN); | |
1634 } | |
1635 | |
1636 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1637 vim_is_input_buf_empty(void) |
7 | 1638 { |
1639 return (inbufcount == 0); | |
1640 } | |
1641 | |
1642 #if defined(FEAT_OLE) || defined(PROTO) | |
1643 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1644 vim_free_in_input_buf(void) |
7 | 1645 { |
1646 return (INBUFLEN - inbufcount); | |
1647 } | |
1648 #endif | |
1649 | |
575 | 1650 #if defined(FEAT_GUI_GTK) || defined(PROTO) |
7 | 1651 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1652 vim_used_in_input_buf(void) |
7 | 1653 { |
1654 return inbufcount; | |
1655 } | |
1656 #endif | |
1657 | |
1658 /* | |
1659 * Return the current contents of the input buffer and make it empty. | |
1660 * The returned pointer must be passed to set_input_buf() later. | |
1661 */ | |
1662 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1663 get_input_buf(void) |
7 | 1664 { |
1665 garray_T *gap; | |
1666 | |
1667 /* We use a growarray to store the data pointer and the length. */ | |
1668 gap = (garray_T *)alloc((unsigned)sizeof(garray_T)); | |
1669 if (gap != NULL) | |
1670 { | |
1671 /* Add one to avoid a zero size. */ | |
1672 gap->ga_data = alloc((unsigned)inbufcount + 1); | |
1673 if (gap->ga_data != NULL) | |
1674 mch_memmove(gap->ga_data, inbuf, (size_t)inbufcount); | |
1675 gap->ga_len = inbufcount; | |
1676 } | |
1677 trash_input_buf(); | |
1678 return (char_u *)gap; | |
1679 } | |
1680 | |
1681 /* | |
1682 * Restore the input buffer with a pointer returned from get_input_buf(). | |
1683 * The allocated memory is freed, this only works once! | |
1684 */ | |
1685 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1686 set_input_buf(char_u *p) |
7 | 1687 { |
1688 garray_T *gap = (garray_T *)p; | |
1689 | |
1690 if (gap != NULL) | |
1691 { | |
1692 if (gap->ga_data != NULL) | |
1693 { | |
1694 mch_memmove(inbuf, gap->ga_data, gap->ga_len); | |
1695 inbufcount = gap->ga_len; | |
1696 vim_free(gap->ga_data); | |
1697 } | |
1698 vim_free(gap); | |
1699 } | |
1700 } | |
1701 | |
1702 /* | |
1703 * Add the given bytes to the input buffer | |
1704 * Special keys start with CSI. A real CSI must have been translated to | |
1705 * CSI KS_EXTRA KE_CSI. K_SPECIAL doesn't require translation. | |
1706 */ | |
1707 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1708 add_to_input_buf(char_u *s, int len) |
7 | 1709 { |
1710 if (inbufcount + len > INBUFLEN + MAX_KEY_CODE_LEN) | |
1711 return; /* Shouldn't ever happen! */ | |
1712 | |
1713 #ifdef FEAT_HANGULIN | |
1714 if ((State & (INSERT|CMDLINE)) && hangul_input_state_get()) | |
1715 if ((len = hangul_input_process(s, len)) == 0) | |
1716 return; | |
1717 #endif | |
1718 | |
1719 while (len--) | |
1720 inbuf[inbufcount++] = *s++; | |
1721 } | |
1722 | |
1723 /* | |
1724 * Add "str[len]" to the input buffer while escaping CSI bytes. | |
1725 */ | |
1726 void | |
1727 add_to_input_buf_csi(char_u *str, int len) | |
1728 { | |
1729 int i; | |
1730 char_u buf[2]; | |
1731 | |
1732 for (i = 0; i < len; ++i) | |
1733 { | |
1734 add_to_input_buf(str + i, 1); | |
1735 if (str[i] == CSI) | |
1736 { | |
1737 /* Turn CSI into K_CSI. */ | |
1738 buf[0] = KS_EXTRA; | |
1739 buf[1] = (int)KE_CSI; | |
1740 add_to_input_buf(buf, 2); | |
1741 } | |
1742 } | |
1743 } | |
1744 | |
1745 #if defined(FEAT_HANGULIN) || defined(PROTO) | |
1746 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1747 push_raw_key(char_u *s, int len) |
7 | 1748 { |
7208
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7080
diff
changeset
|
1749 char_u *tmpbuf; |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1750 char_u *inp = s; |
7208
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7080
diff
changeset
|
1751 |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1752 /* use the conversion result if possible */ |
7208
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7080
diff
changeset
|
1753 tmpbuf = hangul_string_convert(s, &len); |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7080
diff
changeset
|
1754 if (tmpbuf != NULL) |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1755 inp = tmpbuf; |
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1756 |
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1757 for (; len--; inp++) |
8366
6099e8185045
commit https://github.com/vim/vim/commit/00ded43a5a85df57abb74f9e3a38a401f6fbd8fd
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1758 { |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1759 inbuf[inbufcount++] = *inp; |
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1760 if (*inp == CSI) |
8366
6099e8185045
commit https://github.com/vim/vim/commit/00ded43a5a85df57abb74f9e3a38a401f6fbd8fd
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1761 { |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1762 /* Turn CSI into K_CSI. */ |
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1763 inbuf[inbufcount++] = KS_EXTRA; |
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1764 inbuf[inbufcount++] = (int)KE_CSI; |
8366
6099e8185045
commit https://github.com/vim/vim/commit/00ded43a5a85df57abb74f9e3a38a401f6fbd8fd
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1765 } |
6099e8185045
commit https://github.com/vim/vim/commit/00ded43a5a85df57abb74f9e3a38a401f6fbd8fd
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1766 } |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1767 vim_free(tmpbuf); |
7 | 1768 } |
1769 #endif | |
1770 | |
1771 /* Remove everything from the input buffer. Called when ^C is found */ | |
1772 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1773 trash_input_buf(void) |
7 | 1774 { |
1775 inbufcount = 0; | |
1776 } | |
1777 | |
1778 /* | |
1779 * Read as much data from the input buffer as possible up to maxlen, and store | |
1780 * it in buf. | |
1781 */ | |
1782 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1783 read_from_input_buf(char_u *buf, long maxlen) |
7 | 1784 { |
1785 if (inbufcount == 0) /* if the buffer is empty, fill it */ | |
1786 fill_input_buf(TRUE); | |
1787 if (maxlen > inbufcount) | |
1788 maxlen = inbufcount; | |
1789 mch_memmove(buf, inbuf, (size_t)maxlen); | |
1790 inbufcount -= maxlen; | |
1791 if (inbufcount) | |
1792 mch_memmove(inbuf, inbuf + maxlen, (size_t)inbufcount); | |
1793 return (int)maxlen; | |
1794 } | |
1795 | |
1796 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1797 fill_input_buf(int exit_on_error UNUSED) |
7 | 1798 { |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
1799 #if defined(UNIX) || defined(VMS) || defined(MACOS_X) |
7 | 1800 int len; |
1801 int try; | |
1802 static int did_read_something = FALSE; | |
1803 # ifdef FEAT_MBYTE | |
1804 static char_u *rest = NULL; /* unconverted rest of previous read */ | |
1805 static int restlen = 0; | |
1806 int unconverted; | |
1807 # endif | |
1808 #endif | |
1809 | |
1810 #ifdef FEAT_GUI | |
294 | 1811 if (gui.in_use |
1812 # ifdef NO_CONSOLE_INPUT | |
1813 /* Don't use the GUI input when the window hasn't been opened yet. | |
1814 * We get here from ui_inchar() when we should try reading from stdin. */ | |
1815 && !no_console_input() | |
1816 # endif | |
1817 ) | |
7 | 1818 { |
1819 gui_mch_update(); | |
1820 return; | |
1821 } | |
1822 #endif | |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
1823 #if defined(UNIX) || defined(VMS) || defined(MACOS_X) |
7 | 1824 if (vim_is_input_buf_full()) |
1825 return; | |
1826 /* | |
1827 * Fill_input_buf() is only called when we really need a character. | |
1828 * If we can't get any, but there is some in the buffer, just return. | |
1829 * If we can't get any, and there isn't any in the buffer, we give up and | |
1830 * exit Vim. | |
1831 */ | |
1832 # ifdef __BEOS__ | |
1833 /* | |
1834 * On the BeBox version (for now), all input is secretly performed within | |
1835 * beos_select() which is called from RealWaitForChar(). | |
1836 */ | |
1837 while (!vim_is_input_buf_full() && RealWaitForChar(read_cmd_fd, 0, NULL)) | |
1838 ; | |
1839 len = inbufcount; | |
1840 inbufcount = 0; | |
1841 # else | |
1842 | |
8281
74b15ed0a259
commit https://github.com/vim/vim/commit/85b11769ab507c7df93f319fd964fa579701b76b
Christian Brabandt <cb@256bit.org>
parents:
8236
diff
changeset
|
1843 # ifdef FEAT_MBYTE |
7 | 1844 if (rest != NULL) |
1845 { | |
1846 /* Use remainder of previous call, starts with an invalid character | |
1847 * that may become valid when reading more. */ | |
1848 if (restlen > INBUFLEN - inbufcount) | |
1849 unconverted = INBUFLEN - inbufcount; | |
1850 else | |
1851 unconverted = restlen; | |
1852 mch_memmove(inbuf + inbufcount, rest, unconverted); | |
1853 if (unconverted == restlen) | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
1854 VIM_CLEAR(rest); |
7 | 1855 else |
1856 { | |
1857 restlen -= unconverted; | |
1858 mch_memmove(rest, rest + unconverted, restlen); | |
1859 } | |
1860 inbufcount += unconverted; | |
1861 } | |
1862 else | |
1863 unconverted = 0; | |
8281
74b15ed0a259
commit https://github.com/vim/vim/commit/85b11769ab507c7df93f319fd964fa579701b76b
Christian Brabandt <cb@256bit.org>
parents:
8236
diff
changeset
|
1864 # endif |
7 | 1865 |
1866 len = 0; /* to avoid gcc warning */ | |
1867 for (try = 0; try < 100; ++try) | |
1868 { | |
13758
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
1869 size_t readlen = (size_t)((INBUFLEN - inbufcount) |
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
1870 # ifdef FEAT_MBYTE |
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
1871 / input_conv.vc_factor |
7 | 1872 # endif |
13758
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
1873 ); |
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
1874 # ifdef VMS |
13776
ef6de4674811
patch 8.0.1760: wrong number of arguments to vms_read()
Christian Brabandt <cb@256bit.org>
parents:
13758
diff
changeset
|
1875 len = vms_read((char *)inbuf + inbufcount, readlen); |
13758
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
1876 # else |
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
1877 len = read(read_cmd_fd, (char *)inbuf + inbufcount, readlen); |
7 | 1878 # endif |
169 | 1879 |
7 | 1880 if (len > 0 || got_int) |
1881 break; | |
1882 /* | |
1883 * If reading stdin results in an error, continue reading stderr. | |
1884 * This helps when using "foo | xargs vim". | |
1885 */ | |
1886 if (!did_read_something && !isatty(read_cmd_fd) && read_cmd_fd == 0) | |
1887 { | |
1888 int m = cur_tmode; | |
1889 | |
1890 /* We probably set the wrong file descriptor to raw mode. Switch | |
1891 * back to cooked mode, use another descriptor and set the mode to | |
1892 * what it was. */ | |
1893 settmode(TMODE_COOK); | |
1894 #ifdef HAVE_DUP | |
1895 /* Use stderr for stdin, also works for shell commands. */ | |
1896 close(0); | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1897 vim_ignored = dup(2); |
7 | 1898 #else |
1899 read_cmd_fd = 2; /* read from stderr instead of stdin */ | |
1900 #endif | |
1901 settmode(m); | |
1902 } | |
1903 if (!exit_on_error) | |
1904 return; | |
1905 } | |
1906 # endif | |
1907 if (len <= 0 && !got_int) | |
1908 read_error_exit(); | |
1909 if (len > 0) | |
1910 did_read_something = TRUE; | |
1911 if (got_int) | |
1912 { | |
1913 /* Interrupted, pretend a CTRL-C was typed. */ | |
1914 inbuf[0] = 3; | |
1915 inbufcount = 1; | |
1916 } | |
1917 else | |
1918 { | |
1919 # ifdef FEAT_MBYTE | |
1920 /* | |
1921 * May perform conversion on the input characters. | |
1922 * Include the unconverted rest of the previous call. | |
1923 * If there is an incomplete char at the end it is kept for the next | |
1924 * time, reading more bytes should make conversion possible. | |
1925 * Don't do this in the unlikely event that the input buffer is too | |
1926 * small ("rest" still contains more bytes). | |
1927 */ | |
1928 if (input_conv.vc_type != CONV_NONE) | |
1929 { | |
1930 inbufcount -= unconverted; | |
1931 len = convert_input_safe(inbuf + inbufcount, | |
1932 len + unconverted, INBUFLEN - inbufcount, | |
1933 rest == NULL ? &rest : NULL, &restlen); | |
1934 } | |
1935 # endif | |
1936 while (len-- > 0) | |
1937 { | |
1938 /* | |
1939 * if a CTRL-C was typed, remove it from the buffer and set got_int | |
1940 */ | |
1941 if (inbuf[inbufcount] == 3 && ctrl_c_interrupts) | |
1942 { | |
1943 /* remove everything typed before the CTRL-C */ | |
1944 mch_memmove(inbuf, inbuf + inbufcount, (size_t)(len + 1)); | |
1945 inbufcount = 0; | |
1946 got_int = TRUE; | |
1947 } | |
1948 ++inbufcount; | |
1949 } | |
1950 } | |
7408
1886f2863437
commit https://github.com/vim/vim/commit/e7fedb6ebe72d9a475aa65109b77d5ed4667067a
Christian Brabandt <cb@256bit.org>
parents:
7208
diff
changeset
|
1951 #endif /* UNIX or VMS*/ |
7 | 1952 } |
7408
1886f2863437
commit https://github.com/vim/vim/commit/e7fedb6ebe72d9a475aa65109b77d5ed4667067a
Christian Brabandt <cb@256bit.org>
parents:
7208
diff
changeset
|
1953 #endif /* defined(UNIX) || defined(FEAT_GUI) || defined(VMS) */ |
7 | 1954 |
1955 /* | |
1956 * Exit because of an input read error. | |
1957 */ | |
1958 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1959 read_error_exit(void) |
7 | 1960 { |
1961 if (silent_mode) /* Normal way to exit for "ex -s" */ | |
1962 getout(0); | |
1963 STRCPY(IObuff, _("Vim: Error reading input, exiting...\n")); | |
1964 preserve_exit(); | |
1965 } | |
1966 | |
1967 #if defined(CURSOR_SHAPE) || defined(PROTO) | |
1968 /* | |
1969 * May update the shape of the cursor. | |
1970 */ | |
1971 void | |
12076
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1972 ui_cursor_shape_forced(int forced) |
7 | 1973 { |
1974 # ifdef FEAT_GUI | |
1975 if (gui.in_use) | |
1976 gui_update_cursor_later(); | |
36 | 1977 else |
7 | 1978 # endif |
12076
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1979 term_cursor_mode(forced); |
36 | 1980 |
7 | 1981 # ifdef MCH_CURSOR_SHAPE |
1982 mch_update_cursor(); | |
1983 # endif | |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1984 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1985 # ifdef FEAT_CONCEAL |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13776
diff
changeset
|
1986 conceal_check_cursor_line(); |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1987 # endif |
7 | 1988 } |
12076
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1989 |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1990 void |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1991 ui_cursor_shape(void) |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1992 { |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1993 ui_cursor_shape_forced(FALSE); |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1994 } |
7 | 1995 #endif |
1996 | |
1997 #if defined(FEAT_CLIPBOARD) || defined(FEAT_GUI) || defined(FEAT_RIGHTLEFT) \ | |
1671 | 1998 || defined(FEAT_MBYTE) || defined(PROTO) |
7 | 1999 /* |
2000 * Check bounds for column number | |
2001 */ | |
2002 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2003 check_col(int col) |
7 | 2004 { |
2005 if (col < 0) | |
2006 return 0; | |
2007 if (col >= (int)screen_Columns) | |
2008 return (int)screen_Columns - 1; | |
2009 return col; | |
2010 } | |
2011 | |
2012 /* | |
2013 * Check bounds for row number | |
2014 */ | |
2015 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2016 check_row(int row) |
7 | 2017 { |
2018 if (row < 0) | |
2019 return 0; | |
2020 if (row >= (int)screen_Rows) | |
2021 return (int)screen_Rows - 1; | |
2022 return row; | |
2023 } | |
2024 #endif | |
2025 | |
2026 /* | |
2027 * Stuff for the X clipboard. Shared between VMS and Unix. | |
2028 */ | |
2029 | |
2030 #if defined(FEAT_XCLIPBOARD) || defined(FEAT_GUI_X11) || defined(PROTO) | |
2031 # include <X11/Xatom.h> | |
2032 # include <X11/Intrinsic.h> | |
2033 | |
2034 /* | |
2035 * Open the application context (if it hasn't been opened yet). | |
2036 * Used for Motif and Athena GUI and the xterm clipboard. | |
2037 */ | |
2038 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2039 open_app_context(void) |
7 | 2040 { |
2041 if (app_context == NULL) | |
2042 { | |
2043 XtToolkitInitialize(); | |
2044 app_context = XtCreateApplicationContext(); | |
2045 } | |
2046 } | |
2047 | |
2048 static Atom vim_atom; /* Vim's own special selection format */ | |
2049 #ifdef FEAT_MBYTE | |
2050 static Atom vimenc_atom; /* Vim's extended selection format */ | |
3346 | 2051 static Atom utf8_atom; |
7 | 2052 #endif |
2053 static Atom compound_text_atom; | |
2054 static Atom text_atom; | |
2055 static Atom targets_atom; | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2056 static Atom timestamp_atom; /* Used to get a timestamp */ |
7 | 2057 |
2058 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2059 x11_setup_atoms(Display *dpy) |
7 | 2060 { |
2061 vim_atom = XInternAtom(dpy, VIM_ATOM_NAME, False); | |
2062 #ifdef FEAT_MBYTE | |
2063 vimenc_atom = XInternAtom(dpy, VIMENC_ATOM_NAME,False); | |
3346 | 2064 utf8_atom = XInternAtom(dpy, "UTF8_STRING", False); |
7 | 2065 #endif |
2066 compound_text_atom = XInternAtom(dpy, "COMPOUND_TEXT", False); | |
2067 text_atom = XInternAtom(dpy, "TEXT", False); | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2068 targets_atom = XInternAtom(dpy, "TARGETS", False); |
7 | 2069 clip_star.sel_atom = XA_PRIMARY; |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2070 clip_plus.sel_atom = XInternAtom(dpy, "CLIPBOARD", False); |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2071 timestamp_atom = XInternAtom(dpy, "TIMESTAMP", False); |
7 | 2072 } |
2073 | |
2074 /* | |
2075 * X Selection stuff, for cutting and pasting text to other windows. | |
2076 */ | |
2077 | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2078 static Boolean clip_x11_convert_selection_cb(Widget w, Atom *sel_atom, Atom *target, Atom *type, XtPointer *value, long_u *length, int *format); |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2079 static void clip_x11_lose_ownership_cb(Widget w, Atom *sel_atom); |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2080 static void clip_x11_notify_cb(Widget w, Atom *sel_atom, Atom *target); |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2081 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2082 /* |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2083 * Property callback to get a timestamp for XtOwnSelection. |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2084 */ |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2085 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2086 clip_x11_timestamp_cb( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2087 Widget w, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2088 XtPointer n UNUSED, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2089 XEvent *event, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2090 Boolean *cont UNUSED) |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2091 { |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2092 Atom actual_type; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2093 int format; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2094 unsigned long nitems, bytes_after; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2095 unsigned char *prop=NULL; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2096 XPropertyEvent *xproperty=&event->xproperty; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2097 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2098 /* Must be a property notify, state can't be Delete (True), has to be |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2099 * one of the supported selection types. */ |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2100 if (event->type != PropertyNotify || xproperty->state |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2101 || (xproperty->atom != clip_star.sel_atom |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2102 && xproperty->atom != clip_plus.sel_atom)) |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2103 return; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2104 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2105 if (XGetWindowProperty(xproperty->display, xproperty->window, |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2106 xproperty->atom, 0, 0, False, timestamp_atom, &actual_type, &format, |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2107 &nitems, &bytes_after, &prop)) |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2108 return; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2109 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2110 if (prop) |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2111 XFree(prop); |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2112 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2113 /* Make sure the property type is "TIMESTAMP" and it's 32 bits. */ |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2114 if (actual_type != timestamp_atom || format != 32) |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2115 return; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2116 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2117 /* Get the selection, using the event timestamp. */ |
2586 | 2118 if (XtOwnSelection(w, xproperty->atom, xproperty->time, |
2119 clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb, | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2120 clip_x11_notify_cb) == OK) |
2586 | 2121 { |
2122 /* Set the "owned" flag now, there may have been a call to | |
2123 * lose_ownership_cb in between. */ | |
2124 if (xproperty->atom == clip_plus.sel_atom) | |
2125 clip_plus.owned = TRUE; | |
2126 else | |
2127 clip_star.owned = TRUE; | |
2128 } | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2129 } |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2130 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2131 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2132 x11_setup_selection(Widget w) |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2133 { |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2134 XtAddEventHandler(w, PropertyChangeMask, False, |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2135 /*(XtEventHandler)*/clip_x11_timestamp_cb, (XtPointer)NULL); |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2136 } |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2137 |
7 | 2138 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2139 clip_x11_request_selection_cb( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2140 Widget w UNUSED, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2141 XtPointer success, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2142 Atom *sel_atom, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2143 Atom *type, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2144 XtPointer value, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2145 long_u *length, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2146 int *format) |
7 | 2147 { |
2896 | 2148 int motion_type = MAUTO; |
7 | 2149 long_u len; |
2150 char_u *p; | |
2151 char **text_list = NULL; | |
2152 VimClipboard *cbd; | |
2153 #ifdef FEAT_MBYTE | |
2154 char_u *tmpbuf = NULL; | |
2155 #endif | |
2156 | |
2157 if (*sel_atom == clip_plus.sel_atom) | |
2158 cbd = &clip_plus; | |
2159 else | |
2160 cbd = &clip_star; | |
2161 | |
2162 if (value == NULL || *length == 0) | |
2163 { | |
1719 | 2164 clip_free_selection(cbd); /* nothing received, clear register */ |
7 | 2165 *(int *)success = FALSE; |
2166 return; | |
2167 } | |
2168 p = (char_u *)value; | |
2169 len = *length; | |
2170 if (*type == vim_atom) | |
2171 { | |
2172 motion_type = *p++; | |
2173 len--; | |
2174 } | |
2175 | |
2176 #ifdef FEAT_MBYTE | |
2177 else if (*type == vimenc_atom) | |
2178 { | |
2179 char_u *enc; | |
2180 vimconv_T conv; | |
2181 int convlen; | |
2182 | |
2183 motion_type = *p++; | |
2184 --len; | |
2185 | |
2186 enc = p; | |
2187 p += STRLEN(p) + 1; | |
2188 len -= p - enc; | |
2189 | |
2190 /* If the encoding of the text is different from 'encoding', attempt | |
2191 * converting it. */ | |
2192 conv.vc_type = CONV_NONE; | |
2193 convert_setup(&conv, enc, p_enc); | |
2194 if (conv.vc_type != CONV_NONE) | |
2195 { | |
2196 convlen = len; /* Need to use an int here. */ | |
2197 tmpbuf = string_convert(&conv, p, &convlen); | |
2198 len = convlen; | |
2199 if (tmpbuf != NULL) | |
2200 p = tmpbuf; | |
2201 convert_setup(&conv, NULL, NULL); | |
2202 } | |
2203 } | |
2204 #endif | |
2205 | |
3346 | 2206 else if (*type == compound_text_atom |
2207 #ifdef FEAT_MBYTE | |
2208 || *type == utf8_atom | |
2209 #endif | |
2210 || ( | |
7 | 2211 #ifdef FEAT_MBYTE |
2212 enc_dbcs != 0 && | |
2213 #endif | |
2214 *type == text_atom)) | |
2215 { | |
2216 XTextProperty text_prop; | |
2217 int n_text = 0; | |
2218 int status; | |
2219 | |
2220 text_prop.value = (unsigned char *)value; | |
2221 text_prop.encoding = *type; | |
2222 text_prop.format = *format; | |
1719 | 2223 text_prop.nitems = len; |
4272 | 2224 #if defined(FEAT_MBYTE) && defined(X_HAVE_UTF8_STRING) |
4201 | 2225 if (*type == utf8_atom) |
2226 status = Xutf8TextPropertyToTextList(X_DISPLAY, &text_prop, | |
2227 &text_list, &n_text); | |
2228 else | |
2229 #endif | |
2230 status = XmbTextPropertyToTextList(X_DISPLAY, &text_prop, | |
7 | 2231 &text_list, &n_text); |
2232 if (status != Success || n_text < 1) | |
2233 { | |
2234 *(int *)success = FALSE; | |
2235 return; | |
2236 } | |
2237 p = (char_u *)text_list[0]; | |
2238 len = STRLEN(p); | |
2239 } | |
2240 clip_yank_selection(motion_type, p, (long)len, cbd); | |
2241 | |
2242 if (text_list != NULL) | |
2243 XFreeStringList(text_list); | |
2244 #ifdef FEAT_MBYTE | |
2245 vim_free(tmpbuf); | |
2246 #endif | |
2247 XtFree((char *)value); | |
2248 *(int *)success = TRUE; | |
2249 } | |
2250 | |
2251 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2252 clip_x11_request_selection( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2253 Widget myShell, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2254 Display *dpy, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2255 VimClipboard *cbd) |
7 | 2256 { |
2257 XEvent event; | |
2258 Atom type; | |
2259 static int success; | |
2260 int i; | |
1715 | 2261 time_t start_time; |
2262 int timed_out = FALSE; | |
7 | 2263 |
2264 for (i = | |
2265 #ifdef FEAT_MBYTE | |
2266 0 | |
2267 #else | |
2268 1 | |
2269 #endif | |
3346 | 2270 ; i < 6; i++) |
7 | 2271 { |
2272 switch (i) | |
2273 { | |
2274 #ifdef FEAT_MBYTE | |
2275 case 0: type = vimenc_atom; break; | |
2276 #endif | |
2277 case 1: type = vim_atom; break; | |
3346 | 2278 #ifdef FEAT_MBYTE |
2279 case 2: type = utf8_atom; break; | |
2280 #endif | |
2281 case 3: type = compound_text_atom; break; | |
2282 case 4: type = text_atom; break; | |
7 | 2283 default: type = XA_STRING; |
2284 } | |
3346 | 2285 #ifdef FEAT_MBYTE |
4272 | 2286 if (type == utf8_atom |
2287 # if defined(X_HAVE_UTF8_STRING) | |
2288 && !enc_utf8 | |
2289 # endif | |
2290 ) | |
2291 /* Only request utf-8 when 'encoding' is utf8 and | |
2292 * Xutf8TextPropertyToTextList is available. */ | |
3346 | 2293 continue; |
2294 #endif | |
1719 | 2295 success = MAYBE; |
7 | 2296 XtGetSelectionValue(myShell, cbd->sel_atom, type, |
2297 clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime); | |
2298 | |
2299 /* Make sure the request for the selection goes out before waiting for | |
2300 * a response. */ | |
2301 XFlush(dpy); | |
2302 | |
2303 /* | |
2304 * Wait for result of selection request, otherwise if we type more | |
2305 * characters, then they will appear before the one that requested the | |
2306 * paste! Don't worry, we will catch up with any other events later. | |
2307 */ | |
1715 | 2308 start_time = time(NULL); |
1719 | 2309 while (success == MAYBE) |
7 | 2310 { |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2311 if (XCheckTypedEvent(dpy, PropertyNotify, &event) |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2312 || XCheckTypedEvent(dpy, SelectionNotify, &event) |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2313 || XCheckTypedEvent(dpy, SelectionRequest, &event)) |
1715 | 2314 { |
1719 | 2315 /* This is where clip_x11_request_selection_cb() should be |
2316 * called. It may actually happen a bit later, so we loop | |
2317 * until "success" changes. | |
2318 * We may get a SelectionRequest here and if we don't handle | |
2319 * it we hang. KDE klipper does this, for example. | |
2320 * We need to handle a PropertyNotify for large selections. */ | |
1715 | 2321 XtDispatchEvent(&event); |
1719 | 2322 continue; |
1715 | 2323 } |
7 | 2324 |
1715 | 2325 /* Time out after 2 to 3 seconds to avoid that we hang when the |
2326 * other process doesn't respond. Note that the SelectionNotify | |
2327 * event may still come later when the selection owner comes back | |
1719 | 2328 * to life and the text gets inserted unexpectedly. Don't know |
2329 * why that happens or how to avoid that :-(. */ | |
1715 | 2330 if (time(NULL) > start_time + 2) |
2331 { | |
2332 timed_out = TRUE; | |
2333 break; | |
2334 } | |
2335 | |
7 | 2336 /* Do we need this? Probably not. */ |
2337 XSync(dpy, False); | |
2338 | |
1715 | 2339 /* Wait for 1 msec to avoid that we eat up all CPU time. */ |
2340 ui_delay(1L, TRUE); | |
7 | 2341 } |
2342 | |
1719 | 2343 if (success == TRUE) |
7 | 2344 return; |
1715 | 2345 |
2346 /* don't do a retry with another type after timing out, otherwise we | |
2347 * hang for 15 seconds. */ | |
2348 if (timed_out) | |
2349 break; | |
7 | 2350 } |
2351 | |
2352 /* Final fallback position - use the X CUT_BUFFER0 store */ | |
1924 | 2353 yank_cut_buffer0(dpy, cbd); |
7 | 2354 } |
2355 | |
2356 static Boolean | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2357 clip_x11_convert_selection_cb( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2358 Widget w UNUSED, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2359 Atom *sel_atom, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2360 Atom *target, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2361 Atom *type, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2362 XtPointer *value, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2363 long_u *length, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2364 int *format) |
7 | 2365 { |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2366 static char_u *save_result = NULL; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2367 static long_u save_length = 0; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2368 char_u *string; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2369 int motion_type; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2370 VimClipboard *cbd; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2371 int i; |
7 | 2372 |
2373 if (*sel_atom == clip_plus.sel_atom) | |
2374 cbd = &clip_plus; | |
2375 else | |
2376 cbd = &clip_star; | |
2377 | |
2378 if (!cbd->owned) | |
2379 return False; /* Shouldn't ever happen */ | |
2380 | |
2381 /* requestor wants to know what target types we support */ | |
2382 if (*target == targets_atom) | |
2383 { | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2384 static Atom array[7]; |
7 | 2385 |
2386 *value = (XtPointer)array; | |
2387 i = 0; | |
2388 array[i++] = targets_atom; | |
2389 #ifdef FEAT_MBYTE | |
2390 array[i++] = vimenc_atom; | |
2391 #endif | |
2392 array[i++] = vim_atom; | |
3346 | 2393 #ifdef FEAT_MBYTE |
2394 if (enc_utf8) | |
2395 array[i++] = utf8_atom; | |
2396 #endif | |
2397 array[i++] = XA_STRING; | |
7 | 2398 array[i++] = text_atom; |
2399 array[i++] = compound_text_atom; | |
3346 | 2400 |
7 | 2401 *type = XA_ATOM; |
2402 /* This used to be: *format = sizeof(Atom) * 8; but that caused | |
2403 * crashes on 64 bit machines. (Peter Derr) */ | |
2404 *format = 32; | |
2405 *length = i; | |
2406 return True; | |
2407 } | |
2408 | |
2409 if ( *target != XA_STRING | |
2410 #ifdef FEAT_MBYTE | |
2411 && *target != vimenc_atom | |
5956 | 2412 && (*target != utf8_atom || !enc_utf8) |
7 | 2413 #endif |
2414 && *target != vim_atom | |
2415 && *target != text_atom | |
2416 && *target != compound_text_atom) | |
2417 return False; | |
2418 | |
2419 clip_get_selection(cbd); | |
2420 motion_type = clip_convert_selection(&string, length, cbd); | |
2421 if (motion_type < 0) | |
2422 return False; | |
2423 | |
2424 /* For our own format, the first byte contains the motion type */ | |
2425 if (*target == vim_atom) | |
2426 (*length)++; | |
2427 | |
2428 #ifdef FEAT_MBYTE | |
2429 /* Our own format with encoding: motion 'encoding' NUL text */ | |
2430 if (*target == vimenc_atom) | |
2431 *length += STRLEN(p_enc) + 2; | |
2432 #endif | |
2433 | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2434 if (save_length < *length || save_length / 2 >= *length) |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2435 *value = XtRealloc((char *)save_result, (Cardinal)*length + 1); |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2436 else |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2437 *value = save_result; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2438 if (*value == NULL) |
7 | 2439 { |
2440 vim_free(string); | |
2441 return False; | |
2442 } | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2443 save_result = (char_u *)*value; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2444 save_length = *length; |
7 | 2445 |
3346 | 2446 if (*target == XA_STRING |
2447 #ifdef FEAT_MBYTE | |
2448 || (*target == utf8_atom && enc_utf8) | |
2449 #endif | |
2450 ) | |
7 | 2451 { |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2452 mch_memmove(save_result, string, (size_t)(*length)); |
3346 | 2453 *type = *target; |
7 | 2454 } |
3346 | 2455 else if (*target == compound_text_atom || *target == text_atom) |
7 | 2456 { |
2457 XTextProperty text_prop; | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2458 char *string_nt = (char *)save_result; |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2459 int conv_result; |
7 | 2460 |
2461 /* create NUL terminated string which XmbTextListToTextProperty wants */ | |
2462 mch_memmove(string_nt, string, (size_t)*length); | |
2463 string_nt[*length] = NUL; | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2464 conv_result = XmbTextListToTextProperty(X_DISPLAY, (char **)&string_nt, |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2465 1, XCompoundTextStyle, &text_prop); |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2466 if (conv_result != Success) |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2467 { |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2468 vim_free(string); |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2469 return False; |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2470 } |
7 | 2471 *value = (XtPointer)(text_prop.value); /* from plain text */ |
2472 *length = text_prop.nitems; | |
2473 *type = compound_text_atom; | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2474 XtFree((char *)save_result); |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2475 save_result = (char_u *)*value; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2476 save_length = *length; |
7 | 2477 } |
2478 #ifdef FEAT_MBYTE | |
2479 else if (*target == vimenc_atom) | |
2480 { | |
2481 int l = STRLEN(p_enc); | |
2482 | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2483 save_result[0] = motion_type; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2484 STRCPY(save_result + 1, p_enc); |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2485 mch_memmove(save_result + l + 2, string, (size_t)(*length - l - 2)); |
7 | 2486 *type = vimenc_atom; |
2487 } | |
2488 #endif | |
2489 else | |
2490 { | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2491 save_result[0] = motion_type; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2492 mch_memmove(save_result + 1, string, (size_t)(*length - 1)); |
7 | 2493 *type = vim_atom; |
2494 } | |
2495 *format = 8; /* 8 bits per char */ | |
2496 vim_free(string); | |
2497 return True; | |
2498 } | |
2499 | |
2500 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2501 clip_x11_lose_ownership_cb(Widget w UNUSED, Atom *sel_atom) |
7 | 2502 { |
2503 if (*sel_atom == clip_plus.sel_atom) | |
2504 clip_lose_selection(&clip_plus); | |
2505 else | |
2506 clip_lose_selection(&clip_star); | |
2507 } | |
2508 | |
2509 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2510 clip_x11_lose_selection(Widget myShell, VimClipboard *cbd) |
7 | 2511 { |
4209 | 2512 XtDisownSelection(myShell, cbd->sel_atom, |
2513 XtLastTimestampProcessed(XtDisplay(myShell))); | |
7 | 2514 } |
2515 | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2516 static void |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2517 clip_x11_notify_cb(Widget w UNUSED, Atom *sel_atom UNUSED, Atom *target UNUSED) |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2518 { |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2519 /* To prevent automatically freeing the selection value. */ |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2520 } |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2521 |
7 | 2522 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2523 clip_x11_own_selection(Widget myShell, VimClipboard *cbd) |
7 | 2524 { |
2586 | 2525 /* When using the GUI we have proper timestamps, use the one of the last |
2526 * event. When in the console we don't get events (the terminal gets | |
2527 * them), Get the time by a zero-length append, clip_x11_timestamp_cb will | |
2528 * be called with the current timestamp. */ | |
2529 #ifdef FEAT_GUI | |
2530 if (gui.in_use) | |
2531 { | |
2532 if (XtOwnSelection(myShell, cbd->sel_atom, | |
2533 XtLastTimestampProcessed(XtDisplay(myShell)), | |
2534 clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb, | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2535 clip_x11_notify_cb) == False) |
3312 | 2536 return FAIL; |
2586 | 2537 } |
2538 else | |
2539 #endif | |
2540 { | |
2541 if (!XChangeProperty(XtDisplay(myShell), XtWindow(myShell), | |
2542 cbd->sel_atom, timestamp_atom, 32, PropModeAppend, NULL, 0)) | |
3312 | 2543 return FAIL; |
2586 | 2544 } |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2545 /* Flush is required in a terminal as nothing else is doing it. */ |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2546 XFlush(XtDisplay(myShell)); |
7 | 2547 return OK; |
2548 } | |
2549 | |
2550 /* | |
2551 * Send the current selection to the clipboard. Do nothing for X because we | |
2552 * will fill in the selection only when requested by another app. | |
2553 */ | |
2554 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2555 clip_x11_set_selection(VimClipboard *cbd UNUSED) |
7 | 2556 { |
2557 } | |
4209 | 2558 |
2559 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2560 clip_x11_owner_exists(VimClipboard *cbd) |
4209 | 2561 { |
2562 return XGetSelectionOwner(X_DISPLAY, cbd->sel_atom) != None; | |
2563 } | |
7 | 2564 #endif |
2565 | |
1924 | 2566 #if defined(FEAT_XCLIPBOARD) || defined(FEAT_GUI_X11) \ |
2567 || defined(FEAT_GUI_GTK) || defined(PROTO) | |
2568 /* | |
2569 * Get the contents of the X CUT_BUFFER0 and put it in "cbd". | |
2570 */ | |
2571 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2572 yank_cut_buffer0(Display *dpy, VimClipboard *cbd) |
1924 | 2573 { |
2574 int nbytes = 0; | |
2575 char_u *buffer = (char_u *)XFetchBuffer(dpy, &nbytes, 0); | |
2576 | |
2577 if (nbytes > 0) | |
2578 { | |
2579 #ifdef FEAT_MBYTE | |
2580 int done = FALSE; | |
2581 | |
2582 /* CUT_BUFFER0 is supposed to be always latin1. Convert to 'enc' when | |
2583 * using a multi-byte encoding. Conversion between two 8-bit | |
2584 * character sets usually fails and the text might actually be in | |
2585 * 'enc' anyway. */ | |
2586 if (has_mbyte) | |
2587 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
1961
diff
changeset
|
2588 char_u *conv_buf; |
1924 | 2589 vimconv_T vc; |
2590 | |
2591 vc.vc_type = CONV_NONE; | |
2592 if (convert_setup(&vc, (char_u *)"latin1", p_enc) == OK) | |
2593 { | |
2594 conv_buf = string_convert(&vc, buffer, &nbytes); | |
2595 if (conv_buf != NULL) | |
2596 { | |
2597 clip_yank_selection(MCHAR, conv_buf, (long)nbytes, cbd); | |
2598 vim_free(conv_buf); | |
2599 done = TRUE; | |
2600 } | |
2601 convert_setup(&vc, NULL, NULL); | |
2602 } | |
2603 } | |
2604 if (!done) /* use the text without conversion */ | |
2605 #endif | |
2606 clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd); | |
2607 XFree((void *)buffer); | |
2608 if (p_verbose > 0) | |
2609 { | |
2610 verbose_enter(); | |
2611 verb_msg((char_u *)_("Used CUT_BUFFER0 instead of empty selection")); | |
2612 verbose_leave(); | |
2613 } | |
2614 } | |
2615 } | |
2616 #endif | |
2617 | |
7 | 2618 #if defined(FEAT_MOUSE) || defined(PROTO) |
2619 | |
2620 /* | |
2621 * Move the cursor to the specified row and column on the screen. | |
1226 | 2622 * Change current window if necessary. Returns an integer with the |
7 | 2623 * CURSOR_MOVED bit set if the cursor has moved or unset otherwise. |
2624 * | |
2625 * The MOUSE_FOLD_CLOSE bit is set when clicked on the '-' in a fold column. | |
2626 * The MOUSE_FOLD_OPEN bit is set when clicked on the '+' in a fold column. | |
2627 * | |
2628 * If flags has MOUSE_FOCUS, then the current window will not be changed, and | |
2629 * if the mouse is outside the window then the text will scroll, or if the | |
2630 * mouse was previously on a status line, then the status line may be dragged. | |
2631 * | |
2632 * If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the | |
2633 * cursor is moved unless the cursor was on a status line. | |
2634 * This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or | |
2635 * IN_SEP_LINE depending on where the cursor was clicked. | |
2636 * | |
2637 * If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless | |
2638 * the mouse is on the status line of the same window. | |
2639 * | |
2640 * If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since | |
2641 * the last call. | |
2642 * | |
2643 * If flags has MOUSE_SETPOS, nothing is done, only the current position is | |
2644 * remembered. | |
2645 */ | |
2646 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2647 jump_to_mouse( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2648 int flags, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2649 int *inclusive, /* used for inclusive operator, can be NULL */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2650 int which_button) /* MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE */ |
7 | 2651 { |
2652 static int on_status_line = 0; /* #lines below bottom of window */ | |
2653 static int on_sep_line = 0; /* on separator right of window */ | |
12519
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2654 #ifdef FEAT_MENU |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2655 static int in_winbar = FALSE; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2656 #endif |
7 | 2657 static int prev_row = -1; |
2658 static int prev_col = -1; | |
2659 static win_T *dragwin = NULL; /* window being dragged */ | |
2660 static int did_drag = FALSE; /* drag was noticed */ | |
2661 | |
2662 win_T *wp, *old_curwin; | |
2663 pos_T old_cursor; | |
2664 int count; | |
2665 int first; | |
2666 int row = mouse_row; | |
2667 int col = mouse_col; | |
2668 #ifdef FEAT_FOLDING | |
2669 int mouse_char; | |
2670 #endif | |
2671 | |
2672 mouse_past_bottom = FALSE; | |
2673 mouse_past_eol = FALSE; | |
2674 | |
2675 if (flags & MOUSE_RELEASED) | |
2676 { | |
2677 /* On button release we may change window focus if positioned on a | |
2678 * status line and no dragging happened. */ | |
2679 if (dragwin != NULL && !did_drag) | |
2680 flags &= ~(MOUSE_FOCUS | MOUSE_DID_MOVE); | |
2681 dragwin = NULL; | |
2682 did_drag = FALSE; | |
2683 } | |
2684 | |
2685 if ((flags & MOUSE_DID_MOVE) | |
2686 && prev_row == mouse_row | |
2687 && prev_col == mouse_col) | |
2688 { | |
2689 retnomove: | |
1226 | 2690 /* before moving the cursor for a left click which is NOT in a status |
7 | 2691 * line, stop Visual mode */ |
2692 if (on_status_line) | |
2693 return IN_STATUS_LINE; | |
2694 if (on_sep_line) | |
2695 return IN_SEP_LINE; | |
12831
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2696 #ifdef FEAT_MENU |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2697 if (in_winbar) |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2698 { |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2699 /* A quick second click may arrive as a double-click, but we use it |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2700 * as a second click in the WinBar. */ |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2701 if ((mod_mask & MOD_MASK_MULTI_CLICK) && !(flags & MOUSE_RELEASED)) |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2702 { |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2703 wp = mouse_find_win(&row, &col); |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2704 if (wp == NULL) |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2705 return IN_UNKNOWN; |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2706 winbar_click(wp, col); |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2707 } |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2708 return IN_OTHER_WIN | MOUSE_WINBAR; |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2709 } |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2710 #endif |
7 | 2711 if (flags & MOUSE_MAY_STOP_VIS) |
2712 { | |
2713 end_visual_mode(); | |
2714 redraw_curbuf_later(INVERTED); /* delete the inversion */ | |
2715 } | |
2716 #if defined(FEAT_CMDWIN) && defined(FEAT_CLIPBOARD) | |
2717 /* Continue a modeless selection in another window. */ | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2718 if (cmdwin_type != 0 && row < curwin->w_winrow) |
7 | 2719 return IN_OTHER_WIN; |
2720 #endif | |
2721 return IN_BUFFER; | |
2722 } | |
2723 | |
2724 prev_row = mouse_row; | |
2725 prev_col = mouse_col; | |
2726 | |
2727 if (flags & MOUSE_SETPOS) | |
2728 goto retnomove; /* ugly goto... */ | |
2729 | |
2730 #ifdef FEAT_FOLDING | |
2731 /* Remember the character under the mouse, it might be a '-' or '+' in the | |
2732 * fold column. */ | |
534 | 2733 if (row >= 0 && row < Rows && col >= 0 && col <= Columns |
2734 && ScreenLines != NULL) | |
7 | 2735 mouse_char = ScreenLines[LineOffset[row] + col]; |
2736 else | |
2737 mouse_char = ' '; | |
2738 #endif | |
2739 | |
2740 old_curwin = curwin; | |
2741 old_cursor = curwin->w_cursor; | |
2742 | |
2743 if (!(flags & MOUSE_FOCUS)) | |
2744 { | |
2745 if (row < 0 || col < 0) /* check if it makes sense */ | |
2746 return IN_UNKNOWN; | |
2747 | |
2748 /* find the window where the row is in */ | |
2749 wp = mouse_find_win(&row, &col); | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
2750 if (wp == NULL) |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
2751 return IN_UNKNOWN; |
7 | 2752 dragwin = NULL; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2753 |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2754 #ifdef FEAT_MENU |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2755 if (row == -1) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2756 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2757 /* A click in the window toolbar does not enter another window or |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2758 * change Visual highlighting. */ |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2759 winbar_click(wp, col); |
12519
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2760 in_winbar = TRUE; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2761 return IN_OTHER_WIN | MOUSE_WINBAR; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2762 } |
12519
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2763 in_winbar = FALSE; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2764 #endif |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2765 |
7 | 2766 /* |
2767 * winpos and height may change in win_enter()! | |
2768 */ | |
2769 if (row >= wp->w_height) /* In (or below) status line */ | |
2770 { | |
2771 on_status_line = row - wp->w_height + 1; | |
2772 dragwin = wp; | |
2773 } | |
2774 else | |
2775 on_status_line = 0; | |
2776 if (col >= wp->w_width) /* In separator line */ | |
2777 { | |
2778 on_sep_line = col - wp->w_width + 1; | |
2779 dragwin = wp; | |
2780 } | |
2781 else | |
2782 on_sep_line = 0; | |
2783 | |
2784 /* The rightmost character of the status line might be a vertical | |
2785 * separator character if there is no connecting window to the right. */ | |
2786 if (on_status_line && on_sep_line) | |
2787 { | |
2788 if (stl_connected(wp)) | |
2789 on_sep_line = 0; | |
2790 else | |
2791 on_status_line = 0; | |
2792 } | |
2793 | |
2794 /* Before jumping to another buffer, or moving the cursor for a left | |
2795 * click, stop Visual mode. */ | |
2796 if (VIsual_active | |
2797 && (wp->w_buffer != curwin->w_buffer | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12337
diff
changeset
|
2798 || (!on_status_line && !on_sep_line |
5735 | 2799 #ifdef FEAT_FOLDING |
7 | 2800 && ( |
5735 | 2801 # ifdef FEAT_RIGHTLEFT |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2802 wp->w_p_rl ? col < wp->w_width - wp->w_p_fdc : |
5735 | 2803 # endif |
7 | 2804 col >= wp->w_p_fdc |
5735 | 2805 # ifdef FEAT_CMDWIN |
7 | 2806 + (cmdwin_type == 0 && wp == curwin ? 0 : 1) |
5735 | 2807 # endif |
7 | 2808 ) |
5735 | 2809 #endif |
7 | 2810 && (flags & MOUSE_MAY_STOP_VIS)))) |
2811 { | |
2812 end_visual_mode(); | |
2813 redraw_curbuf_later(INVERTED); /* delete the inversion */ | |
2814 } | |
2815 #ifdef FEAT_CMDWIN | |
2816 if (cmdwin_type != 0 && wp != curwin) | |
2817 { | |
2818 /* A click outside the command-line window: Use modeless | |
2102
907cf09fbb32
updated for version 7.2.385
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
2819 * selection if possible. Allow dragging the status lines. */ |
7 | 2820 on_sep_line = 0; |
2821 # ifdef FEAT_CLIPBOARD | |
2822 if (on_status_line) | |
2823 return IN_STATUS_LINE; | |
2824 return IN_OTHER_WIN; | |
2825 # else | |
2826 row = 0; | |
2827 col += wp->w_wincol; | |
2828 wp = curwin; | |
2829 # endif | |
2830 } | |
2831 #endif | |
2832 /* Only change window focus when not clicking on or dragging the | |
2833 * status line. Do change focus when releasing the mouse button | |
2834 * (MOUSE_FOCUS was set above if we dragged first). */ | |
2835 if (dragwin == NULL || (flags & MOUSE_RELEASED)) | |
2836 win_enter(wp, TRUE); /* can make wp invalid! */ | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2837 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2838 if (curwin != old_curwin) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2839 { |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12337
diff
changeset
|
2840 #ifdef CHECK_DOUBLE_CLICK |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2841 /* set topline, to be able to check for double click ourselves */ |
7 | 2842 set_mouse_topline(curwin); |
2843 #endif | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2844 #ifdef FEAT_TERMINAL |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2845 /* when entering a terminal window may change state */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2846 term_win_entered(); |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2847 #endif |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2848 } |
7 | 2849 if (on_status_line) /* In (or below) status line */ |
2850 { | |
2851 /* Don't use start_arrow() if we're in the same window */ | |
2852 if (curwin == old_curwin) | |
2853 return IN_STATUS_LINE; | |
2854 else | |
2855 return IN_STATUS_LINE | CURSOR_MOVED; | |
2856 } | |
2857 if (on_sep_line) /* In (or below) status line */ | |
2858 { | |
2859 /* Don't use start_arrow() if we're in the same window */ | |
2860 if (curwin == old_curwin) | |
2861 return IN_SEP_LINE; | |
2862 else | |
2863 return IN_SEP_LINE | CURSOR_MOVED; | |
2864 } | |
2865 | |
2866 curwin->w_cursor.lnum = curwin->w_topline; | |
2867 #ifdef FEAT_GUI | |
2868 /* remember topline, needed for double click */ | |
2869 gui_prev_topline = curwin->w_topline; | |
2870 # ifdef FEAT_DIFF | |
2871 gui_prev_topfill = curwin->w_topfill; | |
2872 # endif | |
2873 #endif | |
2874 } | |
2875 else if (on_status_line && which_button == MOUSE_LEFT) | |
2876 { | |
2877 if (dragwin != NULL) | |
2878 { | |
2879 /* Drag the status line */ | |
2880 count = row - dragwin->w_winrow - dragwin->w_height + 1 | |
2881 - on_status_line; | |
2882 win_drag_status_line(dragwin, count); | |
2883 did_drag |= count; | |
2884 } | |
2885 return IN_STATUS_LINE; /* Cursor didn't move */ | |
2886 } | |
2887 else if (on_sep_line && which_button == MOUSE_LEFT) | |
2888 { | |
2889 if (dragwin != NULL) | |
2890 { | |
2891 /* Drag the separator column */ | |
2892 count = col - dragwin->w_wincol - dragwin->w_width + 1 | |
2893 - on_sep_line; | |
2894 win_drag_vsep_line(dragwin, count); | |
2895 did_drag |= count; | |
2896 } | |
2897 return IN_SEP_LINE; /* Cursor didn't move */ | |
2898 } | |
12519
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2899 #ifdef FEAT_MENU |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2900 else if (in_winbar) |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2901 { |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2902 /* After a click on the window toolbar don't start Visual mode. */ |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2903 return IN_OTHER_WIN | MOUSE_WINBAR; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2904 } |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2905 #endif |
7 | 2906 else /* keep_window_focus must be TRUE */ |
2907 { | |
2908 /* before moving the cursor for a left click, stop Visual mode */ | |
2909 if (flags & MOUSE_MAY_STOP_VIS) | |
2910 { | |
2911 end_visual_mode(); | |
2912 redraw_curbuf_later(INVERTED); /* delete the inversion */ | |
2913 } | |
2914 | |
2915 #if defined(FEAT_CMDWIN) && defined(FEAT_CLIPBOARD) | |
2916 /* Continue a modeless selection in another window. */ | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2917 if (cmdwin_type != 0 && row < curwin->w_winrow) |
7 | 2918 return IN_OTHER_WIN; |
2919 #endif | |
2920 | |
2921 row -= W_WINROW(curwin); | |
12513
3ca08bf99396
patch 8.0.1135: W_WINCOL() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2922 col -= curwin->w_wincol; |
7 | 2923 |
2924 /* | |
2925 * When clicking beyond the end of the window, scroll the screen. | |
2926 * Scroll by however many rows outside the window we are. | |
2927 */ | |
2928 if (row < 0) | |
2929 { | |
2930 count = 0; | |
2931 for (first = TRUE; curwin->w_topline > 1; ) | |
2932 { | |
2933 #ifdef FEAT_DIFF | |
2934 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)) | |
2935 ++count; | |
2936 else | |
2937 #endif | |
2938 count += plines(curwin->w_topline - 1); | |
2939 if (!first && count > -row) | |
2940 break; | |
2941 first = FALSE; | |
2942 #ifdef FEAT_FOLDING | |
7009 | 2943 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
7 | 2944 #endif |
2945 #ifdef FEAT_DIFF | |
2946 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)) | |
2947 ++curwin->w_topfill; | |
2948 else | |
2949 #endif | |
2950 { | |
2951 --curwin->w_topline; | |
2952 #ifdef FEAT_DIFF | |
2953 curwin->w_topfill = 0; | |
2954 #endif | |
2955 } | |
2956 } | |
2957 #ifdef FEAT_DIFF | |
2958 check_topfill(curwin, FALSE); | |
2959 #endif | |
2960 curwin->w_valid &= | |
2961 ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
2962 redraw_later(VALID); | |
2963 row = 0; | |
2964 } | |
2965 else if (row >= curwin->w_height) | |
2966 { | |
2967 count = 0; | |
2968 for (first = TRUE; curwin->w_topline < curbuf->b_ml.ml_line_count; ) | |
2969 { | |
2970 #ifdef FEAT_DIFF | |
2971 if (curwin->w_topfill > 0) | |
2972 ++count; | |
2973 else | |
2974 #endif | |
2975 count += plines(curwin->w_topline); | |
2976 if (!first && count > row - curwin->w_height + 1) | |
2977 break; | |
2978 first = FALSE; | |
2979 #ifdef FEAT_FOLDING | |
2980 if (hasFolding(curwin->w_topline, NULL, &curwin->w_topline) | |
2981 && curwin->w_topline == curbuf->b_ml.ml_line_count) | |
2982 break; | |
2983 #endif | |
2984 #ifdef FEAT_DIFF | |
2985 if (curwin->w_topfill > 0) | |
2986 --curwin->w_topfill; | |
2987 else | |
2988 #endif | |
2989 { | |
2990 ++curwin->w_topline; | |
2991 #ifdef FEAT_DIFF | |
2992 curwin->w_topfill = | |
2993 diff_check_fill(curwin, curwin->w_topline); | |
2994 #endif | |
2995 } | |
2996 } | |
2997 #ifdef FEAT_DIFF | |
2998 check_topfill(curwin, FALSE); | |
2999 #endif | |
3000 redraw_later(VALID); | |
3001 curwin->w_valid &= | |
3002 ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
3003 row = curwin->w_height - 1; | |
3004 } | |
3005 else if (row == 0) | |
3006 { | |
3007 /* When dragging the mouse, while the text has been scrolled up as | |
3008 * far as it goes, moving the mouse in the top line should scroll | |
3009 * the text down (done later when recomputing w_topline). */ | |
1164 | 3010 if (mouse_dragging > 0 |
7 | 3011 && curwin->w_cursor.lnum |
3012 == curwin->w_buffer->b_ml.ml_line_count | |
3013 && curwin->w_cursor.lnum == curwin->w_topline) | |
3014 curwin->w_valid &= ~(VALID_TOPLINE); | |
3015 } | |
3016 } | |
3017 | |
3018 #ifdef FEAT_FOLDING | |
3019 /* Check for position outside of the fold column. */ | |
3020 if ( | |
3021 # ifdef FEAT_RIGHTLEFT | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
3022 curwin->w_p_rl ? col < curwin->w_width - curwin->w_p_fdc : |
7 | 3023 # endif |
3024 col >= curwin->w_p_fdc | |
3025 # ifdef FEAT_CMDWIN | |
3026 + (cmdwin_type == 0 ? 0 : 1) | |
3027 # endif | |
3028 ) | |
3029 mouse_char = ' '; | |
3030 #endif | |
3031 | |
3032 /* compute the position in the buffer line from the posn on the screen */ | |
3033 if (mouse_comp_pos(curwin, &row, &col, &curwin->w_cursor.lnum)) | |
3034 mouse_past_bottom = TRUE; | |
3035 | |
3036 /* Start Visual mode before coladvance(), for when 'sel' != "old" */ | |
3037 if ((flags & MOUSE_MAY_VIS) && !VIsual_active) | |
3038 { | |
3039 check_visual_highlight(); | |
3040 VIsual = old_cursor; | |
3041 VIsual_active = TRUE; | |
3042 VIsual_reselect = TRUE; | |
3043 /* if 'selectmode' contains "mouse", start Select mode */ | |
3044 may_start_select('o'); | |
3045 setmouse(); | |
642 | 3046 if (p_smd && msg_silent == 0) |
7 | 3047 redraw_cmdline = TRUE; /* show visual mode later */ |
3048 } | |
3049 | |
3050 curwin->w_curswant = col; | |
3051 curwin->w_set_curswant = FALSE; /* May still have been TRUE */ | |
3052 if (coladvance(col) == FAIL) /* Mouse click beyond end of line */ | |
3053 { | |
3054 if (inclusive != NULL) | |
3055 *inclusive = TRUE; | |
3056 mouse_past_eol = TRUE; | |
3057 } | |
3058 else if (inclusive != NULL) | |
3059 *inclusive = FALSE; | |
3060 | |
3061 count = IN_BUFFER; | |
3062 if (curwin != old_curwin || curwin->w_cursor.lnum != old_cursor.lnum | |
3063 || curwin->w_cursor.col != old_cursor.col) | |
3064 count |= CURSOR_MOVED; /* Cursor has moved */ | |
3065 | |
3066 #ifdef FEAT_FOLDING | |
3067 if (mouse_char == '+') | |
3068 count |= MOUSE_FOLD_OPEN; | |
3069 else if (mouse_char != ' ') | |
3070 count |= MOUSE_FOLD_CLOSE; | |
3071 #endif | |
3072 | |
3073 return count; | |
3074 } | |
3075 | |
3076 /* | |
3077 * Compute the position in the buffer line from the posn on the screen in | |
3078 * window "win". | |
3079 * Returns TRUE if the position is below the last line. | |
3080 */ | |
3081 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3082 mouse_comp_pos( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3083 win_T *win, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3084 int *rowp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3085 int *colp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3086 linenr_T *lnump) |
7 | 3087 { |
3088 int col = *colp; | |
3089 int row = *rowp; | |
3090 linenr_T lnum; | |
3091 int retval = FALSE; | |
3092 int off; | |
3093 int count; | |
3094 | |
3095 #ifdef FEAT_RIGHTLEFT | |
3096 if (win->w_p_rl) | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
3097 col = win->w_width - 1 - col; |
7 | 3098 #endif |
3099 | |
3100 lnum = win->w_topline; | |
3101 | |
3102 while (row > 0) | |
3103 { | |
3104 #ifdef FEAT_DIFF | |
3105 /* Don't include filler lines in "count" */ | |
237 | 3106 if (win->w_p_diff |
3107 # ifdef FEAT_FOLDING | |
3108 && !hasFoldingWin(win, lnum, NULL, NULL, TRUE, NULL) | |
3109 # endif | |
3110 ) | |
7 | 3111 { |
3112 if (lnum == win->w_topline) | |
3113 row -= win->w_topfill; | |
3114 else | |
3115 row -= diff_check_fill(win, lnum); | |
3116 count = plines_win_nofill(win, lnum, TRUE); | |
3117 } | |
3118 else | |
3119 #endif | |
3120 count = plines_win(win, lnum, TRUE); | |
3121 if (count > row) | |
3122 break; /* Position is in this buffer line. */ | |
3123 #ifdef FEAT_FOLDING | |
3124 (void)hasFoldingWin(win, lnum, NULL, &lnum, TRUE, NULL); | |
3125 #endif | |
3126 if (lnum == win->w_buffer->b_ml.ml_line_count) | |
3127 { | |
3128 retval = TRUE; | |
3129 break; /* past end of file */ | |
3130 } | |
3131 row -= count; | |
3132 ++lnum; | |
3133 } | |
3134 | |
3135 if (!retval) | |
3136 { | |
3137 /* Compute the column without wrapping. */ | |
3138 off = win_col_off(win) - win_col_off2(win); | |
3139 if (col < off) | |
3140 col = off; | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
3141 col += row * (win->w_width - off); |
7 | 3142 /* add skip column (for long wrapping line) */ |
3143 col += win->w_skipcol; | |
3144 } | |
3145 | |
3146 if (!win->w_p_wrap) | |
3147 col += win->w_leftcol; | |
3148 | |
3149 /* skip line number and fold column in front of the line */ | |
3150 col -= win_col_off(win); | |
3151 if (col < 0) | |
3152 { | |
3153 #ifdef FEAT_NETBEANS_INTG | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3154 netbeans_gutter_click(lnum); |
7 | 3155 #endif |
3156 col = 0; | |
3157 } | |
3158 | |
3159 *colp = col; | |
3160 *rowp = row; | |
3161 *lnump = lnum; | |
3162 return retval; | |
3163 } | |
3164 | |
3165 /* | |
3166 * Find the window at screen position "*rowp" and "*colp". The positions are | |
3167 * updated to become relative to the top-left of the window. | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3168 * Returns NULL when something is wrong. |
7 | 3169 */ |
3170 win_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3171 mouse_find_win(int *rowp, int *colp UNUSED) |
7 | 3172 { |
3173 frame_T *fp; | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3174 win_T *wp; |
7 | 3175 |
3176 fp = topframe; | |
667 | 3177 *rowp -= firstwin->w_winrow; |
7 | 3178 for (;;) |
3179 { | |
3180 if (fp->fr_layout == FR_LEAF) | |
3181 break; | |
3182 if (fp->fr_layout == FR_ROW) | |
3183 { | |
3184 for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) | |
3185 { | |
3186 if (*colp < fp->fr_width) | |
3187 break; | |
3188 *colp -= fp->fr_width; | |
3189 } | |
3190 } | |
3191 else /* fr_layout == FR_COL */ | |
3192 { | |
3193 for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) | |
3194 { | |
3195 if (*rowp < fp->fr_height) | |
3196 break; | |
3197 *rowp -= fp->fr_height; | |
3198 } | |
3199 } | |
3200 } | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3201 /* When using a timer that closes a window the window might not actually |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3202 * exist. */ |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3203 FOR_ALL_WINDOWS(wp) |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3204 if (wp == fp->fr_win) |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3205 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3206 #ifdef FEAT_MENU |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3207 *rowp -= wp->w_winbar_height; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3208 #endif |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3209 return wp; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3210 } |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3211 return NULL; |
7 | 3212 } |
3213 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
3214 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MAC) \ |
7 | 3215 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \ |
13371
1a3f5759b61e
patch 8.0.1559: build failure without GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3216 || defined(FEAT_GUI_PHOTON) || defined(FEAT_TERM_POPUP_MENU) \ |
1a3f5759b61e
patch 8.0.1559: build failure without GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3217 || defined(PROTO) |
7 | 3218 /* |
3219 * Translate window coordinates to buffer position without any side effects | |
3220 */ | |
3221 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3222 get_fpos_of_mouse(pos_T *mpos) |
7 | 3223 { |
3224 win_T *wp; | |
3225 int row = mouse_row; | |
3226 int col = mouse_col; | |
3227 | |
3228 if (row < 0 || col < 0) /* check if it makes sense */ | |
3229 return IN_UNKNOWN; | |
3230 | |
3231 /* find the window where the row is in */ | |
3232 wp = mouse_find_win(&row, &col); | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3233 if (wp == NULL) |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3234 return IN_UNKNOWN; |
7 | 3235 /* |
3236 * winpos and height may change in win_enter()! | |
3237 */ | |
3238 if (row >= wp->w_height) /* In (or below) status line */ | |
3239 return IN_STATUS_LINE; | |
3240 if (col >= wp->w_width) /* In vertical separator line */ | |
3241 return IN_SEP_LINE; | |
3242 | |
3243 if (wp != curwin) | |
3244 return IN_UNKNOWN; | |
3245 | |
3246 /* compute the position in the buffer line from the posn on the screen */ | |
3247 if (mouse_comp_pos(curwin, &row, &col, &mpos->lnum)) | |
3248 return IN_STATUS_LINE; /* past bottom */ | |
3249 | |
3250 mpos->col = vcol2col(wp, mpos->lnum, col); | |
3251 | |
3252 if (mpos->col > 0) | |
3253 --mpos->col; | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
3254 #ifdef FEAT_VIRTUALEDIT |
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
3255 mpos->coladd = 0; |
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
3256 #endif |
7 | 3257 return IN_BUFFER; |
3258 } | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12831
diff
changeset
|
3259 #endif |
7 | 3260 |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12831
diff
changeset
|
3261 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MAC) \ |
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12831
diff
changeset
|
3262 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \ |
13373
0802633a0b2d
patch 8.0.1560: build failure without GUI on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13371
diff
changeset
|
3263 || defined(FEAT_GUI_PHOTON) || defined(FEAT_BEVAL) \ |
0802633a0b2d
patch 8.0.1560: build failure without GUI on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13371
diff
changeset
|
3264 || defined(FEAT_TERM_POPUP_MENU) || defined(PROTO) |
7 | 3265 /* |
3266 * Convert a virtual (screen) column to a character column. | |
3267 * The first column is one. | |
3268 */ | |
3269 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3270 vcol2col(win_T *wp, linenr_T lnum, int vcol) |
7 | 3271 { |
3272 /* try to advance to the specified column */ | |
3273 int count = 0; | |
3274 char_u *ptr; | |
5995 | 3275 char_u *line; |
7 | 3276 |
5995 | 3277 line = ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); |
3877 | 3278 while (count < vcol && *ptr != NUL) |
7 | 3279 { |
5995 | 3280 count += win_lbr_chartabsize(wp, line, ptr, count, NULL); |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3281 MB_PTR_ADV(ptr); |
7 | 3282 } |
5995 | 3283 return (int)(ptr - line); |
7 | 3284 } |
3285 #endif | |
3286 | |
3287 #endif /* FEAT_MOUSE */ | |
3288 | |
3289 #if defined(FEAT_GUI) || defined(WIN3264) || defined(PROTO) | |
3290 /* | |
3291 * Called when focus changed. Used for the GUI or for systems where this can | |
3292 * be done in the console (Win32). | |
3293 */ | |
3294 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3295 ui_focus_change( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3296 int in_focus) /* TRUE if focus gained. */ |
7 | 3297 { |
3298 static time_t last_time = (time_t)0; | |
3299 int need_redraw = FALSE; | |
3300 | |
3301 /* When activated: Check if any file was modified outside of Vim. | |
3302 * Only do this when not done within the last two seconds (could get | |
3303 * several events in a row). */ | |
3304 if (in_focus && last_time + 2 < time(NULL)) | |
3305 { | |
3306 need_redraw = check_timestamps( | |
3307 # ifdef FEAT_GUI | |
3308 gui.in_use | |
3309 # else | |
3310 FALSE | |
3311 # endif | |
3312 ); | |
3313 last_time = time(NULL); | |
3314 } | |
3315 | |
3316 /* | |
3317 * Fire the focus gained/lost autocommand. | |
3318 */ | |
3319 need_redraw |= apply_autocmds(in_focus ? EVENT_FOCUSGAINED | |
3320 : EVENT_FOCUSLOST, NULL, NULL, FALSE, curbuf); | |
3321 | |
3322 if (need_redraw) | |
3323 { | |
3324 /* Something was executed, make sure the cursor is put back where it | |
3325 * belongs. */ | |
3326 need_wait_return = FALSE; | |
3327 | |
3328 if (State & CMDLINE) | |
3329 redrawcmdline(); | |
3330 else if (State == HITRETURN || State == SETWSIZE || State == ASKMORE | |
3331 || State == EXTERNCMD || State == CONFIRM || exmode_active) | |
3332 repeat_message(); | |
3333 else if ((State & NORMAL) || (State & INSERT)) | |
3334 { | |
3335 if (must_redraw != 0) | |
3336 update_screen(0); | |
3337 setcursor(); | |
3338 } | |
3339 cursor_on(); /* redrawing may have switched it off */ | |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
3340 out_flush_cursor(FALSE, TRUE); |
7 | 3341 # ifdef FEAT_GUI |
3342 if (gui.in_use) | |
3343 gui_update_scrollbars(FALSE); | |
3344 # endif | |
3345 } | |
3346 #ifdef FEAT_TITLE | |
3347 /* File may have been changed from 'readonly' to 'noreadonly' */ | |
3348 if (need_maketitle) | |
3349 maketitle(); | |
3350 #endif | |
3351 } | |
3352 #endif | |
3353 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13373
diff
changeset
|
3354 #if defined(HAVE_INPUT_METHOD) || defined(PROTO) |
7 | 3355 /* |
3356 * Save current Input Method status to specified place. | |
3357 */ | |
3358 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3359 im_save_status(long *psave) |
7 | 3360 { |
3361 /* Don't save when 'imdisable' is set or "xic" is NULL, IM is always | |
3362 * disabled then (but might start later). | |
3363 * Also don't save when inside a mapping, vgetc_im_active has not been set | |
3364 * then. | |
3365 * And don't save when the keys were stuffed (e.g., for a "." command). | |
3366 * And don't save when the GUI is running but our window doesn't have | |
3367 * input focus (e.g., when a find dialog is open). */ | |
3368 if (!p_imdisable && KeyTyped && !KeyStuffed | |
3369 # ifdef FEAT_XIM | |
3370 && xic != NULL | |
3371 # endif | |
3372 # ifdef FEAT_GUI | |
3373 && (!gui.in_use || gui.in_focus) | |
3374 # endif | |
3375 ) | |
3376 { | |
3377 /* Do save when IM is on, or IM is off and saved status is on. */ | |
3378 if (vgetc_im_active) | |
3379 *psave = B_IMODE_IM; | |
3380 else if (*psave == B_IMODE_IM) | |
3381 *psave = B_IMODE_NONE; | |
3382 } | |
3383 } | |
3384 #endif |