mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	fix(paste): wrong '[ mark after pasting a big string (streamed chunks) #33025
Problem
Pasting a big string ("streamed paste" with multiple chunks) sets the '[
mark to the edit from the last chunk, instead of the start of the paste.
Solution:
Set the '[ mark where the paste started, not where the last chunk was
inserted.
Note: `startpos == nil` is not equal to `phase == 1` because there may
be some empty chunks pasted which won't arrive here (returned at code
before).
			
			
This commit is contained in:
		| @@ -213,7 +213,7 @@ end | ||||
| vim.inspect = vim.inspect | ||||
|  | ||||
| do | ||||
|   local tdots, tick, got_line1, undo_started, trailing_nl = 0, 0, false, false, false | ||||
|   local startpos, tdots, tick, got_line1, undo_started, trailing_nl = nil, 0, 0, false, false, false | ||||
|  | ||||
|   --- Paste handler, invoked by |nvim_paste()|. | ||||
|   --- | ||||
| @@ -328,7 +328,13 @@ do | ||||
|       -- message when there are zero dots. | ||||
|       vim.api.nvim_command(('echo "%s"'):format(dots)) | ||||
|     end | ||||
|     if startpos == nil then | ||||
|       startpos = vim.fn.getpos("'[") | ||||
|     else | ||||
|       vim.fn.setpos("'[", startpos) | ||||
|     end | ||||
|     if is_last_chunk then | ||||
|       startpos = nil | ||||
|       vim.api.nvim_command('redraw' .. (tick > 1 and '|echo ""' or '')) | ||||
|     end | ||||
|     return true -- Paste will not continue if not returning `true`. | ||||
|   | ||||
| @@ -853,6 +853,39 @@ describe('API', function() | ||||
|         feed('u') -- Undo. | ||||
|         expect(expected1) | ||||
|       end) | ||||
|       it("stream: multiple chunks sets correct '[ mark", function() | ||||
|         -- Pastes single chunk | ||||
|         api.nvim_paste('aaaaaa\n', true, -1) | ||||
|         eq({ 0, 1, 1, 0 }, fn.getpos("'[")) | ||||
|         -- Pastes an empty chunk | ||||
|         api.nvim_paste('', true, -1) | ||||
|         eq({ 0, 2, 1, 0 }, fn.getpos("'[")) | ||||
|         -- Pastes some chunks on empty line | ||||
|         api.nvim_paste('1/chunk 1 (start)\n', true, 1) | ||||
|         eq({ 0, 2, 1, 0 }, fn.getpos("'[")) | ||||
|         api.nvim_paste('1/chunk 2\n', true, 2) | ||||
|         eq({ 0, 2, 1, 0 }, fn.getpos("'[")) | ||||
|         api.nvim_paste('1/chunk 3 (end)\n', true, 3) | ||||
|         eq({ 0, 2, 1, 0 }, fn.getpos("'[")) | ||||
|         -- Pastes some chunks on non-empty line | ||||
|         api.nvim_paste('aaaaaa', true, -1) | ||||
|         eq({ 0, 5, 1, 0 }, fn.getpos("'[")) | ||||
|         api.nvim_paste('bbbbbb', true, 1) | ||||
|         eq({ 0, 5, 7, 0 }, fn.getpos("'[")) | ||||
|         api.nvim_paste('cccccc', true, 2) | ||||
|         eq({ 0, 5, 7, 0 }, fn.getpos("'[")) | ||||
|         api.nvim_paste('dddddd\n', true, 3) | ||||
|         eq({ 0, 5, 7, 0 }, fn.getpos("'[")) | ||||
|         -- Pastes some empty chunks between non-empty chunks | ||||
|         api.nvim_paste('', true, 1) | ||||
|         eq({ 0, 5, 7, 0 }, fn.getpos("'[")) | ||||
|         api.nvim_paste('a', true, 2) | ||||
|         eq({ 0, 6, 1, 0 }, fn.getpos("'[")) | ||||
|         api.nvim_paste('', true, 2) | ||||
|         eq({ 0, 6, 1, 0 }, fn.getpos("'[")) | ||||
|         api.nvim_paste('a', true, 3) | ||||
|         eq({ 0, 6, 1, 0 }, fn.getpos("'[")) | ||||
|       end) | ||||
|       it('stream: Insert mode', function() | ||||
|         -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. | ||||
|         feed('afoo<Esc>u') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Au.
					Au.