mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 09:44:31 +00:00 
			
		
		
		
	API/buffer-updates: always detach on buf-reload #9643
Independently of the 'undoreload' option and the length of the file. closes #9642 closes #9643
This commit is contained in:
		
				
					committed by
					
						
						Justin M. Keyes
					
				
			
			
				
	
			
			
			
						parent
						
							6cd4ff2ab7
						
					
				
				
					commit
					018e0d5a19
				
			@@ -591,7 +591,8 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
 | 
				
			|||||||
  /* Change directories when the 'acd' option is set. */
 | 
					  /* Change directories when the 'acd' option is set. */
 | 
				
			||||||
  do_autochdir();
 | 
					  do_autochdir();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // disable buffer updates for the current buffer
 | 
					  // Disable buffer-updates for the current buffer.
 | 
				
			||||||
 | 
					  // No need to check `unload_buf`: in that case the function returned above.
 | 
				
			||||||
  buf_updates_unregister_all(buf);
 | 
					  buf_updates_unregister_all(buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /*
 | 
					  /*
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2476,8 +2476,8 @@ int do_ecmd(
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    set_bufref(&bufref, buf);
 | 
					    set_bufref(&bufref, buf);
 | 
				
			||||||
    if (p_ur < 0 || curbuf->b_ml.ml_line_count <= p_ur) {
 | 
					    if (p_ur < 0 || curbuf->b_ml.ml_line_count <= p_ur) {
 | 
				
			||||||
      /* Save all the text, so that the reload can be undone.
 | 
					      // Save all the text, so that the reload can be undone.
 | 
				
			||||||
       * Sync first so that this is a separate undo-able action. */
 | 
					      // Sync first so that this is a separate undo-able action.
 | 
				
			||||||
      u_sync(false);
 | 
					      u_sync(false);
 | 
				
			||||||
      if (u_savecommon(0, curbuf->b_ml.ml_line_count + 1, 0, true)
 | 
					      if (u_savecommon(0, curbuf->b_ml.ml_line_count + 1, 0, true)
 | 
				
			||||||
          == FAIL) {
 | 
					          == FAIL) {
 | 
				
			||||||
@@ -2491,6 +2491,7 @@ int do_ecmd(
 | 
				
			|||||||
      // Tell readfile() not to clear or reload undo info.
 | 
					      // Tell readfile() not to clear or reload undo info.
 | 
				
			||||||
      readfile_flags = READ_KEEP_UNDO;
 | 
					      readfile_flags = READ_KEEP_UNDO;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
 | 
					      buf_updates_unregister_all(curbuf);
 | 
				
			||||||
      buf_freeall(curbuf, 0);  // Free all things for buffer.
 | 
					      buf_freeall(curbuf, 0);  // Free all things for buffer.
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // If autocommands deleted the buffer we were going to re-edit, give
 | 
					    // If autocommands deleted the buffer we were going to re-edit, give
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -678,6 +678,32 @@ describe('API: buffer events:', function()
 | 
				
			|||||||
    expectn('Hello There', {})
 | 
					    expectn('Hello There', {})
 | 
				
			||||||
  end)
 | 
					  end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  it(':edit! (reload) causes detach #9642', function()
 | 
				
			||||||
 | 
					    local b, tick = editoriginal(true, {'AAA', 'BBB'})
 | 
				
			||||||
 | 
					    command('set undoreload=1')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    command('normal! x')
 | 
				
			||||||
 | 
					    tick = tick + 1
 | 
				
			||||||
 | 
					    expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    command('edit!')
 | 
				
			||||||
 | 
					    expectn('nvim_buf_detach_event', {b})
 | 
				
			||||||
 | 
					  end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  it(':enew! does not detach hidden buffer', function()
 | 
				
			||||||
 | 
					    local b, tick = editoriginal(true, {'AAA', 'BBB'})
 | 
				
			||||||
 | 
					    local channel = nvim('get_api_info')[1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    command('set undoreload=1 hidden')
 | 
				
			||||||
 | 
					    command('normal! x')
 | 
				
			||||||
 | 
					    tick = tick + 1
 | 
				
			||||||
 | 
					    expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    command('enew!')
 | 
				
			||||||
 | 
					    eval('rpcnotify('..channel..', "Hello There")')
 | 
				
			||||||
 | 
					    expectn('Hello There', {})
 | 
				
			||||||
 | 
					  end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it('stays attached if the buffer is hidden', function()
 | 
					  it('stays attached if the buffer is hidden', function()
 | 
				
			||||||
    local b, tick = editoriginal(true, {'AAA'})
 | 
					    local b, tick = editoriginal(true, {'AAA'})
 | 
				
			||||||
    local channel = nvim('get_api_info')[1]
 | 
					    local channel = nvim('get_api_info')[1]
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user