mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	fix(treesitter): don't open fold when o/O adds a line below #28709
Problem: `o`-ing on a folded line opens the fold, because the new line gets the fold level from the above line (level '='), which extends the fold to the new line. `O` has a similar problem when run on the line below a fold. Solution: Use -1 for the added line to get the lower level from the above/below line.
This commit is contained in:
		| @@ -87,7 +87,7 @@ end | |||||||
| ---@param srow integer | ---@param srow integer | ||||||
| ---@param erow integer 0-indexed, exclusive | ---@param erow integer 0-indexed, exclusive | ||||||
| function FoldInfo:add_range(srow, erow) | function FoldInfo:add_range(srow, erow) | ||||||
|   list_insert(self.levels, srow + 1, erow, '=') |   list_insert(self.levels, srow + 1, erow, -1) | ||||||
|   list_insert(self.levels0, srow + 1, erow, -1) |   list_insert(self.levels0, srow + 1, erow, -1) | ||||||
| end | end | ||||||
|  |  | ||||||
|   | |||||||
| @@ -646,6 +646,67 @@ import hello]]) | |||||||
|     } |     } | ||||||
|   end) |   end) | ||||||
|  |  | ||||||
|  |   it('does not extend closed fold with `o`/`O`', function() | ||||||
|  |     local screen = Screen.new(60, 24) | ||||||
|  |     screen:attach() | ||||||
|  |  | ||||||
|  |     insert(test_text) | ||||||
|  |     parse('c') | ||||||
|  |     command([[set foldmethod=expr foldexpr=v:lua.vim.treesitter.foldexpr() foldcolumn=1]]) | ||||||
|  |  | ||||||
|  |     feed('5ggzco') | ||||||
|  |     screen:expect({ | ||||||
|  |       grid = [[ | ||||||
|  |         {7:-}void ui_refresh(void)                                      | | ||||||
|  |         {7:│}{                                                          | | ||||||
|  |         {7:│}  int width = INT_MAX, height = INT_MAX;                   | | ||||||
|  |         {7:│}  bool ext_widgets[kUIExtCount];                           | | ||||||
|  |         {7:+}{13:+---  3 lines: for (UIExtension i = 0; (int)i < kUIExtCount}| | ||||||
|  |         {7:│}^                                                           | | ||||||
|  |         {7:│}                                                           | | ||||||
|  |         {7:│}  bool inclusive = ui_override();                          | | ||||||
|  |         {7:-}  for (size_t i = 0; i < ui_count; i++) {                  | | ||||||
|  |         {7:2}    UI *ui = uis[i];                                       | | ||||||
|  |         {7:2}    width = MIN(ui->width, width);                         | | ||||||
|  |         {7:2}    height = MIN(ui->height, height);                      | | ||||||
|  |         {7:2}    foo = BAR(ui->bazaar, bazaar);                         | | ||||||
|  |         {7:-}    for (UIExtension j = 0; (int)j < kUIExtCount; j++) {   | | ||||||
|  |         {7:3}      ext_widgets[j] &= (ui->ui_ext[j] || inclusive);      | | ||||||
|  |         {7:3}    }                                                      | | ||||||
|  |         {7:2}  }                                                        | | ||||||
|  |         {7:│}}                                                          | | ||||||
|  |         {1:~                                                           }|*5 | ||||||
|  |         {5:-- INSERT --}                                                | | ||||||
|  |       ]], | ||||||
|  |     }) | ||||||
|  |  | ||||||
|  |     feed('<Esc>O') | ||||||
|  |     screen:expect({ | ||||||
|  |       grid = [[ | ||||||
|  |         {7:-}void ui_refresh(void)                                      | | ||||||
|  |         {7:│}{                                                          | | ||||||
|  |         {7:│}  int width = INT_MAX, height = INT_MAX;                   | | ||||||
|  |         {7:│}  bool ext_widgets[kUIExtCount];                           | | ||||||
|  |         {7:+}{13:+---  3 lines: for (UIExtension i = 0; (int)i < kUIExtCount}| | ||||||
|  |         {7:│}^                                                           | | ||||||
|  |         {7:│}                                                           |*2 | ||||||
|  |         {7:│}  bool inclusive = ui_override();                          | | ||||||
|  |         {7:-}  for (size_t i = 0; i < ui_count; i++) {                  | | ||||||
|  |         {7:2}    UI *ui = uis[i];                                       | | ||||||
|  |         {7:2}    width = MIN(ui->width, width);                         | | ||||||
|  |         {7:2}    height = MIN(ui->height, height);                      | | ||||||
|  |         {7:2}    foo = BAR(ui->bazaar, bazaar);                         | | ||||||
|  |         {7:-}    for (UIExtension j = 0; (int)j < kUIExtCount; j++) {   | | ||||||
|  |         {7:3}      ext_widgets[j] &= (ui->ui_ext[j] || inclusive);      | | ||||||
|  |         {7:3}    }                                                      | | ||||||
|  |         {7:2}  }                                                        | | ||||||
|  |         {7:│}}                                                          | | ||||||
|  |         {1:~                                                           }|*4 | ||||||
|  |         {5:-- INSERT --}                                                | | ||||||
|  |       ]], | ||||||
|  |     }) | ||||||
|  |   end) | ||||||
|  |  | ||||||
|   it("doesn't open folds that are not touched", function() |   it("doesn't open folds that are not touched", function() | ||||||
|     local screen = Screen.new(40, 8) |     local screen = Screen.new(40, 8) | ||||||
|     screen:set_default_attr_ids({ |     screen:set_default_attr_ids({ | ||||||
| @@ -674,7 +735,7 @@ t2]]) | |||||||
|       grid = [[ |       grid = [[ | ||||||
|       {1:-}# h1                                   | |       {1:-}# h1                                   | | ||||||
|       {1:│}t1                                     | |       {1:│}t1                                     | | ||||||
|       {1:│}^                                       | |       {1:-}^                                       | | ||||||
|       {1:+}{2:+--  2 lines: # h2·····················}| |       {1:+}{2:+--  2 lines: # h2·····················}| | ||||||
|       {3:~                                       }|*3 |       {3:~                                       }|*3 | ||||||
|       {4:-- INSERT --}                            | |       {4:-- INSERT --}                            | | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jaehwang Jung
					Jaehwang Jung