@@ -24,50 +24,105 @@ local function get_lines_with_extmarks(bufnr, ns)
24
24
lines [lnum ] = prefix .. virt_text [1 ] .. suffix
25
25
col_offset [lnum ] = col_offset [lnum ] + # virt_text [1 ]
26
26
end
27
+ elseif details .virt_text_pos == " overlay" then
28
+ local virt_text = details .virt_text [1 ][1 ]
29
+ col_offset [lnum ] = col_offset [lnum ] or 0
30
+ local prefix = lines [lnum ]:sub (1 , col + col_offset [lnum ])
31
+ local suffix = lines [lnum ]:sub (col + col_offset [lnum ] + 1 + vim .fn .strdisplaywidth (virt_text ))
32
+ lines [lnum ] = prefix .. virt_text .. suffix
33
+ col_offset [lnum ] = col_offset [lnum ] + # virt_text - vim .fn .strdisplaywidth (virt_text )
27
34
end
28
35
end
36
+
29
37
return lines
30
38
end
31
39
32
40
describe (" view" , function ()
33
41
csvview .setup ()
34
42
local ns = vim .api .nvim_get_namespaces ()[" csv_extmark" ]
35
43
describe (" CsvView:render" , function ()
36
- it (" should align correctly even if it contains multibyte characters" , function ()
37
- local bufnr = vim .api .nvim_create_buf (false , true )
38
- local opts = config .get ({
39
- view = { min_column_width = 5 , spacing = 1 },
40
- })
41
- local lines = {
42
- " column1(number),column2(emoji),column3(string)" ,
43
- " 111,π,abcde" ,
44
- " 222222222222,ππππ,fgh" ,
45
- " 333333333333333333,πbπbπbπbπbπb,ijk" ,
46
- }
47
- local expected = {
48
- " column1(number) ,column2(emoji) ,column3(string) " ,
49
- " 111,π ,abcde " ,
50
- " 222222222222,ππππ ,fgh " ,
51
- " 333333333333333333,πbπbπbπbπbπb ,ijk " ,
52
- }
44
+ describe (" should align correctly even if it contains multibyte characters" , function ()
45
+ it (" display_mode = 'highlight'" , function ()
46
+ local bufnr = vim .api .nvim_create_buf (false , true )
47
+ local opts = config .get ({
48
+ view = {
49
+ min_column_width = 5 ,
50
+ spacing = 1 ,
51
+ display_mode = " highlight" ,
52
+ },
53
+ })
54
+ local lines = {
55
+ " column1(number),column2(emoji),column3(string)" ,
56
+ " 111,π,abcde" ,
57
+ " 222222222222,ππππ,fgh" ,
58
+ " 333333333333333333,πbπbπbπbπbπb,ijk" ,
59
+ }
60
+ local expected = {
61
+ " column1(number) ,column2(emoji) ,column3(string) " ,
62
+ " 111,π ,abcde " ,
63
+ " 222222222222,ππππ ,fgh " ,
64
+ " 333333333333333333,πbπbπbπbπbπb ,ijk " ,
65
+ }
53
66
54
- vim .api .nvim_buf_set_lines (bufnr , 0 , - 1 , false , lines )
55
- local co = coroutine.running ()
56
- metrics .compute_csv_metrics (bufnr , opts , function (fields , column_max_widths )
57
- local v = view .CsvView :new (bufnr , fields , column_max_widths , opts )
67
+ vim .api .nvim_buf_set_lines (bufnr , 0 , - 1 , false , lines )
68
+ local co = coroutine.running ()
69
+ metrics .compute_csv_metrics (bufnr , opts , function (fields , column_max_widths )
70
+ local v = view .CsvView :new (bufnr , fields , column_max_widths , opts )
58
71
59
- -- test
60
- v :render (1 , vim .api .nvim_buf_line_count (bufnr ))
61
- local actual = get_lines_with_extmarks (bufnr , ns )
62
- for i , line in ipairs (actual ) do
63
- assert .are .same (expected [i ], line )
64
- end
65
- vim .schedule (function ()
66
- coroutine.resume (co )
72
+ -- test
73
+ v :render (1 , vim .api .nvim_buf_line_count (bufnr ))
74
+ local actual = get_lines_with_extmarks (bufnr , ns )
75
+ for i , line in ipairs (actual ) do
76
+ assert .are .same (expected [i ], line )
77
+ end
78
+ vim .schedule (function ()
79
+ coroutine.resume (co )
80
+ end )
67
81
end )
82
+
83
+ coroutine.yield ()
68
84
end )
69
85
70
- coroutine.yield ()
86
+ it (" display_mode = 'border'" , function ()
87
+ local bufnr = vim .api .nvim_create_buf (false , true )
88
+ local opts = config .get ({
89
+ view = {
90
+ min_column_width = 5 ,
91
+ spacing = 1 ,
92
+ display_mode = " border" ,
93
+ },
94
+ })
95
+ local lines = {
96
+ " column1(number),column2(emoji),column3(string)" ,
97
+ " 111,π,abcde" ,
98
+ " 222222222222,ππππ,fgh" ,
99
+ " 333333333333333333,πbπbπbπbπbπb,ijk" ,
100
+ }
101
+ local expected = {
102
+ " column1(number) βcolumn2(emoji) βcolumn3(string) " ,
103
+ " 111βπ βabcde " ,
104
+ " 222222222222βππππ βfgh " ,
105
+ " 333333333333333333βπbπbπbπbπbπb βijk " ,
106
+ }
107
+
108
+ vim .api .nvim_buf_set_lines (bufnr , 0 , - 1 , false , lines )
109
+ local co = coroutine.running ()
110
+ metrics .compute_csv_metrics (bufnr , opts , function (fields , column_max_widths )
111
+ local v = view .CsvView :new (bufnr , fields , column_max_widths , opts )
112
+
113
+ -- test
114
+ v :render (1 , vim .api .nvim_buf_line_count (bufnr ))
115
+ local actual = get_lines_with_extmarks (bufnr , ns )
116
+ for i , line in ipairs (actual ) do
117
+ assert .are .same (expected [i ], line )
118
+ end
119
+ vim .schedule (function ()
120
+ coroutine.resume (co )
121
+ end )
122
+ end )
123
+
124
+ coroutine.yield ()
125
+ end )
71
126
end )
72
127
end )
73
128
end )
0 commit comments