Skip to content

Commit cc5eb02

Browse files
committed
fix(files): account for 'cursorlineopt' to force show cursor line
Resolve #2084
1 parent 5121416 commit cc5eb02

7 files changed

+106
-17
lines changed

lua/mini/files.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,8 @@ H.explorer_show_help = function(explorer, explorer_buf_id, explorer_win_id)
19451945
H.window_update_highlight(win_id, 'FloatTitle', 'MiniFilesTitle')
19461946
H.window_update_highlight(win_id, 'CursorLine', 'MiniFilesCursorLine')
19471947
vim.wo[win_id].cursorline = true
1948+
local culopt = vim.wo[win_id].cursorlineopt
1949+
if culopt:find('line') == nil then vim.wo[win_id].cursorlineopt = culopt .. ',line' end
19481950

19491951
vim.api.nvim_set_current_win(win_id)
19501952
return win_id
@@ -2504,8 +2506,10 @@ H.window_set_view = function(win_id, view)
25042506

25052507
-- Set cursor (if defined), visible only in directories
25062508
pcall(H.window_set_cursor, win_id, view.cursor)
2507-
-- NOTE: set 'cursorline' here because changing buffer might remove it
2509+
-- NOTE: set 'cursorline[opt]' here because changing buffer might remove it
25082510
vim.wo[win_id].cursorline = H.fs_get_type(buf_data.path) == 'directory'
2511+
local culopt = vim.wo[win_id].cursorlineopt
2512+
if culopt:find('line') == nil then vim.wo[win_id].cursorlineopt = culopt .. ',line' end
25092513

25102514
-- Update border highlight based on buffer status
25112515
H.window_update_border_hl(win_id)

tests/dir-files/common/b-file

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
b-file
2+
Another line

tests/screenshots/tests-test_files.lua---Default-explorer---works-in-`-tabfind-.`-002

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--|---------|---------|---------|---------|---------|---------|
22
01|b-file
3-
02|~
3+
02|Another line
44
03|~
55
04|~
66
05|~
@@ -17,7 +17,7 @@
1717

1818
--|---------|---------|---------|---------|---------|---------|
1919
01|000000000000000000000000000000000000000000000000000000000000
20-
02|111111111111111111111111111111111111111111111111111111111111
20+
02|000000000000000000000000000000000000000000000000000000000000
2121
03|111111111111111111111111111111111111111111111111111111111111
2222
04|111111111111111111111111111111111111111111111111111111111111
2323
05|111111111111111111111111111111111111111111111111111111111111
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--|---------|---------|---------|---------|---------|---------|---------|---------|
22
01|b-file │
3-
02|~ │~
3+
02|Another line │~
44
03|~ │~
55
04|~ │~
66
05|~ │~
@@ -17,17 +17,17 @@
1717

