Skip to content

Commit de3c702

Browse files
committed
feat(statuscolumn): Added click support for lnum
1 parent 869299a commit de3c702

File tree

4 files changed

+101
-31
lines changed

4 files changed

+101
-31
lines changed

lua/bars/components/statuscolumn.lua

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ffi.cdef(table.concat(C, "\n"));
2222
--- Line number.
2323
---@param buffer integer
2424
---@param window integer
25-
---@param config statuscolumn.lnum
25+
---@param config statuscolumn.parts.lnum
2626
---@return string
2727
scC.lnum = function (buffer, window, config)
2828
---|fS
@@ -73,30 +73,38 @@ scC.lnum = function (buffer, window, config)
7373
});
7474
end
7575
elseif config.mode == 1 then
76-
_o = _o
77-
.. utils.set_hl(get(config.hl, vim.v.relnum + 1))
78-
.. utils.align("right", vim.v.lnum, max_width)
79-
;
76+
_o = table.concat({
77+
_o,
78+
utils.set_hl(get(config.hl, vim.v.relnum + 1)),
79+
utils.align("right", vim.v.lnum, max_width)
80+
});
8081
elseif config.mode == 2 then
81-
_o = _o
82-
.. utils.set_hl(get(config.hl, vim.v.relnum + 1))
83-
.. utils.align("right", vim.v.relnum, max_width)
84-
;
82+
_o = table.concat({
83+
_o,
84+
utils.set_hl(get(config.hl, vim.v.relnum + 1)),
85+
utils.align("right", vim.v.relnum, max_width)
86+
});
8587
elseif vim.v.relnum == 0 then
86-
_o = _o
87-
.. utils.set_hl(get(config.hl, vim.v.relnum + 1, true))
88-
.. utils.align("right", vim.v.lnum, max_width)
89-
;
88+
_o = table.concat({
89+
_o,
90+
utils.set_hl(get(config.hl, vim.v.relnum + 1, true)),
91+
utils.align("right", vim.v.lnum, max_width)
92+
});
9093
else
91-
_o = _o
92-
.. utils.set_hl(get(config.hl, vim.v.relnum + 1))
93-
.. utils.align("right", vim.v.relnum, max_width)
94-
;
94+
_o = table.concat({
95+
_o,
96+
utils.set_hl(get(config.hl, vim.v.relnum + 1)),
97+
utils.align("right", vim.v.relnum, max_width)
98+
});
9599
end
96100

97-
--- FEAT, Maybe Later.
98-
-- if config.click_support ~= false then
99-
-- end
101+
if config.click ~= false then
102+
_o = table.concat({
103+
"%@v:lua.__goto_lnum@",
104+
_o,
105+
"%X"
106+
});
107+
end
100108

101109
return _o;
102110

lua/bars/global.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
local statusline = require("bars.statusline");
22
local utils = require("bars.utils");
33

4+
--- Goes to clicked line number.
5+
_G.__goto_lnum = function ()
6+
local mousepos = vim.fn.getmousepos();
7+
local cursor = vim.api.nvim_win_get_cursor(mousepos.winid);
8+
9+
pcall(vim.api.nvim_win_set_cursor, mousepos.winid, { mousepos.line, cursor[2] });
10+
end
11+
412
--- Changes the type of diagnostic
513
--- that are shown on the statusline.
614
_G.__change_diagnostic_state = function ()

