zefei / vim-wintabs

Modern buffer manager for Vim
MIT License
325 stars 25 forks source link

Bug when WintabsClose on unsaved buffer that is open in another window. #23

Closed jordwalke closed 6 years ago

jordwalke commented 6 years ago
  1. :e newFile.txt
  2. vsplit
  3. Edit the split file (see changes appear in the other window too).
  4. Try to :WintabsClose.
  5. Watch it not succeed in closing it since it's open in another window. It is not in a broken state.
jordwalke commented 6 years ago

config:

set hidden
let g:tabSystem = 'wintabs'
let g:wintabs_autoclose=1
let g:wintabs_autoclose_vim=1
let g:wintabs_switchbuf='useopen,usetab'
let g:wintabs_ui_modified*
let g:wintabs_ui_active_higroup = 'TabLineSel'
jordwalke commented 6 years ago

let g:wintabs_autoclose=2 seems to work but let g:wintabs_autoclose=1 doesn't.

zefei commented 6 years ago

Should be fixed in the latest commit. This is a very edge case that I can't fix completely due to how confirm/hidden interact with each other. The new behavior is that you can close a modified buffer if it's currently shown in another window or vimtab, with no confirm dialog. I think this behavior is less broken than not closing with no error/confirm.

Let me know if this is fixed for you, and if it feels "more correct" than before.

jordwalke commented 6 years ago

I'll check it out: For posterity here's the workaround I created. You might find it useful to handle some edge cases - I basically just detect whether or not there are unsaved changes before even calling wintabs#close(). The problem is that in this workaround, if you have the file open in another split, it resets the modifications to the files to the last saved version even in the other split. I think an improvement would be to first see if the file is open anywhere else before resetting, or before even asking if they want to save changes upon 'close'.

function MaybeCloseWinTab()
  if &modified
    let choice = confirm("File has unsaved changes!", "&Save\n&Cancel\n&Don't Save", 2)
    if choice == 3
      " Don't save: Reset the file then call WintabsClose
      execute "silent earlier 1f"
      call wintabs#close()
    elseif choice == 2 || choice == 0
      " Cancel
    elseif choice == 1
      execute ":w"
      call wintabs#close()
    endif
  else
    call wintabs#close()
  endif
endfunction
zefei commented 6 years ago

Closing this as I implemented your suggestion.