Repository navigation
Expand file tree
/
Copy pathmouse.c
More file actions
3637 lines (3360 loc) · 93 KB
/
Copy pathmouse.c
File metadata and controls
3637 lines (3360 loc) · 93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* vi:set ts=8 sts=4 sw=4 noet:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* mouse.c: mouse handling functions
*/
#include "vim.h"
/*
* Horiziontal and vertical steps used when scrolling.
* When negative scroll by a whole page.
*/
static long mouse_hor_step = 6;
static long mouse_vert_step = 3;
static win_T *dragwin = NULL; // window being dragged
static int stl_click_handler(win_T *wp, int mrow, int mcol, int which_button,
int mods);
static int stl_click_handler_regions(stl_click_region_T *regions,
int region_count, int winid,
char_u *area_name, int mrow, int mcol,
int which_button, int mods);
void
mouse_set_vert_scroll_step(long step)
{
mouse_vert_step = step;
}
void
mouse_set_hor_scroll_step(long step)
{
mouse_hor_step = step;
}
#ifdef CHECK_DOUBLE_CLICK
/*
* Return the duration from t1 to t2 in milliseconds.
*/
static long
time_diff_ms(struct timeval *t1, struct timeval *t2)
{
// This handles wrapping of tv_usec correctly without any special case.
// Example of 2 pairs (tv_sec, tv_usec) with a duration of 5 ms:
// t1 = (1, 998000) t2 = (2, 3000) gives:
// (2 - 1) * 1000 + (3000 - 998000) / 1000 -> 5 ms.
return (t2->tv_sec - t1->tv_sec) * 1000
+ (t2->tv_usec - t1->tv_usec) / 1000;
}
#endif
/*
* Get class of a character for selection: same class means same word.
* 0: blank
* 1: punctuation groups
* 2: normal word character
* >2: multi-byte word character.
*/
static int
get_mouse_class(char_u *p)
{
int c;
if (has_mbyte && MB_BYTE2LEN(p[0]) > 1)
return mb_get_class(p);
c = *p;
if (c == ' ' || c == '\t')
return 0;
if (vim_iswordc(c))
return 2;
// There are a few special cases where we want certain combinations of
// characters to be considered as a single word. These are things like
// "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each
// character is in its own class.
if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL)
return 1;
return c;
}
/*
* Move "pos" back to the start of the word it's in.
*/
static void
find_start_of_word(pos_T *pos)
{
char_u *line;
int cclass;
int col;
line = ml_get(pos->lnum);
cclass = get_mouse_class(line + pos->col);
while (pos->col > 0)
{
col = pos->col - 1;
col -= (*mb_head_off)(line, line + col);
if (get_mouse_class(line + col) != cclass)
break;
pos->col = col;
}
}
/*
* Move "pos" forward to the end of the word it's in.
* When 'selection' is "exclusive", the position is just after the word.
*/
static void
find_end_of_word(pos_T *pos)
{
char_u *line;
int cclass;
int col;
line = ml_get(pos->lnum);
if (*p_sel == 'e' && pos->col > 0)
{
--pos->col;
pos->col -= (*mb_head_off)(line, line + pos->col);
}
cclass = get_mouse_class(line + pos->col);
while (line[pos->col] != NUL)
{
col = pos->col + (*mb_ptr2len)(line + pos->col);
if (get_mouse_class(line + col) != cclass)
{
if (*p_sel == 'e')
pos->col = col;
break;
}
pos->col = col;
}
}
#if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \
|| defined(FEAT_GUI_MSWIN) \
|| defined(FEAT_GUI_PHOTON) \
|| defined(FEAT_TERM_POPUP_MENU)
# define USE_POPUP_SETPOS
# define NEED_VCOL2COL
/*
* Translate window coordinates to buffer position without any side effects.
* Returns IN_BUFFER and sets "mpos->col" to the column when in buffer text.
* The column is one for the first column.
*/
static int
get_fpos_of_mouse(pos_T *mpos)
{
win_T *wp;
int row = mouse_row;
int col = mouse_col;
if (row < 0 || col < 0) // check if it makes sense
return IN_UNKNOWN;
// find the window where the row is in
wp = mouse_find_win(&row, &col, FAIL_POPUP);
if (wp == NULL)
return IN_UNKNOWN;
// winpos and height may change in win_enter()!
if (row >= wp->w_height) // In (or below) status line
return IN_STATUS_LINE;
if (col >= wp->w_width) // In vertical separator line
return IN_SEP_LINE;
if (wp != curwin)
return IN_UNKNOWN;
// compute the position in the buffer line from the posn on the screen
if (mouse_comp_pos(curwin, &row, &col, &mpos->lnum, NULL))
return IN_STATUS_LINE; // past bottom
mpos->col = vcol2col(wp, mpos->lnum, col, &mpos->coladd);
return IN_BUFFER;
}
#endif
/*
* Do the appropriate action for the current mouse click in the current mode.
* Not used for Command-line mode.
*
* Normal and Visual Mode:
* event modi- position visual change action
* fier cursor window
* left press - yes end yes
* left press C yes end yes "^]" (2)
* left press S yes end (popup: extend) yes "*" (2)
* left drag - yes start if moved no
* left relse - yes start if moved no
* middle press - yes if not active no put register
* middle press - yes if active no yank and put
* right press - yes start or extend yes
* right press S yes no change yes "#" (2)
* right drag - yes extend no
* right relse - yes extend no
*
* Insert or Replace Mode:
* event modi- position visual change action
* fier cursor window
* left press - yes (cannot be active) yes
* left press C yes (cannot be active) yes "CTRL-O^]" (2)
* left press S yes (cannot be active) yes "CTRL-O*" (2)
* left drag - yes start or extend (1) no CTRL-O (1)
* left relse - yes start or extend (1) no CTRL-O (1)
* middle press - no (cannot be active) no put register
* right press - yes start or extend yes CTRL-O
* right press S yes (cannot be active) yes "CTRL-O#" (2)
*
* (1) only if mouse pointer moved since press
* (2) only if click is in same buffer
*
* Return TRUE if start_arrow() should be called for edit mode.
*/
int
do_mouse(
oparg_T *oap, // operator argument, can be NULL
int c, // K_LEFTMOUSE, etc
int dir, // Direction to 'put' if necessary
long count,
int fixindent) // PUT_FIXINDENT if fixing indent necessary
{
static int do_always = FALSE; // ignore 'mouse' setting next time
static int got_click = FALSE; // got a click some time back
int which_button; // MOUSE_LEFT, _MIDDLE or _RIGHT
int is_click = FALSE; // If FALSE it's a drag or release event
int is_drag = FALSE; // If TRUE it's a drag event
int jump_flags = 0; // flags for jump_to_mouse()
pos_T start_visual;
int moved; // Has cursor moved?
int in_status_line; // mouse in status line
static int in_tab_line = FALSE; // mouse clicked in tab line
static int in_tabpanel = FALSE; // mouse clicked in tabpanel
#ifdef FEAT_TABPANEL
static bool in_tabpanel_scrollbar = false; // dragging tabpanel scrollbar
#endif
int in_sep_line; // mouse in vertical separator line
int c1, c2;
#if defined(FEAT_FOLDING)
pos_T save_cursor;
#endif
win_T *old_curwin = curwin;
static pos_T orig_cursor;
colnr_T leftcol, rightcol;
pos_T end_visual;
int diff;
int old_active = VIsual_active;
int old_mode = VIsual_mode;
int regname;
#if defined(FEAT_FOLDING)
save_cursor = curwin->w_cursor;
#endif
// When GUI is active, always recognize mouse events, otherwise:
// - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'.
// - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'.
// - For command line and insert mode 'mouse' is checked before calling
// do_mouse().
if (do_always)
do_always = FALSE;
else
#ifdef FEAT_GUI
if (!gui.in_use)
#endif
{
if (VIsual_active)
{
if (!mouse_has(MOUSE_VISUAL))
return FALSE;
}
else if (State == MODE_NORMAL && !mouse_has(MOUSE_NORMAL))
return FALSE;
}
for (;;)
{
which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag);
if (is_drag)
{
// If the next character is the same mouse event then use that
// one. Speeds up dragging the status line.
// Note: Since characters added to the stuff buffer in the code
// below need to come before the next character, do not do this
// when the current character was stuffed.
if (!KeyStuffed && vpeekc() != NUL)
{
int nc;
int save_mouse_row = mouse_row;
int save_mouse_col = mouse_col;
// Need to get the character, peeking doesn't get the actual
// one.
nc = safe_vgetc();
if (c == nc)
continue;
vungetc(nc);
mouse_row = save_mouse_row;
mouse_col = save_mouse_col;
}
}
break;
}
if (c == K_MOUSEMOVE)
{
// Mouse moved without a button pressed.
#ifdef FEAT_BEVAL_TERM
ui_may_remove_balloon();
if (p_bevalterm)
{
profile_setlimit(p_bdlay, &bevalexpr_due);
bevalexpr_due_set = TRUE;
}
#endif
#ifdef FEAT_PROP_POPUP
popup_handle_mouse_moved();
#endif
return FALSE;
}
#ifdef FEAT_MOUSESHAPE
// May have stopped dragging the status or separator line. The pointer is
// most likely still on the status or separator line.
if (!is_drag && drag_status_line)
{
drag_status_line = FALSE;
update_mouseshape(SHAPE_IDX_STATUS);
}
if (!is_drag && drag_sep_line)
{
drag_sep_line = FALSE;
update_mouseshape(SHAPE_IDX_VSEP);
}
#endif
// Ignore drag and release events if we didn't get a click.
if (is_click)
{
got_click = TRUE;
in_tab_line = FALSE;
in_tabpanel = FALSE;
#ifdef FEAT_TABPANEL
in_tabpanel_scrollbar = false;
#endif
}
else
{
if (!got_click) // didn't get click, ignore
return FALSE;
if (!is_drag) // release, reset got_click
{
got_click = FALSE;
if (in_tab_line || in_tabpanel
#ifdef FEAT_TABPANEL
|| in_tabpanel_scrollbar
#endif
)
{
in_tab_line = FALSE;
in_tabpanel = FALSE;
#ifdef FEAT_TABPANEL
in_tabpanel_scrollbar = false;
#endif
return FALSE;
}
}
}
#ifdef FEAT_TABPANEL
// Continue a scrollbar drag before any tab-selection handling.
if (is_drag && in_tabpanel_scrollbar)
{
tabpanel_drag_scrollbar(mouse_row);
return FALSE;
}
#endif
// CTRL right mouse button does CTRL-T
if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT)
{
if (State & MODE_INSERT)
stuffcharReadbuff(Ctrl_O);
if (count > 1)
stuffnumReadbuff(count);
stuffcharReadbuff(Ctrl_T);
got_click = FALSE; // ignore drag&release now
return FALSE;
}
// CTRL only works with left mouse button
if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT)
return FALSE;
// When a modifier is down, ignore drag and release events, as well as
// multiple clicks and the middle mouse button.
// Accept shift-leftmouse drags when 'mousemodel' is "popup.*".
if ((mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT
| MOD_MASK_META))
&& (!is_click
|| (mod_mask & MOD_MASK_MULTI_CLICK)
|| which_button == MOUSE_MIDDLE)
&& !((mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT))
&& mouse_model_popup()
&& which_button == MOUSE_LEFT)
&& !((mod_mask & MOD_MASK_ALT)
&& !mouse_model_popup()
&& which_button == MOUSE_RIGHT)
)
return FALSE;
// If the button press was used as the movement command for an operator
// (eg "d<MOUSE>"), or it is the middle button that is held down, ignore
// drag/release events.
if (!is_click && which_button == MOUSE_MIDDLE)
return FALSE;
if (oap != NULL)
regname = oap->regname;
else
regname = 0;
// Middle mouse button does a 'put' of the selected text
if (which_button == MOUSE_MIDDLE)
{
if (State == MODE_NORMAL)
{
// If an operator was pending, we don't know what the user wanted
// to do. Go back to normal mode: Clear the operator and beep().
if (oap != NULL && oap->op_type != OP_NOP)
{
clearopbeep(oap);
return FALSE;
}
// If visual was active, yank the highlighted text and put it
// before the mouse pointer position.
// In Select mode replace the highlighted text with the clipboard.
if (VIsual_active)
{
if (VIsual_select)
{
stuffcharReadbuff(Ctrl_G);
stuffReadbuff((char_u *)"\"+p");
}
else
{
stuffcharReadbuff('y');
stuffcharReadbuff(K_MIDDLEMOUSE);
}
do_always = TRUE; // ignore 'mouse' setting next time
return FALSE;
}
// The rest is below jump_to_mouse()
}
else if ((State & MODE_INSERT) == 0)
return FALSE;
// Middle click in insert mode doesn't move the mouse, just insert the
// contents of a register. '.' register is special, can't insert that
// with do_put().
// Also paste at the cursor if the current mode isn't in 'mouse' (only
// happens for the GUI).
if ((State & MODE_INSERT) || !mouse_has(MOUSE_NORMAL))
{
if (regname == '.')
insert_reg(regname, TRUE);
else
{
#ifdef FEAT_CLIPBOARD
if (clip_star.available && regname == 0)
regname = '*';
#endif
if ((State & REPLACE_FLAG) && !yank_register_mline(regname))
insert_reg(regname, TRUE);
else
{
do_put(regname, NULL, BACKWARD, 1L,
fixindent | PUT_CURSEND);
// Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r
AppendCharToRedobuff(Ctrl_R);
AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O);
AppendCharToRedobuff(regname == 0 ? '"' : regname);
}
}
return FALSE;
}
}
// When dragging or button-up stay in the same window.
if (!is_click)
jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE;
start_visual.lnum = 0;
struct tabpage_label_info {
bool is_panel; // label type. true: tabpanel, false: tab line
bool just_in; // just in tabpage label area
bool just_click; // just click tabpage label area
int nr; // tabpage number
} tp_label = { false, false, false, 0 };
// Check for clicking in the tab page panel.
#if defined(FEAT_TABPANEL)
if (mouse_col < firstwin->w_wincol
|| mouse_col >= firstwin->w_wincol + topframe->fr_width)
{
// A click on the scrollbar column starts a drag interaction and
// preempts tab-selection.
if (is_click && !is_drag && mouse_on_tabpanel_scrollbar())
{
in_tabpanel_scrollbar = TRUE;
tabpanel_drag_scrollbar(mouse_row);
return FALSE;
}
// Dispatch 'tabpanel' %[FuncName] click regions before falling through
// to tab-page selection. On drag events fall through to the normal
// tab-drag handling.
if (is_click && !is_drag
&& stl_click_handler_regions(tabpanel_stl_click,
tabpanel_stl_click_count,
0, (char_u *)"tabpanel",
mouse_row, mouse_col,
which_button, mod_mask))
return FALSE;
tp_label.is_panel = true;
tp_label.just_in = true;
tp_label.nr = get_tabpagenr_on_tabpanel();
// click in a tab selects that tab page
if (is_click && cmdwin_type == 0)
tp_label.just_click = true;
}
else
#endif
// Check for clicking in the tab page line.
if (TabPageIdxs != NULL && mouse_row == 0 && firstwin->w_winrow > 0)
{
// Dispatch 'tabline' %[FuncName] click regions before falling through
// to tab-page selection. On drag events fall through to the normal
// tab-drag handling.
if (is_click && !is_drag
&& stl_click_handler_regions(tabline_stl_click,
tabline_stl_click_count,
0, (char_u *)"tabline",
mouse_row, mouse_col,
which_button, mod_mask))
return FALSE;
tp_label.just_in = true;
tp_label.nr = TabPageIdxs[mouse_col];
// click in a tab selects that tab page
if (is_click && cmdwin_type == 0
&& mouse_col < firstwin->w_wincol + topframe->fr_width)
tp_label.just_click = true;
}
if (tp_label.just_in)
{
if (is_drag)
{
if (in_tabpanel || in_tab_line)
{
c1 = tp_label.nr;
tabpage_move(c1 <= 0 ? 9999 : c1 < tabpage_index(curtab)
? c1 - 1 : c1);
}
return FALSE;
}
if (tp_label.just_click)
{
if (tp_label.is_panel)
in_tabpanel = TRUE;
else
in_tab_line = TRUE;
c1 = tp_label.nr;
if (c1 >= 0)
{
if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK
&& !tp_label.is_panel)
{
// Double-click on the tabline opens a new, empty tab page.
// The tabpanel has no "empty area" (every row maps to a tab)
// and this behavior is not documented for tabpanel, so fall
// through to the regular tab-switch path there.
end_visual_mode_keep_button();
tabpage_new();
tabpage_move(c1 == 0 ? 9999 : c1 - 1);
}
else
{
// Go to specified tab page, or next one if not clicking
// on a label.
goto_tabpage(c1);
// It's like clicking on the status line of a window.
if (curwin != old_curwin)
end_visual_mode_keep_button();
}
}
else
{
tabpage_T *tp;
// Close the current or specified tab page.
if (c1 == -999)
tp = curtab;
else
tp = find_tabpage(-c1);
if (tp == curtab)
{
if (first_tabpage->tp_next != NULL)
tabpage_close(FALSE);
}
else if (tp != NULL)
tabpage_close_other(tp, FALSE);
}
}
return TRUE;
}
else if (is_drag && (in_tabpanel || (in_tab_line && TabPageIdxs != NULL)))
{
#if defined(FEAT_TABPANEL)
if (in_tabpanel)
c1 = get_tabpagenr_on_tabpanel();
else
#endif
c1 = TabPageIdxs[mouse_col];
tabpage_move(c1 <= 0 ? 9999 : c1 - 1);
return FALSE;
}
// When 'mousemodel' is "popup" or "popup_setpos", translate mouse events:
// right button up -> pop-up menu
// shift-left button -> right button
// alt-left button -> alt-right button
if (mouse_model_popup())
{
if (which_button == MOUSE_RIGHT
&& !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)))
{
#ifdef USE_POPUP_SETPOS
# ifdef FEAT_GUI
if (gui.in_use)
{
# if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \
|| defined(FEAT_GUI_PHOTON)
if (!is_click)
// Ignore right button release events, only shows the popup
// menu on the button down event.
return FALSE;
# endif
# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_HAIKU)
if (is_click || is_drag)
// Ignore right button down and drag mouse events. Windows
// only shows the popup menu on the button up event.
return FALSE;
# endif
}
# endif
# if defined(FEAT_GUI) && defined(FEAT_TERM_POPUP_MENU)
else
# endif
# if defined(FEAT_TERM_POPUP_MENU)
if (!is_click)
// Ignore right button release events, only shows the popup
// menu on the button down event.
return FALSE;
# endif
jump_flags = 0;
if (STRCMP(p_mousem, "popup_setpos") == 0)
{
// First set the cursor position before showing the popup
// menu.
if (VIsual_active)
{
pos_T m_pos;
// set MOUSE_MAY_STOP_VIS if we are outside the
// selection or the current window (might have false
// negative here)
if (mouse_row < curwin->w_winrow
|| mouse_row
> (curwin->w_winrow + curwin->w_height))
jump_flags = MOUSE_MAY_STOP_VIS;
else if (get_fpos_of_mouse(&m_pos) != IN_BUFFER)
jump_flags = MOUSE_MAY_STOP_VIS;
else
{
if (VIsual_mode == 'V')
{
if ((curwin->w_cursor.lnum <= VIsual.lnum
&& (m_pos.lnum < curwin->w_cursor.lnum
|| VIsual.lnum < m_pos.lnum))
|| (VIsual.lnum < curwin->w_cursor.lnum
&& (m_pos.lnum < VIsual.lnum
|| curwin->w_cursor.lnum < m_pos.lnum)))
{
jump_flags = MOUSE_MAY_STOP_VIS;
}
}
else if ((LTOREQ_POS(curwin->w_cursor, VIsual)
&& (LT_POS(m_pos, curwin->w_cursor)
|| LT_POS(VIsual, m_pos)))
|| (LT_POS(VIsual, curwin->w_cursor)
&& (LT_POS(m_pos, VIsual)
|| LT_POS(curwin->w_cursor, m_pos))))
{
jump_flags = MOUSE_MAY_STOP_VIS;
}
else if (VIsual_mode == Ctrl_V)
{
getvcols(curwin, &curwin->w_cursor, &VIsual,
&leftcol, &rightcol, 0);
getvcol(curwin, &m_pos, NULL, &m_pos.col, NULL, 0);
if (m_pos.col < leftcol || m_pos.col > rightcol)
jump_flags = MOUSE_MAY_STOP_VIS;
}
}
}
else
jump_flags = MOUSE_MAY_STOP_VIS;
}
if (jump_flags)
{
jump_flags = jump_to_mouse(jump_flags, NULL, which_button);
update_curbuf(VIsual_active ? UPD_INVERTED : UPD_VALID);
setcursor();
out_flush(); // Update before showing popup menu
}
# ifdef FEAT_MENU
show_popupmenu();
got_click = FALSE; // ignore release events
# endif
return (jump_flags & CURSOR_MOVED) != 0;
#else
return FALSE;
#endif
}
if (which_button == MOUSE_LEFT
&& (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT)))
{
which_button = MOUSE_RIGHT;
mod_mask &= ~MOD_MASK_SHIFT;
}
}
if ((State & (MODE_NORMAL | MODE_INSERT))
&& !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)))
{
if (which_button == MOUSE_LEFT)
{
if (is_click)
{
// stop Visual mode for a left click in a window, but not when
// on a status line
if (VIsual_active)
jump_flags |= MOUSE_MAY_STOP_VIS;
}
else if (mouse_has(MOUSE_VISUAL))
jump_flags |= MOUSE_MAY_VIS;
}
else if (which_button == MOUSE_RIGHT)
{
if (is_click && VIsual_active)
{
// Remember the start and end of visual before moving the
// cursor.
if (LT_POS(curwin->w_cursor, VIsual))
{
start_visual = curwin->w_cursor;
end_visual = VIsual;
}
else
{
start_visual = VIsual;
end_visual = curwin->w_cursor;
}
}
jump_flags |= MOUSE_FOCUS;
if (mouse_has(MOUSE_VISUAL))
jump_flags |= MOUSE_MAY_VIS;
}
}
// If an operator is pending, ignore all drags and releases until the
// next mouse click.
if (!is_drag && oap != NULL && oap->op_type != OP_NOP)
{
got_click = FALSE;
oap->motion_type = MCHAR;
}
// When releasing the button let jump_to_mouse() know.
if (!is_click && !is_drag)
jump_flags |= MOUSE_RELEASED;
// JUMP!
jump_flags = jump_to_mouse(jump_flags,
oap == NULL ? NULL : &(oap->inclusive), which_button);
#ifdef FEAT_MENU
// A click in the window toolbar has no side effects.
if (jump_flags & MOUSE_WINBAR)
return FALSE;
#endif
moved = (jump_flags & CURSOR_MOVED);
in_status_line = (jump_flags & IN_STATUS_LINE);
in_sep_line = (jump_flags & IN_SEP_LINE);
// Check for statusline click handler early, before visual mode or
// other button-specific handling can interfere.
if (in_status_line && is_click && !is_drag
&& stl_click_handler(dragwin, mouse_row, mouse_col,
which_button, mod_mask))
{
#ifdef FEAT_MOUSESHAPE
if (!drag_status_line)
{
drag_status_line = TRUE;
update_mouseshape(-1);
}
#endif
return FALSE;
}
#ifdef FEAT_NETBEANS_INTG
if (isNetbeansBuffer(curbuf)
&& !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE)))
{
int key = KEY2TERMCAP1(c);
if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE
|| key == (int)KE_RIGHTRELEASE)
netbeans_button_release(which_button);
}
#endif
// When jumping to another window, clear a pending operator. That's a bit
// friendlier than beeping and not jumping to that window.
if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP)
clearop(oap);
#ifdef FEAT_FOLDING
if (mod_mask == 0
&& !is_drag
&& (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN))
&& which_button == MOUSE_LEFT)
{
// open or close a fold at this line
if (jump_flags & MOUSE_FOLD_OPEN)
openFold(curwin->w_cursor.lnum, 1L);
else
closeFold(curwin->w_cursor.lnum, 1L);
// don't move the cursor if still in the same window
if (curwin == old_curwin)
curwin->w_cursor = save_cursor;
}
#endif
#if defined(FEAT_CLIPBOARD)
if ((jump_flags & IN_OTHER_WIN) && !VIsual_active &&
(clip_star.available || clip_plus.available))
{
clip_modeless(which_button, is_click, is_drag);
return FALSE;
}
#endif
// Set global flag that we are extending the Visual area with mouse
// dragging; temporarily minimize 'scrolloff'.
if (VIsual_active && is_drag && get_scrolloff_value())
{
// In the very first line, allow scrolling one line
if (mouse_row == 0)
mouse_dragging = 2;
else
mouse_dragging = 1;
}
// When dragging the mouse above the window, scroll down.
if (is_drag && mouse_row < 0 && !in_status_line)
{
scroll_redraw(FALSE, 1L);
mouse_row = 0;
}
if (start_visual.lnum) // right click in visual mode
{
// When ALT is pressed make Visual mode blockwise.
if (mod_mask & MOD_MASK_ALT)
VIsual_mode = Ctrl_V;
// In Visual-block mode, divide the area in four, pick up the corner
// that is in the quarter that the cursor is in.
if (VIsual_mode == Ctrl_V)
{
getvcols(curwin, &start_visual, &end_visual,
&leftcol, &rightcol, 0);
if (curwin->w_curswant > (leftcol + rightcol) / 2)
end_visual.col = leftcol;
else
end_visual.col = rightcol;
if (curwin->w_cursor.lnum >=
(start_visual.lnum + end_visual.lnum) / 2)
end_visual.lnum = start_visual.lnum;
// move VIsual to the right column
start_visual = curwin->w_cursor; // save the cursor pos
curwin->w_cursor = end_visual;
coladvance(end_visual.col);
VIsual = curwin->w_cursor;
curwin->w_cursor = start_visual; // restore the cursor
}
else
{
// If the click is before the start of visual, change the start.
// If the click is after the end of visual, change the end. If
// the click is inside the visual, change the closest side.
if (LT_POS(curwin->w_cursor, start_visual))
VIsual = end_visual;
else if (LT_POS(end_visual, curwin->w_cursor))
VIsual = start_visual;
else
{
// In the same line, compare column number
if (end_visual.lnum == start_visual.lnum)
{
if (curwin->w_cursor.col - start_visual.col >
end_visual.col - curwin->w_cursor.col)
VIsual = start_visual;
else
VIsual = end_visual;
}
// In different lines, compare line number
else
{
diff = (curwin->w_cursor.lnum - start_visual.lnum) -
(end_visual.lnum - curwin->w_cursor.lnum);
if (diff > 0) // closest to end
VIsual = start_visual;
else if (diff < 0) // closest to start
VIsual = end_visual;
else // in the middle line
{
if (curwin->w_cursor.col <
(start_visual.col + end_visual.col) / 2)
VIsual = end_visual;
else
VIsual = start_visual;
}
}
}
}
}
// If Visual mode started in insert mode, execute "CTRL-O"
else if ((State & MODE_INSERT) && VIsual_active)
stuffcharReadbuff(Ctrl_O);
// Middle mouse click: Put text before cursor.
if (which_button == MOUSE_MIDDLE)
{
#ifdef FEAT_CLIPBOARD
if (clip_star.available && regname == 0)
regname = '*';
#endif
if (yank_register_mline(regname))
{
if (mouse_past_bottom)
dir = FORWARD;
}
else if (mouse_past_eol)
dir = FORWARD;
if (fixindent)
{
c1 = (dir == BACKWARD) ? '[' : ']';
c2 = 'p';
}
else
{
c1 = (dir == FORWARD) ? 'p' : 'P';