+49
-2
lines changedFilter options
+49
-2
lines changed Original file line number Diff line number Diff line change
@@ -192,8 +192,19 @@ do
192
192
if mode:find('^n') then -- Normal mode
193
193
vim.api.nvim_put(lines, 'c', true, false)
194
194
else -- Visual or Select mode
195
-
vim.api.nvim_command([[exe "normal! \<Del>"]])
196
-
vim.api.nvim_put(lines, 'c', false, false)
195
+
vim.api.nvim_command([[exe "silent normal! \<Del>"]])
196
+
local del_start = vim.fn.getpos("'[")
197
+
local cursor_pos = vim.fn.getpos('.')
198
+
if mode:find('^[VS]') then -- linewise
199
+
if cursor_pos[2] < del_start[2] then -- replacing lines at eof
200
+
-- create a new line
201
+
vim.api.nvim_put({''}, 'l', true, true)
202
+
end
203
+
vim.api.nvim_put(lines, 'c', false, false)
204
+
else
205
+
-- paste after cursor when replacing text at eol, otherwise paste before cursor
206
+
vim.api.nvim_put(lines, 'c', cursor_pos[3] < del_start[3], false)
207
+
end
197
208
end
198
209
-- put cursor at the end of the text instead of one character after it
199
210
vim.fn.setpos('.', vim.fn.getpos("']"))
Original file line number Diff line number Diff line change
@@ -702,6 +702,42 @@ describe('API', function()
702
702
feed('u')
703
703
expect('||')
704
704
end)
705
+
it('stream: Visual mode either end not at the end of a line', function()
706
+
feed('i|xxx<CR>xxx|<Esc>hvhk')
707
+
nvim('paste', 'aaaaaa', false, 1)
708
+
nvim('paste', 'bbbbbb', false, 2)
709
+
nvim('paste', 'cccccc', false, 2)
710
+
nvim('paste', 'dddddd', false, 3)
711
+
expect('|aaaaaabbbbbbccccccdddddd|')
712
+
feed('u')
713
+
expect([[
714
+
|xxx
715
+
xxx|]])
716
+
end)
717
+
it('stream: Visual mode cursor at the end of a line', function()
718
+
feed('i||xxx<CR>xxx<Esc>vko')
719
+
nvim('paste', 'aaaaaa', false, 1)
720
+
nvim('paste', 'bbbbbb', false, 2)
721
+
nvim('paste', 'cccccc', false, 2)
722
+
nvim('paste', 'dddddd', false, 3)
723
+
expect('||aaaaaabbbbbbccccccdddddd')
724
+
feed('u')
725
+
expect([[
726
+
||xxx
727
+
xxx]])
728
+
end)
729
+
it('stream: Visual mode other end at the end of a line', function()
730
+
feed('i||xxx<CR>xxx<Esc>vk')
731
+
nvim('paste', 'aaaaaa', false, 1)
732
+
nvim('paste', 'bbbbbb', false, 2)
733
+
nvim('paste', 'cccccc', false, 2)
734
+
nvim('paste', 'dddddd', false, 3)
735
+
expect('||aaaaaabbbbbbccccccdddddd')
736
+
feed('u')
737
+
expect([[
738
+
||xxx
739
+
xxx]])
740
+
end)
705
741
it('non-streaming', function()
706
742
-- With final "\n".
707
743
nvim('paste', 'line 1\nline 2\nline 3\n', true, -1)
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4