Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcde9425

Browse files
committed
feat: click support for'statusline' and'winbar'
Adds mouse click support with the `%@` item for `'statusline'` and`'winbar'`.
1 parent976f32a commitcde9425

File tree

10 files changed

+533
-386
lines changed

10 files changed

+533
-386
lines changed

‎runtime/doc/options.txt‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6045,7 +6045,7 @@ A jump table for the options with a short description can be found at |Q_op|.
60456045
the label, e.g.: %3Xclose%X. Use %999X for a "close current
60466046
tab" label. Clicking this label with left mouse button closes
60476047
specified tab page.
6048-
@ NFor'tabline': start of execute function label. Use %X or %T to
6048+
@ NStart of execute function label. Use %X or %T to
60496049
end the label, e.g.: %10@SwitchBuffer@foo.c%X. Clicking this
60506050
label runs specified function: in the example when clicking once
60516051
using left mouse button on "foo.c" "SwitchBuffer(10, 1, 'l',
@@ -6069,8 +6069,6 @@ A jump table for the options with a short description can be found at |Q_op|.
60696069
is a bug that denotes that new mouse button recognition was
60706070
added without modifying code that reacts on mouse clicks on
60716071
this label.
6072-
Note: to test whether your version of Neovim contains this
6073-
feature use`has('tablineat')`.
60746072
< - Where to truncate line if too long. Default is at the start.
60756073
No width fields allowed.
60766074
= - Separation point between alignment sections. Each section will

‎src/nvim/buffer_defs.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// for FILE
77
#include<stdio.h>
88

9+
#include"grid_defs.h"
10+
911
typedefstructfile_bufferbuf_T;// Forward declaration
1012

1113
// Reference to a buffer that stores the value of buf_free_count.
@@ -1492,6 +1494,16 @@ struct window_S {
14921494
// Location list reference used in the location list window.
14931495
// In a non-location list window, w_llist_ref is NULL.
14941496
qf_info_T*w_llist_ref;
1497+
1498+
// Status line click definitions
1499+
StlClickDefinition*w_status_click_defs;
1500+
// Size of the w_status_click_defs array
1501+
size_tw_status_click_defs_size;
1502+
1503+
// Window bar click definitions
1504+
StlClickDefinition*w_winbar_click_defs;
1505+
// Size of the w_winbar_click_defs array
1506+
size_tw_winbar_click_defs_size;
14951507
};
14961508

14971509
staticinlineintwin_hl_attr(win_T*wp,inthlf)

‎src/nvim/grid_defs.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,22 @@ struct ScreenGrid {
111111
false, 0, 0, NULL, false, true, 0, \
112112
0, 0, 0, 0, 0, false }
113113

114+
/// Status line click definition
115+
typedefstruct {
116+
enum {
117+
kStlClickDisabled=0,///< Clicks to this area are ignored.
118+
kStlClickTabSwitch,///< Switch to the given tab.
119+
kStlClickTabClose,///< Close given tab.
120+
kStlClickFuncRun,///< Run user function.
121+
}type;///< Type of the click.
122+
inttabnr;///< Tab page number.
123+
char*func;///< Function to run.
124+
}StlClickDefinition;
125+
126+
/// Used for tabline clicks
127+
typedefstruct {
128+
StlClickDefinitiondef;///< Click definition.
129+
constchar*start;///< Location where region starts.
130+
}StlClickRecord;
131+
114132
#endif// NVIM_GRID_DEFS_H

‎src/nvim/mouse.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ int jump_to_mouse(int flags, bool *inclusive, int which_button)
241241
}
242242

