undoquit.vim icon indicating copy to clipboard operation
undoquit.vim copied to clipboard

Split restores to wrong side

Open durka opened this issue 1 year ago • 5 comments

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.

durka avatar Nov 21 '23 19:11 durka

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 avatar Nov 21 '23 22:11 AndrewRadev

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.

AndrewRadev avatar Nov 24 '23 17:11 AndrewRadev

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.

durka avatar Nov 27 '23 21:11 durka

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 avatar Dec 10 '23 17:12 AndrewRadev

@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.

AndrewRadev avatar Feb 06 '24 20:02 AndrewRadev