mirror of
				https://github.com/vim/vim.git
				synced 2025-10-30 09:47:20 -04:00 
			
		
		
		
	patch 9.1.0002: a closing fold expr, may start a new fold
Problem:  a closing fold expression may unexpectedly start a new fold
          when it should end a fold
          (reported by Shota Nozaki)
Solution: if a fold hasn't started yet, do not immediately
          start a new fold with level 1
          (Shota Nozaki)
fixes: #12768
closes: #13748
Signed-off-by: Shota Nozaki <emonkak@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
			
			
This commit is contained in:
		
				
					committed by
					
						 Christian Brabandt
						Christian Brabandt
					
				
			
			
				
	
			
			
			
						parent
						
							bf44b69d1f
						
					
				
				
					commit
					0689b87059
				
			| @@ -3362,7 +3362,9 @@ foldlevelExpr(fline_T *flp) | |||||||
| 		  break; | 		  break; | ||||||
|  |  | ||||||
| 	// "<1", "<2", .. : end a fold with a certain level | 	// "<1", "<2", .. : end a fold with a certain level | ||||||
| 	case '<': flp->lvl_next = n - 1; | 	case '<': // To prevent an unexpected start of a new fold, the next | ||||||
|  | 		  // level must not exceed the level of the current fold. | ||||||
|  | 		  flp->lvl_next = MIN(flp->lvl, n - 1); | ||||||
| 		  flp->end = n; | 		  flp->end = n; | ||||||
| 		  break; | 		  break; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1778,4 +1778,17 @@ func Test_foldexpr_return_empty_string() | |||||||
|  |  | ||||||
|   bwipe! |   bwipe! | ||||||
| endfunc | endfunc | ||||||
|  |  | ||||||
|  | " Make sure that when ending a fold that hasn't been started, it does not | ||||||
|  | " start a new fold. | ||||||
|  | func Test_foldexpr_end_fold() | ||||||
|  |   new | ||||||
|  |   setlocal foldmethod=expr | ||||||
|  |   let &l:foldexpr = 'v:lnum == 2 ? "<2" : "="' | ||||||
|  |   call setline(1, range(1, 3)) | ||||||
|  |   redraw | ||||||
|  |   call assert_equal([0, 0, 0], range(1, 3)->map('foldlevel(v:val)')) | ||||||
|  |  | ||||||
|  |   bwipe! | ||||||
|  | endfunc | ||||||
|  |  | ||||||
|   | |||||||
| @@ -704,6 +704,8 @@ static char *(features[]) = | |||||||
|  |  | ||||||
| static int included_patches[] = | static int included_patches[] = | ||||||
| {   /* Add new patch number below this line */ | {   /* Add new patch number below this line */ | ||||||
|  | /**/ | ||||||
|  |     2, | ||||||
| /**/ | /**/ | ||||||
|     1, |     1, | ||||||
| /**/ | /**/ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user