+48
-3
lines changedFilter options
+48
-3
lines changed Original file line number Diff line number Diff line change
@@ -128,7 +128,7 @@ local function inspect(object, options) -- luacheck: no unused
128
128
end
129
129
130
130
do
131
-
local tdots, tick, got_line1, undo_started = 0, 0, false, false
131
+
local tdots, tick, got_line1, undo_started, trailing_nl = 0, 0, false, false, false
132
132
133
133
--- Paste handler, invoked by |nvim_paste()| when a conforming UI
134
134
--- (such as the |TUI|) pastes text into the editor.
@@ -160,7 +160,7 @@ do
160
160
local is_first_chunk = phase < 2
161
161
local is_last_chunk = phase == -1 or phase == 3
162
162
if is_first_chunk then -- Reset flags.
163
-
tdots, tick, got_line1, undo_started = now, 0, false, false
163
+
tdots, tick, got_line1, undo_started, trailing_nl = now, 0, false, false, false
164
164
end
165
165
if #lines == 0 then
166
166
lines = {''}
@@ -203,7 +203,10 @@ do
203
203
vim.api.nvim_buf_set_lines(0, row-1, row, false, lines)
204
204
elseif mode:find('^[nvV\22sS\19]') then -- Normal or Visual or Select mode
205
205
if mode:find('^n') then -- Normal mode
206
-
vim.api.nvim_put(lines, 'c', true, false)
206
+
-- When there was a trailing new line in the previous chunk,
207
+
-- the cursor is on the first character of the next line,
208
+
-- so paste before the cursor instead of after it.
209
+
vim.api.nvim_put(lines, 'c', not trailing_nl, false)
207
210
else -- Visual or Select mode
208
211
vim.api.nvim_command([[exe "silent normal! \<Del>"]])
209
212
local del_start = vim.fn.getpos("'[")
@@ -221,6 +224,7 @@ do
221
224
end
222
225
-- put cursor at the end of the text instead of one character after it
223
226
vim.fn.setpos('.', vim.fn.getpos("']"))
227
+
trailing_nl = lines[#lines] == ''
224
228
else -- Don't know what to do in other modes
225
229
return false
226
230
end
Original file line number Diff line number Diff line change
@@ -686,6 +686,19 @@ describe('API', function()
686
686
feed('u')
687
687
expect('')
688
688
end)
689
+
it('stream: Normal mode on empty line pasting multiple lines', function()
690
+
nvim('paste', 'aaaaaa\n', false, 1)
691
+
nvim('paste', 'bbbbbb\n', false, 2)
692
+
nvim('paste', 'cccccc\n', false, 2)
693
+
nvim('paste', 'dddddd', false, 3)
694
+
expect([[
695
+
aaaaaa
696
+
bbbbbb
697
+
cccccc
698
+
dddddd]])
699
+
feed('u')
700
+
expect('')
701
+
end)
689
702
it('stream: Normal mode not at the end of a line', function()
690
703
feed('i||<Esc>0')
691
704
nvim('paste', 'aaaaaa', false, 1)
@@ -696,6 +709,20 @@ describe('API', function()
696
709
feed('u')
697
710
expect('||')
698
711
end)
712
+
it('stream: Normal mode not at the end of a line pasting multiple lines', function()
713
+
feed('i||<Esc>0')
714
+
nvim('paste', 'aaaaaa\n', false, 1)
715
+
nvim('paste', 'bbbbbb\n', false, 2)
716
+
nvim('paste', 'cccccc\n', false, 2)
717
+
nvim('paste', 'dddddd', false, 3)
718
+
expect([[
719
+
|aaaaaa
720
+
bbbbbb
721
+
cccccc
722
+
dddddd|]])
723
+
feed('u')
724
+
expect('||')
725
+
end)
699
726
it('stream: Normal mode at the end of a line', function()
700
727
feed('i||<Esc>')
701
728
nvim('paste', 'aaaaaa', false, 1)
@@ -706,6 +733,20 @@ describe('API', function()
706
733
feed('u')
707
734
expect('||')
708
735
end)
736
+
it('stream: Normal mode at the end of a line pasting multiple lines', function()
737
+
feed('i||<Esc>')
738
+
nvim('paste', 'aaaaaa\n', false, 1)
739
+
nvim('paste', 'bbbbbb\n', false, 2)
740
+
nvim('paste', 'cccccc\n', false, 2)
741
+
nvim('paste', 'dddddd', false, 3)
742
+
expect([[
743
+
||aaaaaa
744
+
bbbbbb
745
+
cccccc
746
+
dddddd]])
747
+
feed('u')
748
+
expect('||')
749
+
end)
709
750
it('stream: Visual mode neither end at the end of a line', function()
710
751
feed('i|xxx<CR>xxx|<Esc>hvhk')
711
752
nvim('paste', 'aaaaaa', false, 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