243243
curwin->w_cursor.lnum=curwin->w_topline;
244-
}elseif (on_status_line&&which_button==MOUSE_LEFT) {
245-
if (dragwin!=NULL) {
244+
}elseif (on_status_line) {
245+
if (which_button==MOUSE_LEFT&&dragwin!=NULL) {
246246
// Drag the status line
247247
count=row-dragwin->w_winrow-dragwin->w_height+1
248248
-on_status_line;

‎src/nvim/normal.c‎

Lines changed: 90 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include"nvim/fold.h"
3333
#include"nvim/getchar.h"
3434
#include"nvim/globals.h"
35+
#include"nvim/grid_defs.h"
3536
#include"nvim/indent.h"
3637
#include"nvim/keycodes.h"
3738
#include"nvim/log.h"
@@ -1443,6 +1444,63 @@ static void move_tab_to_mouse(void)
14431444
}
14441445
}
14451446

1447+
/// Call click definition function for column "col" in the "click_defs" array for button
1448+
/// "which_button".
1449+
staticvoidcall_click_def_func(StlClickDefinition*click_defs,intcol,intwhich_button)
1450+
{
1451+
typval_Targv[]= {
1452+
{
1453+
.v_lock=VAR_FIXED,
1454+
.v_type=VAR_NUMBER,
1455+
.vval= {
1456+
.v_number= (varnumber_T)click_defs[col].tabnr
1457+
},
1458+
},
1459+
{
1460+
.v_lock=VAR_FIXED,
1461+
.v_type=VAR_NUMBER,
1462+
.vval= {
1463+
.v_number= ((mod_mask&MOD_MASK_MULTI_CLICK)==MOD_MASK_4CLICK
1464+
?4
1465+
: ((mod_mask&MOD_MASK_MULTI_CLICK)==MOD_MASK_3CLICK
1466+
?3
1467+
: ((mod_mask&MOD_MASK_MULTI_CLICK)==MOD_MASK_2CLICK
1468+
?2
1469+
:1)))
1470+
},
1471+
},
1472+
{
1473+
.v_lock=VAR_FIXED,
1474+
.v_type=VAR_STRING,
1475+
.vval= {
1476+
.v_string= (which_button==MOUSE_LEFT
1477+
?"l"
1478+
: (which_button==MOUSE_RIGHT
1479+
?"r"
1480+
: (which_button==MOUSE_MIDDLE
1481+
?"m"
1482+
:"?")))
1483+
},
1484+
},
1485+
{
1486+
.v_lock=VAR_FIXED,
1487+
.v_type=VAR_STRING,
1488+
.vval= {
1489+
.v_string= (char[]) {
1490+
(char)(mod_mask&MOD_MASK_SHIFT ?'s' :' '),
1491+
(char)(mod_mask&MOD_MASK_CTRL ?'c' :' '),
1492+
(char)(mod_mask&MOD_MASK_ALT ?'a' :' '),
1493+
(char)(mod_mask&MOD_MASK_META ?'m' :' '),
1494+
NUL
1495+
}
1496+
},
1497+
}
1498+
};
1499+
typval_Trettv;
1500+
(void)call_vim_function(click_defs[col].func,ARRAY_SIZE(argv),argv,&rettv);
1501+
tv_clear(&rettv);
1502+
}
1503+
14461504
/// Do the appropriate action for the current mouse click in the current mode.
14471505
/// Not used for Command-line mode.
14481506
///
@@ -1492,6 +1550,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
14921550
intjump_flags=0;// flags for jump_to_mouse()
14931551
pos_Tstart_visual;
14941552
boolmoved;// Has cursor moved?
1553+
boolin_winbar;// mouse in window bar
14951554
boolin_status_line;// mouse in status line
14961555
staticboolin_tab_line= false;// mouse clicked in tab line
14971556
boolin_sep_line;// mouse in vertical separator line
@@ -1722,66 +1781,10 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
17221781
}
17231782
}
17241783
break;
1725-
casekStlClickFuncRun: {
1726-
typval_Targv[]= {
1727-
{
1728-
.v_lock=VAR_FIXED,
1729-
.v_type=VAR_NUMBER,
1730-
.vval= {
1731-
.v_number= (varnumber_T)tab_page_click_defs[mouse_col].tabnr
1732-
},
1733-
},
1734-
{
1735-
.v_lock=VAR_FIXED,
1736-
.v_type=VAR_NUMBER,
1737-
.vval= {
1738-
.v_number= ((mod_mask&MOD_MASK_MULTI_CLICK)==MOD_MASK_4CLICK
1739-
?4
1740-
: ((mod_mask&MOD_MASK_MULTI_CLICK)==MOD_MASK_3CLICK
1741-
?3
1742-
: ((mod_mask&MOD_MASK_MULTI_CLICK)==MOD_MASK_2CLICK
1743-
?2
1744-
:1)))
1745-
},
1746-
},
1747-
{
1748-
.v_lock=VAR_FIXED,
1749-
.v_type=VAR_STRING,
1750-
.vval= {
1751-
.v_string= (which_button==MOUSE_LEFT
1752-
?"l"
1753-
: (which_button==MOUSE_RIGHT
1754-
?"r"
1755-
: (which_button==MOUSE_MIDDLE
1756-
?"m"
1757-
:"?")))
1758-
},
1759-
},
1760-
{
1761-
.v_lock=VAR_FIXED,
1762-
.v_type=VAR_STRING,
1763-
.vval= {
1764-
.v_string= (char[]) {
1765-
(char)(mod_mask&MOD_MASK_SHIFT ?'s' :' '),
1766-
(char)(mod_mask&MOD_MASK_CTRL ?'c' :' '),
1767-
(char)(mod_mask&MOD_MASK_ALT ?'a' :' '),
1768-
(char)(mod_mask&MOD_MASK_META ?'m' :' '),
1769-
NUL
1770-
}
1771-
},
1772-
}
1773-
};
1774-
typval_Trettv;
1775-
funcexe_Tfuncexe=FUNCEXE_INIT;
1776-
funcexe.firstline=curwin->w_cursor.lnum;
1777-
funcexe.lastline=curwin->w_cursor.lnum;
1778-
funcexe.evaluate= true;
1779-
(void)call_func(tab_page_click_defs[mouse_col].func,-1,
1780-
&rettv,ARRAY_SIZE(argv),argv,&funcexe);
1781-
tv_clear(&rettv);
1784+
casekStlClickFuncRun:
1785+
call_click_def_func(tab_page_click_defs,mouse_col,which_button);
17821786
break;
17831787
}
1784-
}
17851788
}
17861789
return true;
17871790
}elseif (is_drag&&in_tab_line) {
@@ -1851,15 +1854,39 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
18511854
oap==NULL ?NULL :&(oap->inclusive),
18521855
which_button);
18531856