lua/bars/statuscolumn.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ statuscolumn.config = {
4343
},
4444
{
4545
kind = "lnum",
46+
mode = 3,
47+
48+
click = function (_, window)
49+
return window == vim.api.nvim_get_current_win();
50+
end,
4651

4752
wrap_markers = "",
4853
virt_markers = "",
@@ -121,6 +126,7 @@ statuscolumn.config = {
121126
condition = function (buffer)
122127
return vim.bo[buffer].ft == "query" and vim.bo[buffer].bt == "nofile";
123128
end,
129+
124130
parts = {
125131
{
126132
kind = "empty",

lua/definitions/statuscolumn.lua

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,105 @@
11
---@meta
22

3-
3+
--- Statuscolumn state variables.
44
---@class statuscolumn.state
55
---
6+
--- Is the module enabled?
67
---@field enable boolean
7-
---@field attached_windows { [integer]: boolean }
8+
---
9+
---@field attached_windows table<integer, boolean>
810

11+
-----------------------------------------------------------------------------
912

13+
--- Configuration table for the statuscolumn.
1014
---@class statuscolumn.config
1115
---
16+
--- Filetypes to ignore.
1217
---@field ignore_filetypes string[]
18+
--- Buftypes to ignore.
1319
---@field ignore_buftypes string[]
1420
---
15-
---@field condition? fun(buffer: integer): boolean | nil
21+
--- Additional condition for attaching to
22+
--- windows.
23+
---@field condition? fun(buffer: integer, window: integer): boolean | nil
24+
---
25+
--- Default style.
26+
---@field default statuscolumn.style
27+
---
28+
--- Configuration style.
29+
---@field [string] statuscolumn.style
30+
31+
--- A configuration style.
32+
--- Must have a condition(unless `default`)
33+
--- and a list of parts.
34+
---@class statuscolumn.style
35+
---
36+
---@field condition? fun(buffer: integer, window: integer): boolean Condition for this style.
1637
---
17-
---@field default table
18-
---@field [string] table
38+
--- Parts for this style.
39+
---@field parts statuscolumn_part[]
1940

41+
---@alias statuscolumn_part
42+
---| statuscolumn.parts.lnum Line number.
43+
---| statuscolumn.parts.folds Fold column.
44+
---| statuscolumn.parts.signs Sign column.
45+
---| statuscolumn.parts.empty An empty column.
46+
---| statuscolumn.parts.border A statuscolumn border.
2047

21-
---@class statuscolumn.lnum
48+
-----------------------------------------------------------------------------
49+
50+
--- Line number for statuscolumn.
51+
---@class statuscolumn.parts.lnum
52+
---
53+
--- Condition for this component.
54+
---@field condition? fun(buffer: integer, window: integer, statuscolumn: string): boolean
55+
---
56+
---@field kind "lnum" What kind of part is this?
57+
---
58+
---@field click? boolean | fun(buffer: integer, window: integer, statuscolumn: string): boolean
2259
---
23-
---@field kind "lnum"
2460
---@field mode
2561
---| 1 Line number.
2662
---| 2 Relative line number.
2763
---| 3 Hybrid line number.
2864
---
65+
--- Text used for the wrapped lines.
66+
--- Can be a list to create a *fake* gradient effect.
2967
---@field wrap_markers string | string[]
68+
---
69+
--- Text used for the virtual lines.
70+
--- Can be a list to create a *fake* gradient effect.
3071
---@field virt_markers string | string[]
3172
---
73+
--- Highlight group for `wrap_markers`.
74+
--- Can be a list to create a color gradient.
3275
---@field wrap_hl? string | string[]
76+
---
77+
--- Highlight group for `virt_markers`.
78+
--- Can be a list to create a color gradient.
3379
---@field virt_hl? string | string[]
3480
---
81+
--- Highlight group for the line numbers.
82+
--- Can be a list to create a color gradient.
3583
---@field hl? string | string[]
3684

3785

38-
---@class statuscolumn.empty
86+
---@class statuscolumn.parts.empty
3987
---
4088
---@field kind "empty"
4189
---@field len integer
4290
---
4391
---@field hl? string
4492

4593

46-
---@class statuscolumn.border
94+
---@class statuscolumn.parts.border
4795
---
4896
---@field kind "border"
4997
---
5098
---@field text string | string[]
5199
---@field hl? string | string[]
52100

53101

54-
---@class statuscolumn.folds
102+
---@class statuscolumn.parts.folds
55103
---
56104
---@field kind "folds"
57105
---
@@ -74,7 +122,7 @@
74122
---@field fill_hl? string
75123

76124

77-
---@class statuscolumn.signs
125+
---@class statuscolumn.parts.signs
78126
---
79127
---@field kind "signs"
80128
---@field hl? string

0 commit comments

Comments
 (0)