1818
--|---------|---------|---------|---------|---------|---------|---------|---------|
1919
01|00000000000000000000000000000000000000001222222222222222222222222222222222222222
20-
02|33333333333333333333333333333333333333331444444444444444444444444444444444444444
21-
03|33333333333333333333333333333333333333331444444444444444444444444444444444444444
22-
04|33333333333333333333333333333333333333331444444444444444444444444444444444444444
23-
05|33333333333333333333333333333333333333331444444444444444444444444444444444444444
24-
06|33333333333333333333333333333333333333331444444444444444444444444444444444444444
25-
07|33333333333333333333333333333333333333331444444444444444444444444444444444444444
26-
08|33333333333333333333333333333333333333331444444444444444444444444444444444444444
27-
09|33333333333333333333333333333333333333331444444444444444444444444444444444444444
28-
10|33333333333333333333333333333333333333331444444444444444444444444444444444444444
29-
11|33333333333333333333333333333333333333331444444444444444444444444444444444444444
30-
12|33333333333333333333333333333333333333331444444444444444444444444444444444444444
31-
13|33333333333333333333333333333333333333331444444444444444444444444444444444444444
32-
14|33333333333333333333333333333333333333331444444444444444444444444444444444444444
20+
02|00000000000000000000000000000000000000001333333333333333333333333333333333333333
21+
03|44444444444444444444444444444444444444441333333333333333333333333333333333333333
22+
04|44444444444444444444444444444444444444441333333333333333333333333333333333333333
23+
05|44444444444444444444444444444444444444441333333333333333333333333333333333333333
24+
06|44444444444444444444444444444444444444441333333333333333333333333333333333333333
25+
07|44444444444444444444444444444444444444441333333333333333333333333333333333333333
26+
08|44444444444444444444444444444444444444441333333333333333333333333333333333333333
27+
09|44444444444444444444444444444444444444441333333333333333333333333333333333333333
28+
10|44444444444444444444444444444444444444441333333333333333333333333333333333333333
29+
11|44444444444444444444444444444444444444441333333333333333333333333333333333333333
30+
12|44444444444444444444444444444444444444441333333333333333333333333333333333333333
31+
13|44444444444444444444444444444444444444441333333333333333333333333333333333333333
32+
14|44444444444444444444444444444444444444441333333333333333333333333333333333333333
3333
15|22222222222222222222222222222222222222222222222222222222222222222222222222222222
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--|---------|---------|---------|---------|---------|---------|---------|---------|
2+
01|┌MOCK_ROOT/tests/dir-files/common ─────────────────┐┌ .a-dir ─────────────────┐
3+
02|│ .a-dir ││ aa-file │
4+
03|│ a-dir ││ ab-file │
5+
04|│ b-dir │└─────────────────────────┘
6+
05|│ .a-file │
7+
06|│ a-file │
8+
07|│ A-file-2 │
9+
08|│ b-file │
10+
09|└──────────────────────────────────────────────────┘
11+
10|~
12+
11|~
13+
12|~
14+
13|~
15+
14|~
16+
15| 1,9-7 All
17+
18+
--|---------|---------|---------|---------|---------|---------|---------|---------|
19+
01|01111111111111111111111111111111110000000000000000000222222220000000000000000003
20+
02|04444444455555555555555555555555555555555555555555500555555555555555555555555506
21+
03|07777777888888888888888888888888888888888888888888800888888888888888888888888806
22+
04|07777777888888888888888888888888888888888888888888800000000000000000000000000006
23+
05|08888888888888888888888888888888888888888888888888806666666666666666666666666666
24+
06|08888888888888888888888888888888888888888888888888806666666666666666666666666666
25+
07|08888888888888888888888888888888888888888888888888806666666666666666666666666666
26+
08|08888888888888888888888888888888888888888888888888806666666666666666666666666666
27+
09|00000000000000000000000000000000000000000000000000006666666666666666666666666666
28+
10|66666666666666666666666666666666666666666666666666666666666666666666666666666666
29+
11|66666666666666666666666666666666666666666666666666666666666666666666666666666666
30+
12|66666666666666666666666666666666666666666666666666666666666666666666666666666666
31+
13|66666666666666666666666666666666666666666666666666666666666666666666666666666666
32+
14|66666666666666666666666666666666666666666666666666666666666666666666666666666666
33+
15|33333333333333333333333333333333333333333333333333333333333333333333333333333333
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--|---------|---------|---------|---------|---------|---------|---------|---------|
2+
01|┌MOCK_ROOT/tests/dir-files/common ─────────────────┐┌ b-file ─────────────────┐
3+
02|│ .a-dir ││b-file │
4+
03|│ a-dir ││Another line │
5+
04|│ b-dir │└─────────────────────────┘
6+
05|│ .a-file │
7+
06|│ a-file │
8+
07|│ A-file-2 │
9+
08|│ b-file │
10+
09|└──────────────────────────────────────────────────┘
11+
10|~
12+
11|~
13+
12|~
14+
13|~
15+
14|~
16+
15| 7,9-7 All
17+
18+
--|---------|---------|---------|---------|---------|---------|---------|---------|
19+
01|01111111111111111111111111111111110000000000000000000222222220000000000000000003
20+
02|04444444455555555555555555555555555555555555555555500555555555555555555555555506
21+
03|04444444555555555555555555555555555555555555555555500555555555555555555555555506
22+
04|04444444555555555555555555555555555555555555555555500000000000000000000000000006
23+
05|05555555555555555555555555555555555555555555555555506666666666666666666666666666
24+
06|05555555555555555555555555555555555555555555555555506666666666666666666666666666
25+
07|05555555555555555555555555555555555555555555555555506666666666666666666666666666
26+
08|07777777777777777777777777777777777777777777777777706666666666666666666666666666
27+
09|00000000000000000000000000000000000000000000000000006666666666666666666666666666
28+
10|66666666666666666666666666666666666666666666666666666666666666666666666666666666
29+
11|66666666666666666666666666666666666666666666666666666666666666666666666666666666
30+
12|66666666666666666666666666666666666666666666666666666666666666666666666666666666
31+
13|66666666666666666666666666666666666666666666666666666666666666666666666666666666
32+
14|66666666666666666666666666666666666666666666666666666666666666666666666666666666
33+
15|33333333333333333333333333333333333333333333333333333333333333333333333333333333

tests/test_files.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,6 +2545,24 @@ T['Windows']['correctly highlight content during editing'] = function()
25452545
child.expect_screenshot()
25462546
end
25472547

2548+
T['Windows']['always show cursor line in directories'] = function()
2549+
child.o.cursorline = false
2550+
child.o.cursorlineopt = 'number'
2551+
open(test_dir_path, false, { windows = { preview = true } })
2552+
child.expect_screenshot()
2553+
eq(child.wo.cursorlineopt, 'number,line')
2554+
2555+
-- File preview should not show cursor line
2556+
type_keys('G')
2557+
child.expect_screenshot()
2558+
close()
2559+
2560+
-- Should preserve flags of 'cursorlineopt' as much as possible
2561+
child.o.cursorlineopt = 'screenline'
2562+
open(test_dir_path)
2563+
eq(child.wo.cursorlineopt, 'screenline')
2564+
end
2565+
25482566
T['Windows']['can be closed manually'] = function()
25492567
open(test_dir_path)
25502568
type_keys('G', '<CR>')

0 commit comments

Comments
 (0)