mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	fix(api): fix set_lines viewport adjustment, but this time good
fixes #27720
This commit is contained in:
		| @@ -1243,11 +1243,11 @@ void mark_adjust_buf(buf_T *buf, linenr_T line1, linenr_T line2, linenr_T amount | |||||||
|       if (win != curwin || by_api) { |       if (win != curwin || by_api) { | ||||||
|         if (win->w_topline >= line1 && win->w_topline <= line2) { |         if (win->w_topline >= line1 && win->w_topline <= line2) { | ||||||
|           if (amount == MAXLNUM) {                  // topline is deleted |           if (amount == MAXLNUM) {                  // topline is deleted | ||||||
|             if (line1 <= 1) { |             if (by_api && amount_after > line1 - line2 - 1) { | ||||||
|               win->w_topline = 1; |               // api: if the deleted region was replaced with new contents, topline will | ||||||
|  |               // get adjusted later as an effect of the adjusted cursor in fix_cursor() | ||||||
|             } else { |             } else { | ||||||
|               // api: if the deleted region was replaced with new contents, display that |               win->w_topline = MAX(line1 - 1, 1); | ||||||
|               win->w_topline = (by_api && amount_after > line1 - line2 - 1) ? line1 : line1 - 1; |  | ||||||
|             } |             } | ||||||
|           } else if (win->w_topline > line1) { |           } else if (win->w_topline > line1) { | ||||||
|             // keep topline on the same line, unless inserting just |             // keep topline on the same line, unless inserting just | ||||||
|   | |||||||
| @@ -150,16 +150,16 @@ describe('api/buf', function() | |||||||
|       ]], |       ]], | ||||||
|       } |       } | ||||||
|  |  | ||||||
|  |       lines[5] = 'boogalo 5' | ||||||
|       api.nvim_buf_set_lines(buf, 0, -1, true, lines) |       api.nvim_buf_set_lines(buf, 0, -1, true, lines) | ||||||
|       screen:expect { |       screen:expect { | ||||||
|         grid = [[ |         grid = [[ | ||||||
|         ^                    | |         ^                    | | ||||||
|         {1:~                   }|*4 |         {1:~                   }|*4 | ||||||
|         {2:[No Name]           }| |         {2:[No Name]           }| | ||||||
|         line3               | |         boogalo 5           | | ||||||
|         line4               | |  | ||||||
|         line5               | |  | ||||||
|         line6               | |         line6               | | ||||||
|  |         {1:~                   }|*2 | ||||||
|         {3:[No Name] [+]       }| |         {3:[No Name] [+]       }| | ||||||
|                             | |                             | | ||||||
|       ]], |       ]], | ||||||
| @@ -171,10 +171,9 @@ describe('api/buf', function() | |||||||
|                             | |                             | | ||||||
|         {1:~                   }|*4 |         {1:~                   }|*4 | ||||||
|         {3:[No Name]           }| |         {3:[No Name]           }| | ||||||
|         line3               | |         boogalo 5           | | ||||||
|         line4               | |  | ||||||
|         line5               | |  | ||||||
|         ^line6               | |         ^line6               | | ||||||
|  |         {1:~                   }|*2 | ||||||
|         {2:[No Name] [+]       }| |         {2:[No Name] [+]       }| | ||||||
|                             | |                             | | ||||||
|       ]], |       ]], | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 bfredl
					bfredl