Skip to content

Commit a0fc0bf

Browse files
authored
fix: allow to unset global hotkeys (#10)
1 parent f2e3f1e commit a0fc0bf

3 files changed

Lines changed: 49 additions & 25 deletions

File tree

cmd/govim/main.go

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,19 @@ func (a *App) Run() error {
149149
return fmt.Errorf("failed to register hotkeys: %w", err)
150150
}
151151

152-
a.logger.Info("GoVim is running. Press hotkeys to activate modes.")
152+
a.logger.Info("GoVim is running")
153153
fmt.Println("✓ GoVim is running")
154-
fmt.Printf(" Hint mode (direct): %s\n", a.config.Hotkeys.ActivateHintMode)
155-
fmt.Printf(" Hint mode (with actions): %s\n", a.config.Hotkeys.ActivateHintModeWithActions)
156-
fmt.Printf(" Scroll mode: %s\n", a.config.Hotkeys.ActivateScrollMode)
157-
fmt.Printf(" Exit mode: Escape (hardcoded)\n")
154+
155+
// Print configured hotkeys
156+
if key := strings.TrimSpace(a.config.Hotkeys.ActivateHintMode); key != "" {
157+
fmt.Printf(" Hint mode (direct): %s\n", key)
158+
}
159+
if key := strings.TrimSpace(a.config.Hotkeys.ActivateHintModeWithActions); key != "" {
160+
fmt.Printf(" Hint mode (with actions): %s\n", key)
161+
}
162+
if key := strings.TrimSpace(a.config.Hotkeys.ActivateScrollMode); key != "" {
163+
fmt.Printf(" Scroll mode: %s\n", key)
164+
}
158165

159166
// Wait for interrupt signal with force-quit support
160167
sigChan := make(chan os.Signal, 1)
@@ -196,31 +203,41 @@ func (a *App) Run() error {
196203
// registerHotkeys registers all global hotkeys
197204
func (a *App) registerHotkeys() error {
198205
// Hint mode hotkey (direct click)
199-
a.logger.Info("Registering hint mode hotkey", zap.String("key", a.config.Hotkeys.ActivateHintMode))
200-
if _, err := a.hotkeyManager.Register(a.config.Hotkeys.ActivateHintMode, func() {
201-
a.activateHintMode(false)
202-
}); err != nil {
203-
return fmt.Errorf("failed to register hint mode hotkey: %w", err)
206+
if key := strings.TrimSpace(a.config.Hotkeys.ActivateHintMode); key != "" {
207+
a.logger.Info("Registering hint mode hotkey", zap.String("key", key))
208+
if _, err := a.hotkeyManager.Register(key, func() {
209+
a.activateHintMode(false)
210+
}); err != nil {
211+
return fmt.Errorf("failed to register hint mode hotkey: %w", err)
212+
}
204213
}
205214

206215
// Hint mode with actions hotkey
207-
a.logger.Info("Registering hint mode with actions hotkey", zap.String("key", a.config.Hotkeys.ActivateHintModeWithActions))
208-
if _, err := a.hotkeyManager.Register(a.config.Hotkeys.ActivateHintModeWithActions, func() {
209-
a.activateHintMode(true)
210-
}); err != nil {
211-
return fmt.Errorf("failed to register hint mode with actions hotkey: %w", err)
216+
if key := strings.TrimSpace(a.config.Hotkeys.ActivateHintModeWithActions); key != "" {
217+
a.logger.Info("Registering hint mode with actions hotkey", zap.String("key", key))
218+
if _, err := a.hotkeyManager.Register(key, func() {
219+
a.activateHintMode(true)
220+
}); err != nil {
221+
return fmt.Errorf("failed to register hint mode with actions hotkey: %w", err)
222+
}
212223
}
213224

214225
// Scroll mode hotkey
215-
if _, err := a.hotkeyManager.Register(a.config.Hotkeys.ActivateScrollMode, a.activateScrollMode); err != nil {
216-
return fmt.Errorf("failed to register scroll mode hotkey: %w", err)
226+
if key := strings.TrimSpace(a.config.Hotkeys.ActivateScrollMode); key != "" {
227+
a.logger.Info("Registering scroll mode hotkey", zap.String("key", key))
228+
if _, err := a.hotkeyManager.Register(key, a.activateScrollMode); err != nil {
229+
return fmt.Errorf("failed to register scroll mode hotkey: %w", err)
230+
}
217231
}
218232

219233
// Note: Escape key for exiting modes is hardcoded in handleKeyPress, not registered as global hotkey
220234

221235
// Reload config hotkey
222-
if _, err := a.hotkeyManager.Register(a.config.Hotkeys.ReloadConfig, a.reloadConfig); err != nil {
223-
a.logger.Warn("Failed to register reload config hotkey", zap.Error(err))
236+
if key := strings.TrimSpace(a.config.Hotkeys.ReloadConfig); key != "" {
237+
a.logger.Info("Registering reload config hotkey", zap.String("key", key))
238+
if _, err := a.hotkeyManager.Register(key, a.reloadConfig); err != nil {
239+
a.logger.Warn("Failed to register reload config hotkey", zap.Error(err))
240+
}
224241
}
225242

226243
return nil

configs/default-config.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# GoVim Configuration
2-
# Copy to: ~/Library/Application Support/govim/config.toml
2+
# Copy to:
3+
# - macOS: ~/Library/Application Support/govim/config.toml
4+
# - XDG: ~/.config/govim/config.toml
5+
# - Custom location: specify with --config flag
36

47
[general]
58
hint_characters = "asdfghjkl"
@@ -66,7 +69,11 @@ additional_bundles = [
6669
]
6770

6871
[hotkeys]
72+
# all hotkeys can be disabled by either setting the key to "" or just commenting it out
73+
74+
# Activate hint mode (direct click)
6975
activate_hint_mode = "Cmd+Shift+Space"
76+
7077
# Activate hint mode with action selection (choose click type after typing hint)
7178
activate_hint_mode_with_actions = "Cmd+Shift+A"
7279

internal/config/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ func DefaultConfig() *Config {
123123
},
124124
},
125125
Hotkeys: HotkeysConfig{
126-
ActivateHintMode: "Cmd+Shift+Space",
127-
ActivateHintModeWithActions: "Cmd+Shift+A",
128-
ActivateScrollMode: "Cmd+Shift+J",
129-
ReloadConfig: "Cmd+Shift+R",
126+
ActivateHintMode: "",
127+
ActivateHintModeWithActions: "",
128+
ActivateScrollMode: "",
129+
ReloadConfig: "",
130130
},
131131
Scroll: ScrollConfig{
132132
ScrollSpeed: 50,
@@ -461,7 +461,7 @@ func (c *Config) Save(path string) error {
461461
// validateHotkey validates a hotkey string format
462462
func validateHotkey(hotkey, fieldName string) error {
463463
if strings.TrimSpace(hotkey) == "" {
464-
return fmt.Errorf("%s cannot be empty", fieldName)
464+
return nil // Allow empty hotkey to disable the action
465465
}
466466

467467
// Hotkey format: [Modifier+]*Key

0 commit comments

Comments
 (0)