feat: `actions.close` to clear pending motions before closing
Added extra logic to ensure that actions.close doesn't close Oil if we're in operator pending or visual modes, instead it exits those modes with an <Esc> call and returns early.
This is to improve the UX as I can't be the only one who constantly accidentally closes Oil 😅 When all I wanted to do was clear an unfinished motion or get out of visual mode, but stay in Oil.
P.s. Long term Oil user, and loving life with it!
Hmmm...I would expect that this could be handled by setting the mode of the keymap. What is your current keymap config? What combination of keys are you pressing that winds up with oil closing unexpectedly?
For Oil I've only got this:
keymaps = { ["<Esc>"] = { callback = "actions.close", mode = "n" }, },
But even though that is the case, if you do this:
- Open Oil
- Press Ctrl + V to go into Visual Mode. Or press a single
yto go into Operator Pending mode. - Press Escape
Oil will remain open, but the mode gets changed back to Normal mode. You have to hit Escape again to close Oil. Which feels correct to me.
If you do that again but press Ctrl + C instead of Escape in Step 3, then Oil is instantly closed although the mode was also changed back to Normal mode again.
I use Ctrl + C a lot instead of Esc, so it may be a me problem. But in the context of an Oil buffer, it feels like Ctrl + C should behave like Escape. 🤔
@chrisbellboy I recently made some slight modifications to the default keymaps to put more of them as normal-mode-only. Can you check to see if you have any issues on the latest master?
@stevearc Nice one, thanks! I just tested it, and it's really close but it's a bit buggy at the moment:
The TL;DR is that Ctrl + C now only closes Oil if in normal mode (great). But it can require multiple Ctrl + C presses to clear modes to go back to normal mode when in Visual/Operator Pending modes inside Oil. Which Escape doesn't need.
With Oil open:
- [Bug] If you
Ctrl + Von a single line and thenCtrl + C, Oil now stays open (great), but the Visual mode doesn't get fully cleared. It stays in Visual mode and the operator pending command changes to1. - [Working as expected] If you
Ctrl + Vmultiples lines, then the operator pending command automatically changes to3(or whatever number) and in this situation now hittingCtrl + Cdoes clear it all whilst keeping Oil open.
Similar for operator commands, with Oil open:
- [Bug] If you hit
yand thenCtrl + C, Oil stays open, but theyoperator pending remains active. If you hitCtrl + Ca second time, now the operator gets cleared. - [Working as expected] If you hit
y3and thenCtrl + C, Oil stays open and the operator pending mode gets cleared correctly.
Thanks again for helping with this!
That's odd, I'm not seeing that behavior. For example, if I do y -> <C-c> -> <C-c> oil closes as expected. Can you provide a minimal config (such as the template in the bug report form) that reproduces this?