mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	fix(api): alloc and draw cursor window in nvim__redraw
Problem:  Unable to move cursor to recently opened window.
Solution: Make sure uninitialized window is drawn before trying to move
          the cursor to it.
			
			
This commit is contained in:
		| @@ -2393,10 +2393,6 @@ void nvim__redraw(Dict(redraw) *opts, Error *err) | |||||||
|     redraw_buf_range_later(rbuf, first, last); |     redraw_buf_range_later(rbuf, first, last); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   if (opts->cursor) { |  | ||||||
|     setcursor_mayforce(win ? win : curwin, true); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   bool flush = opts->flush; |   bool flush = opts->flush; | ||||||
|   if (opts->tabline) { |   if (opts->tabline) { | ||||||
|     // Flush later in case tabline was just hidden or shown for the first time. |     // Flush later in case tabline was just hidden or shown for the first time. | ||||||
| @@ -2423,11 +2419,22 @@ void nvim__redraw(Dict(redraw) *opts, Error *err) | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Flush pending screen updates if "flush" or "clear" is true, or when |   win_T *cwin = win ? win : curwin; | ||||||
|   // redrawing a status component may have changed the grid dimensions. |   // Allow moving cursor to recently opened window and make sure it is drawn #28868. | ||||||
|  |   if (opts->cursor && (!cwin->w_grid.target || !cwin->w_grid.target->valid)) { | ||||||
|  |     flush = true; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   // Redraw pending screen updates when explicitly requested or when determined | ||||||
|  |   // that it is necessary to properly draw other requested components. | ||||||
|   if (flush && !cmdpreview) { |   if (flush && !cmdpreview) { | ||||||
|     update_screen(); |     update_screen(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   if (opts->cursor) { | ||||||
|  |     setcursor_mayforce(cwin, true); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   ui_flush(); |   ui_flush(); | ||||||
|  |  | ||||||
|   RedrawingDisabled = save_rd; |   RedrawingDisabled = save_rd; | ||||||
|   | |||||||
| @@ -4969,12 +4969,29 @@ describe('API', function() | |||||||
|   it('nvim__redraw', function() |   it('nvim__redraw', function() | ||||||
|     local screen = Screen.new(60, 5) |     local screen = Screen.new(60, 5) | ||||||
|     screen:attach() |     screen:attach() | ||||||
|     local win = api.nvim_get_current_win() |  | ||||||
|     eq('at least one action required', pcall_err(api.nvim__redraw, {})) |     eq('at least one action required', pcall_err(api.nvim__redraw, {})) | ||||||
|     eq('at least one action required', pcall_err(api.nvim__redraw, { buf = 0 })) |     eq('at least one action required', pcall_err(api.nvim__redraw, { buf = 0 })) | ||||||
|     eq('at least one action required', pcall_err(api.nvim__redraw, { win = 0 })) |     eq('at least one action required', pcall_err(api.nvim__redraw, { win = 0 })) | ||||||
|     eq("cannot use both 'buf' and 'win'", pcall_err(api.nvim__redraw, { buf = 0, win = 0 })) |     eq("cannot use both 'buf' and 'win'", pcall_err(api.nvim__redraw, { buf = 0, win = 0 })) | ||||||
|  |     local win = api.nvim_get_current_win() | ||||||
|  |     -- Can move cursor to recently opened window and window is flushed #28868 | ||||||
|     feed(':echo getchar()<CR>') |     feed(':echo getchar()<CR>') | ||||||
|  |     local newwin = api.nvim_open_win(0, false, { | ||||||
|  |       relative = 'editor', | ||||||
|  |       width = 1, | ||||||
|  |       height = 1, | ||||||
|  |       row = 1, | ||||||
|  |       col = 10, | ||||||
|  |     }) | ||||||
|  |     api.nvim__redraw({ win = newwin, cursor = true }) | ||||||
|  |     screen:expect({ | ||||||
|  |       grid = [[ | ||||||
|  |                                                                     | | ||||||
|  |         {1:~         }{4:^ }{1:                                                 }| | ||||||
|  |         {1:~                                                           }|*2 | ||||||
|  |         :echo getchar()                                             | | ||||||
|  |       ]], | ||||||
|  |     }) | ||||||
|     fn.setline(1, 'foobar') |     fn.setline(1, 'foobar') | ||||||
|     command('vnew') |     command('vnew') | ||||||
|     fn.setline(1, 'foobaz') |     fn.setline(1, 'foobaz') | ||||||
| @@ -4983,11 +5000,13 @@ describe('API', function() | |||||||
|     screen:expect({ |     screen:expect({ | ||||||
|       grid = [[ |       grid = [[ | ||||||
|         foobaz                        │foobar                       | |         foobaz                        │foobar                       | | ||||||
|         {1:~                             }│{1:~                            }|*2 |         {1:~         }{4:^f}{1:                   }│{1:~                            }| | ||||||
|  |         {1:~                             }│{1:~                            }| | ||||||
|         {3:[No Name] [+]                  }{2:[No Name] [+]                }| |         {3:[No Name] [+]                  }{2:[No Name] [+]                }| | ||||||
|         ^:echo getchar()                                             | |         :echo getchar()                                             | | ||||||
|       ]], |       ]], | ||||||
|     }) |     }) | ||||||
|  |     api.nvim_win_close(newwin, true) | ||||||
|     -- Can update the grid cursor position #20793 |     -- Can update the grid cursor position #20793 | ||||||
|     api.nvim__redraw({ cursor = true }) |     api.nvim__redraw({ cursor = true }) | ||||||
|     screen:expect({ |     screen:expect({ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Luuk van Baal
					Luuk van Baal