AndrewRadev / undoquit.vim

Undo a :quit -- reopen the last window you closed
https://www.vim.org/scripts/script.php?script_id=5725
MIT License
64 stars 4 forks source link

Split restores to wrong side #16

Open durka opened 11 months ago

durka commented 11 months ago

The plugin partially works for me, but windows are not getting restored to the same positions. This seems to be independent of the splitright setting.

STR

  1. Open a file nvim a.txt
  2. Split :vsp
  3. Open another file in the split :e b.txt
  4. Close the window :q
  5. Restore the window :Undoquit

Expected: window restores as it was

Actual: window restore, but swapped with the other split

I'm also seeing issues such as: :vsp, then :sp, if I close the original window (the one that wasn't split by :sp) and then restore, it re-splits horizontally instead of vertically.

AndrewRadev commented 11 months ago

Wow, I think I'd actually swapped around the vertical split positioning by accident 😅. I swapped them around and vertical splits should now be restored in their correct position. I don't use vertical splits often myself, but I really should have tested this out properly.

I'm also seeing issues such as: :vsp, then :sp, if I close the original window (the one that wasn't split by :sp) and then restore, it re-splits horizontally instead of vertically.

Hm, I think the reason is the plugin looks for a neighboring buffer to reopen a window from, and it should be looking for a window instead, so it can handle duplicates. Since a :split without an argument will open a new window backed with the same buffer. I'll see about getting that to work.

AndrewRadev commented 11 months ago

I think I managed to push a fix for this particular scenario as well. Could you try it out and let me know? I did find some other cases that might be problematic, I'll explore them separately.

durka commented 11 months ago

I'm still seeing issues when mixing vertical and horizontal splits, I realize this may be hard to fix.

  1. Open vim, I have one window
| a |
  1. Split vertically
| a | b |
  1. Split horizontally
|   | b |
| a | - |
|   | c |

Now if I close a and try to restore it, it splits c instead of bringing back the left window.

AndrewRadev commented 11 months ago

Yeah, there's a few tricky scenarios. I think the best approach is to try to find the "best" neighbour to restore from, which would be a horizontal with the same height or a vertical with the same width. I'll see what I can do, though it might take a bit of time to get around to it.

AndrewRadev commented 9 months ago

@durka Sorry it took a while, I believe I've fixed this case as well:

Now if I close a and try to restore it, it splits c instead of bringing back the left window.

As I explained above, I tried to find the "best" window to restore from to maintain the layout. There is still one case that won't work right, but I can't think of a way to implement it, and I think it ought to be rare enough to not be that big of a problem.

If you have the time, I'd appreciate if you updated and tried out your cases to confirm if I've gotten it working or if there's another issue.