@@ -24,20 +24,21 @@ T["prev_buf_mark"] = MiniTest.new_set()
2424
2525T [" next_buf_mark" ][" navigates forward" ] = function ()
2626 new_buf ()
27- child .type_keys ({ " gg" , " ma" , " j" , " mb" , " j" , " mc" , " gg" })
27+ -- marks on lines 2 and 3; cursor starts at line 1 so no same-line ambiguity
28+ child .type_keys ({ " gg" , " 0" , " j" , " 0" , " llll" , " ma" , " j" , " 0" , " l" , " mb" , " gg" , " 0" })
2829
2930 child .lua ([[ M.next_buf_mark() ]] )
30- eq (child .api .nvim_win_get_cursor (0 )[ 1 ], 2 )
31+ eq (child .api .nvim_win_get_cursor (0 ), { 2 , 4 } )
3132
3233 child .lua ([[ M.next_buf_mark() ]] )
33- eq (child .api .nvim_win_get_cursor (0 )[ 1 ], 3 )
34+ eq (child .api .nvim_win_get_cursor (0 ), { 3 , 1 } )
3435end
3536
3637T [" next_buf_mark" ][" no marks ahead" ] = function ()
3738 new_buf ()
3839 child .type_keys ({ " gg" , " ma" , " j" })
3940
40- child .lua ([[ M.next_buf_mark() ]] )
41+ child .lua ([[ M.next_buf_mark({ wrap = false } ) ]] )
4142 eq (child .api .nvim_win_get_cursor (0 )[1 ], 2 )
4243end
4344
5152
5253T [" next_buf_mark" ][" skips global marks with opts" ] = function ()
5354 new_buf ()
54- child .type_keys ({ " gg" , " ma" , " j" , " mb" , " j" , " mC" , " j" , " md" , " gg" })
55+ -- marks on lines 2-4; cursor starts at line 1 so no same-line ambiguity
56+ child .type_keys ({ " gg" , " 0" , " j" , " 0" , " lll" , " ma" , " j" , " 0" , " mC" , " j" , " 0" , " l" , " mb" , " gg" , " 0" })
5557
5658 child .lua ([[ M.next_buf_mark({ global_mark = false }) ]] )
57- eq (child .api .nvim_win_get_cursor (0 )[ 1 ], 2 )
59+ eq (child .api .nvim_win_get_cursor (0 ), { 2 , 3 } )
5860
5961 child .lua ([[ M.next_buf_mark({ global_mark = false }) ]] )
60- eq (child .api .nvim_win_get_cursor (0 )[ 1 ], 4 )
62+ eq (child .api .nvim_win_get_cursor (0 ), { 4 , 1 } )
6163end
6264
6365T [" prev_buf_mark" ][" navigates backward" ] = function ()
6466 new_buf ()
65- child .type_keys ({ " gg" , " ma" , " j" , " mb" , " j" , " mc" , " G" })
67+ child .type_keys ({ " gg" , " ll " , " ma" , " j" , " 0 " , " llll " , " mb" , " j" , " 0 " , " l " , " mc" , " G" })
6668
6769 child .lua ([[ M.prev_buf_mark() ]] )
68- eq (child .api .nvim_win_get_cursor (0 )[ 1 ], 3 )
70+ eq (child .api .nvim_win_get_cursor (0 ), { 3 , 1 } )
6971
7072 child .lua ([[ M.prev_buf_mark() ]] )
71- eq (child .api .nvim_win_get_cursor (0 )[ 1 ], 2 )
73+ eq (child .api .nvim_win_get_cursor (0 ), { 2 , 4 } )
7274end
7375
7476T [" prev_buf_mark" ][" no marks behind" ] = function ()
8991
9092T [" prev_buf_mark" ][" skips local marks with opts" ] = function ()
9193 new_buf ()
92- child .type_keys ({ " gg" , " ma" , " jj" , " mB" , " jj" , " mc" , " G" })
94+ child .type_keys ({ " gg" , " ll " , " ma" , " jj" , " 0 " , " lll " , " mB" , " jj" , " 0 " , " l " , " mc" , " G" })
9395
9496 child .lua ([[ M.prev_buf_mark({ local_mark = false }) ]] )
95- eq (child .api .nvim_win_get_cursor (0 )[1 ], 3 )
97+ eq (child .api .nvim_win_get_cursor (0 ), { 3 , 3 })
98+ end
99+
100+ T [" Multiple marks on the same line" ] = function ()
101+ new_buf ()
102+ -- mark a at line 2 col 1, mark b at line 2 col 3
103+ child .type_keys ({ " gg" , " 0" , " j" , " 0" , " l" , " ma" , " ll" , " mb" , " gg" , " 0" })
104+
105+ child .lua ([[ M.next_buf_mark() ]] )
106+ eq (child .api .nvim_win_get_cursor (0 ), { 2 , 1 })
107+
108+ child .lua ([[ M.next_buf_mark() ]] )
109+ eq (child .api .nvim_win_get_cursor (0 ), { 2 , 3 })
110+
111+ -- navigate backward through same-line marks
112+ child .lua ([[ M.prev_buf_mark() ]] )
113+ eq (child .api .nvim_win_get_cursor (0 ), { 2 , 1 })
96114end
97115
98116T [" Mixed local and global marks" ] = function ()
99117 new_buf ()
100- child .type_keys ({ " gg" , " ma" , " j" , " mB" , " j" , " mc" , " gg" })
118+ -- mark a at cursor start position so it is not "ahead"; B and c are on later lines
119+ child .type_keys ({ " gg" , " 0" , " ma" , " j" , " 0" , " lll" , " mB" , " j" , " 0" , " l" , " mc" , " gg" , " 0" })
101120
102121 child .lua ([[ M.next_buf_mark() ]] )
103- eq (child .api .nvim_win_get_cursor (0 )[ 1 ], 2 )
122+ eq (child .api .nvim_win_get_cursor (0 ), { 2 , 3 } )
104123
105124 child .lua ([[ M.next_buf_mark() ]] )
106- eq (child .api .nvim_win_get_cursor (0 )[ 1 ], 3 )
125+ eq (child .api .nvim_win_get_cursor (0 ), { 3 , 1 } )
107126end
108127
109128T [" next_buf_mark wrap" ] = MiniTest .new_set ()
110129T [" prev_buf_mark wrap" ] = MiniTest .new_set ()
111130
112131T [" next_buf_mark wrap" ][" wraps from last mark to first" ] = function ()
113132 new_buf ()
114- child .type_keys ({ " gg" , " ma" , " j" , " mb" , " j" , " mc" , " G " })
133+ child .type_keys ({ " gg" , " 0 " , " ll " , " ma" , " j" , " 0 " , " mb" , " j" , " 0 " , " mc" , " jj " })
115134
116135 child .lua ([[ M.next_buf_mark({ wrap = true }) ]] )
117- eq (child .api .nvim_win_get_cursor (0 )[ 1 ], 1 )
136+ eq (child .api .nvim_win_get_cursor (0 ), { 1 , 2 } )
118137end
119138
120139T [" next_buf_mark wrap" ][" does not wrap when mark found ahead" ] = function ()
121140 new_buf ()
122- child .type_keys ({ " gg" , " ma" , " j" , " mb" , " gg" })
141+ -- mark a at col 0, cursor ends at col 3 after gg (preserved), so a is behind
142+ child .type_keys ({ " gg" , " 0" , " ma" , " j" , " 0" , " lll" , " mb" , " gg" })
123143
124144 child .lua ([[ M.next_buf_mark({ wrap = true }) ]] )
125- eq (child .api .nvim_win_get_cursor (0 )[ 1 ], 2 )
145+ eq (child .api .nvim_win_get_cursor (0 ), { 2 , 3 } )
126146end
127147
128148T [" next_buf_mark wrap" ][" no marks present stays put" ] = function ()
@@ -137,24 +157,24 @@ T["next_buf_mark wrap"]["no wrap without opt"] = function()
137157 new_buf ()
138158 child .type_keys ({ " gg" , " ma" , " j" , " mb" , " G" })
139159
140- child .lua ([[ M.next_buf_mark() ]] )
160+ child .lua ([[ M.next_buf_mark({ wrap = false } ) ]] )
141161 eq (child .api .nvim_win_get_cursor (0 )[1 ], 5 )
142162end
143163
144164T [" prev_buf_mark wrap" ][" wraps from first mark to last" ] = function ()
145165 new_buf ()
146- child .type_keys ({ " gg" , " ma" , " j" , " mb" , " j" , " mc" , " gg" })
166+ child .type_keys ({ " gg" , " ma" , " j" , " 0 " , " mb" , " j" , " 0 " , " l " , " mc" , " gg" })
147167
148168 child .lua ([[ M.prev_buf_mark({ wrap = true }) ]] )
149- eq (child .api .nvim_win_get_cursor (0 )[ 1 ], 3 )
169+ eq (child .api .nvim_win_get_cursor (0 ), { 3 , 1 } )
150170end
151171
152172T [" prev_buf_mark wrap" ][" does not wrap when mark found behind" ] = function ()
153173 new_buf ()
154- child .type_keys ({ " gg" , " ma" , " j" , " mb" , " G" })
174+ child .type_keys ({ " gg" , " ma" , " j" , " 0 " , " lll " , " mb" , " G" })
155175
156176 child .lua ([[ M.prev_buf_mark({ wrap = true }) ]] )
157- eq (child .api .nvim_win_get_cursor (0 )[ 1 ], 2 )
177+ eq (child .api .nvim_win_get_cursor (0 ), { 2 , 3 } )
158178end
159179
160180T [" prev_buf_mark wrap" ][" no marks present stays put" ] = function ()
@@ -169,7 +189,7 @@ T["prev_buf_mark wrap"]["no wrap without opt"] = function()
169189 new_buf ()
170190 child .type_keys ({ " gg" , " ma" , " j" , " mb" , " gg" })
171191
172- child .lua ([[ M.prev_buf_mark() ]] )
192+ child .lua ([[ M.prev_buf_mark({ wrap = false } ) ]] )
173193 eq (child .api .nvim_win_get_cursor (0 )[1 ], 1 )
174194end
175195
0 commit comments