File tree Expand file tree Collapse file tree 1 file changed +8
-22
lines changed Expand file tree Collapse file tree 1 file changed +8
-22
lines changed Original file line number Diff line number Diff line change @@ -712,26 +712,15 @@ end
712
712
--- @param regex string
713
713
local function regexAddAllCursors (ctx , regex )
714
714
local mainCursor = ctx :mainCursor ()
715
- if mainCursor :hasSelection () then
716
- mainCursor : feedkeys ( TERM_CODES . ESC )
717
- end
718
- local positions = {}
719
- local nPositions = 0
720
- while true do
715
+ mainCursor :setMode ( " n " )
716
+ vim . fn . search ( regex )
717
+ local firstPos = vim . fn . getcurpos ()
718
+ local pos = firstPos
719
+ repeat
720
+ mainCursor : clone (): setPos ({ pos [ 2 ], pos [ 3 ] })
721
721
vim .fn .search (regex )
722
- local pos = vim .fn .getcurpos ()
723
- nPositions = nPositions + 1
724
- positions [nPositions ] = { pos [2 ], pos [3 ] }
725
- if nPositions > 1
726
- and positions [1 ][1 ] == positions [nPositions ][1 ]
727
- and positions [1 ][2 ] == positions [nPositions ][2 ]
728
- then
729
- break
730
- end
731
- end
732
- for _ , position in ipairs (positions ) do
733
- mainCursor :clone ():setPos (position )
734
- end
722
+ pos = vim .fn .getcurpos ()
723
+ until firstPos [2 ] == pos [2 ] and firstPos [3 ] == pos [3 ]
735
724
mainCursor :delete ()
736
725
end
737
726
@@ -755,9 +744,6 @@ function examples.searchAllAddCursors()
755
744
return
756
745
end
757
746
mc .action (function (ctx )
758
- if ctx :mainCursor ():hasSelection () then
759
- ctx :mainCursor ():feedkeys (TERM_CODES .ESC )
760
- end
761
747
regexAddAllCursors (ctx , regex )
762
748
end )
763
749
end
You can’t perform that action at this time.
0 commit comments