-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Disable global keybinds when confirmation is active #4284
fix: Disable global keybinds when confirmation is active #4284
Conversation
A question I had about the current implementation: Is there a way to express the idea that Also I have no idea why that windows test failed..... |
Interesting findings. A few thoughts:
|
One potential solution for blocking all global keybindings generically could be something like this: diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 51a1bf2c7..38a03ca45 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -819,6 +819,7 @@ func (gui *Gui) Run(startArgs appTypes.StartArgs) error {
defer gui.g.Close()
g.ErrorHandler = gui.PopupHandler.ErrorHandler
+ g.IsGlobalKeybindingBlockedCallback = func() bool { return gui.helpers.Confirmation.IsPopupPanelFocused() }
// if the deadlock package wants to report a deadlock, we first need to
// close the gui so that we can actually read what it prints.
diff --git a/vendor/github.com/jesseduffield/gocui/gui.go b/vendor/github.com/jesseduffield/gocui/gui.go
index 03d55912a..697a1b50a 100644
--- a/vendor/github.com/jesseduffield/gocui/gui.go
+++ b/vendor/github.com/jesseduffield/gocui/gui.go
@@ -177,6 +177,8 @@ type Gui struct {
ErrorHandler func(error) error
+ IsGlobalKeybindingBlockedCallback func() bool
+
screen tcell.Screen
suspendedMutex sync.Mutex
suspended bool
@@ -1539,6 +1541,9 @@ func (g *Gui) execKeybindings(v *View, ev *GocuiEvent) error {
}
if globalKb != nil {
+ if g.IsGlobalKeybindingBlockedCallback != nil && g.IsGlobalKeybindingBlockedCallback() {
+ return nil
+ }
return g.execKeybinding(v, globalKb)
}
return nil It's rather ugly, but seems to do the job. (But also disables If we don't want this, I'd propose to not spend any more time and energy on a generic solution, and simply add the |
I much prefer blocking the commands over auto-closing the popup, however I also like having 'q' quit the application regardless of whether a popup is shown. What's more, we also have ctrl+c in that global context, and I feel that as a cultural norm, in a terminal application, ctrl+c should quit an application no matter what context you're in (albeit vim is an exception, but it's also renowned for being unintuitive to quit!) Maybe we could find some other way to treat the quit keybindings specially, like putting them in a separate controller (e.g. QuitController), and blocking the GlobalController rather than the global context. |
How bad do you think it would be to simply block all those individual handlers with |
Yeah, I'm fine with that. We rarely add new global keybindings |
2afdc95
to
c0eab10
Compare
Pushed up new version using the guard, and added a line at the bottom of the english intro message that tells them what key to hit. I know the confirm key is visible in the bottom bar, but I find in the default color scheme that doesn't stick out as an obvious next step. And clearly some non-zero number of people not seeing it. |
c0eab10
to
fce3400
Compare
Removed the double-popup test since that is now not allowed behavior. I could rewrite the test to assert that it isn't allowed? Didn't feel necessary to me, but happy to do it if others want. |
Looks awesome, I'm happy to merge in this state. The added text to the startup popup looks fine to me, and removing the test is ok with me too. It would be good if you could bring the PR description up to date, since it is going to be used for the merge commit. |
fce3400
to
0ef3832
Compare
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | patch | `v0.47.1` -> `v0.47.2` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary> ### [`v0.47.2`](https://github.com/jesseduffield/lazygit/releases/tag/v0.47.2) [Compare Source](jesseduffield/lazygit@v0.47.1...v0.47.2) <!-- Release notes generated using configuration in .github/release.yml at v0.47.2 --> Small patch release for you all. This is mainly to fix an issue with v0.47.1 which erroneously re-indented users' lazygit config files on startup. Shout-out to [@​karimkhaleel](https://github.com/karimkhaleel) for his MR with some gnarly yaml-handling code. And a special shout-out to [@​ChrisMcD1](https://github.com/ChrisMcD1) who has been pumping out many great contributions lately. Great to have you aboard. #### What's Changed ##### Enhancements 🔥 - Skip post-checkout hook when discarding changes by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4313 ##### Fixes 🔧 - fix: Disable global keybinds when confirmation is active by [@​ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4284 - Don't rewrite config file unnecessarily when it contains commitPrefixes by [@​ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4311 - Change side panel width calculation to work for larger numbers by [@​ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4287 ##### Maintenance ⚙️ - Fix auto-release schedule by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4308 - Use indentation of 2 when rewriting auto-migrated config file by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4312 - Use refs in jsonschema by [@​karimkhaleel](https://github.com/karimkhaleel) in jesseduffield/lazygit#4309 - Improve release workflow by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4307 - Filter out dev comments from schema by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4319 - Fix release script by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4322 - Fix release script once again by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4323 ##### Docs 📖 - Improve the error message when users have gpg signing turned on by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4296 **Full Changelog**: jesseduffield/lazygit@v0.47.1...v0.47.2 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xODAuMiIsInVwZGF0ZWRJblZlciI6IjM5LjE4MC4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Adds a guard around all global keybinds except for quitting the application when a popup window is active. Users must now confirm, or cancel, the popup prior to taking other action. This fixes #4052, and will also prevent other such confusing cases where popups are created, but never removed.
go generate ./...
)