1854-
// A click in the window bar has no side effects.
1855-
if (jump_flags&MOUSE_WINBAR) {
1856-
return false;
1857-
}
1858-
18591857
moved= (jump_flags&CURSOR_MOVED);
1858+
in_winbar= (jump_flags&MOUSE_WINBAR);
18601859
in_status_line= (jump_flags&IN_STATUS_LINE);
18611860
in_sep_line= (jump_flags&IN_SEP_LINE);
18621861

1862+
if ((in_winbar||in_status_line)&&is_click) {
1863+
// Handle click event on window bar or status lin
1864+
intclick_grid=mouse_grid;
1865+
intclick_row=mouse_row;
1866+
intclick_col=mouse_col;
1867+
win_T*wp=mouse_find_win(&click_grid,&click_row,&click_col);
1868+
1869+
StlClickDefinition*click_defs=in_status_line ?wp->w_status_click_defs
1870+
:wp->w_winbar_click_defs;
1871+
1872+
if (click_defs!=NULL) {
1873+
switch (click_defs[click_col].type) {
1874+
casekStlClickDisabled:
1875+
break;
1876+
casekStlClickFuncRun:
1877+
call_click_def_func(click_defs,click_col,which_button);
1878+
break;
1879+
default:
1880+
assert(false&&"winbar and statusline only support %@ for clicks");
1881+
break;
1882+
}
1883+
}
1884+
1885+
return false;
1886+
}elseif (in_winbar) {
1887+
// A drag or release event in the window bar has no side effects.
1888+
return false;
1889+
}
18631890

18641891
// When jumping to another window, clear a pending operator. That's a bit
18651892
// friendlier than beeping and not jumping to that window.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp