fix(input): fix off-by-one in dead key range, extract test config helper
Fix IsTextInputKey dead key upper bound: 0xfe8b -> 0xfe8c to include GDK_KEY_dead_greek. Extract newTestConfig() helper to reduce test boilerplate across 5 test functions.
- commit
- 51b8f8a25fff192c975cc0294521fd942d8debb8
- author
- bnema · · 2026-03-10 22:17 UTC
- committer
- brice · · 2026-03-11 04:05 UTC
- parent
- 56250d7
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +18 -27
M internal/ui/input/keyboard.go +2 -2
| @@ -509,8 +509,8 @@ func IsShortcutModified(modifiers Modifier) bool { | |||
| 509 | 509 | // WebKit IM pipeline for compose/dead-key processing. | |
| 510 | 510 | func IsTextInputKey(keyval uint) bool { | |
| 511 | 511 | // Dead keys used by compose sequences (US International, etc.) | |
| 512 | - | // GDK dead key range: KEY_dead_grave (0xfe50) to KEY_dead_greek (0xfe8b) | |
| 513 | - | if keyval >= 0xfe50 && keyval <= 0xfe8b { | |
| 512 | + | // GDK dead key range: KEY_dead_grave (0xfe50) to KEY_dead_greek (0xfe8c) | |
| 513 | + | if keyval >= 0xfe50 && keyval <= 0xfe8c { | |
| 514 | 514 | return true | |
| 515 | 515 | } | |
| 516 | 516 | ||
| @@ -509,8 +509,8 @@ func IsShortcutModified(modifiers Modifier) bool { | |||||
| 509 | // WebKit IM pipeline for compose/dead-key processing. | 509 | // WebKit IM pipeline for compose/dead-key processing. | ||
| 510 | func IsTextInputKey(keyval uint) bool { | 510 | func IsTextInputKey(keyval uint) bool { | ||
| 511 | // Dead keys used by compose sequences (US International, etc.) | 511 | // Dead keys used by compose sequences (US International, etc.) | ||
| 512 | - | // GDK dead key range: KEY_dead_grave (0xfe50) to KEY_dead_greek (0xfe8b) | 512 | + | // GDK dead key range: KEY_dead_grave (0xfe50) to KEY_dead_greek (0xfe8c) |
| 513 | - | if keyval >= 0xfe50 && keyval <= 0xfe8b { | 513 | + | if keyval >= 0xfe50 && keyval <= 0xfe8c { |
| 514 | return true | 514 | return true | ||
| 515 | } | 515 | } | ||
| 516 | 516 | ||||
M internal/ui/input/keyboard_test.go +16 -25
| @@ -9,6 +9,17 @@ import ( | |||
| 9 | 9 | "github.com/stretchr/testify/assert" | |
| 10 | 10 | ) | |
| 11 | 11 | ||
| 12 | + | // newTestConfig creates a minimal Config with activation shortcuts set. | |
| 13 | + | // Used by tests that construct a KeyboardHandler. | |
| 14 | + | func newTestConfig() *config.Config { | |
| 15 | + | cfg := &config.Config{} | |
| 16 | + | cfg.Workspace.TabMode.ActivationShortcut = "ctrl+t" | |
| 17 | + | cfg.Workspace.PaneMode.ActivationShortcut = "ctrl+p" | |
| 18 | + | cfg.Workspace.ResizeMode.ActivationShortcut = "ctrl+alt+r" | |
| 19 | + | cfg.Session.SessionMode.ActivationShortcut = "ctrl+s" | |
| 20 | + | return cfg | |
| 21 | + | } | |
| 22 | + | ||
| 12 | 23 | func TestIsShortcutModified(t *testing.T) { | |
| 13 | 24 | tests := []struct { | |
| 14 | 25 | name string | |
| @@ -81,11 +92,7 @@ func TestIsTextInputKey(t *testing.T) { | |||
| 81 | 92 | ||
| 82 | 93 | func TestHandleKeyPress_RoutePassToWidget(t *testing.T) { | |
| 83 | 94 | ctx := context.Background() | |
| 84 | - | cfg := &config.Config{} | |
| 85 | - | cfg.Workspace.TabMode.ActivationShortcut = "ctrl+t" | |
| 86 | - | cfg.Workspace.PaneMode.ActivationShortcut = "ctrl+p" | |
| 87 | - | cfg.Workspace.ResizeMode.ActivationShortcut = "ctrl+alt+r" | |
| 88 | - | cfg.Session.SessionMode.ActivationShortcut = "ctrl+s" | |
| 95 | + | cfg := newTestConfig() | |
| 89 | 96 | ||
| 90 | 97 | h := NewKeyboardHandler(ctx, cfg) | |
| 91 | 98 | ||
| @@ -116,11 +123,7 @@ func TestHandleKeyPress_RoutePassToWidget(t *testing.T) { | |||
| 116 | 123 | ||
| 117 | 124 | func TestHandleKeyPress_RouteAccentDetection_NoAccent(t *testing.T) { | |
| 118 | 125 | ctx := context.Background() | |
| 119 | - | cfg := &config.Config{} | |
| 120 | - | cfg.Workspace.TabMode.ActivationShortcut = "ctrl+t" | |
| 121 | - | cfg.Workspace.PaneMode.ActivationShortcut = "ctrl+p" | |
| 122 | - | cfg.Workspace.ResizeMode.ActivationShortcut = "ctrl+alt+r" | |
| 123 | - | cfg.Session.SessionMode.ActivationShortcut = "ctrl+s" | |
| 126 | + | cfg := newTestConfig() | |
| 124 | 127 | ||
| 125 | 128 | h := NewKeyboardHandler(ctx, cfg) | |
| 126 | 129 | ||
| @@ -136,11 +139,7 @@ func TestHandleKeyPress_RouteAccentDetection_NoAccent(t *testing.T) { | |||
| 136 | 139 | ||
| 137 | 140 | func TestHandleKeyPress_ShortcutsWorkWithRouting(t *testing.T) { | |
| 138 | 141 | ctx := context.Background() | |
| 139 | - | cfg := &config.Config{} | |
| 140 | - | cfg.Workspace.TabMode.ActivationShortcut = "ctrl+t" | |
| 141 | - | cfg.Workspace.PaneMode.ActivationShortcut = "ctrl+p" | |
| 142 | - | cfg.Workspace.ResizeMode.ActivationShortcut = "ctrl+alt+r" | |
| 143 | - | cfg.Session.SessionMode.ActivationShortcut = "ctrl+s" | |
| 142 | + | cfg := newTestConfig() | |
| 144 | 143 | ||
| 145 | 144 | h := NewKeyboardHandler(ctx, cfg) | |
| 146 | 145 | ||
| @@ -163,11 +162,7 @@ func TestHandleKeyPress_ShortcutsWorkWithRouting(t *testing.T) { | |||
| 163 | 162 | ||
| 164 | 163 | func TestHandleKeyPress_ModalModeIgnoresRoute(t *testing.T) { | |
| 165 | 164 | ctx := context.Background() | |
| 166 | - | cfg := &config.Config{} | |
| 167 | - | cfg.Workspace.TabMode.ActivationShortcut = "ctrl+t" | |
| 168 | - | cfg.Workspace.PaneMode.ActivationShortcut = "ctrl+p" | |
| 169 | - | cfg.Workspace.ResizeMode.ActivationShortcut = "ctrl+alt+r" | |
| 170 | - | cfg.Session.SessionMode.ActivationShortcut = "ctrl+s" | |
| 165 | + | cfg := newTestConfig() | |
| 171 | 166 | ||
| 172 | 167 | h := NewKeyboardHandler(ctx, cfg) | |
| 173 | 168 | h.EnterTabMode() | |
| @@ -207,11 +202,7 @@ func TestKeyboardHandler_SetRouteKey(t *testing.T) { | |||
| 207 | 202 | ||
| 208 | 203 | func TestHandleKeyPress_NoRouteCallback_DefaultsToShortcuts(t *testing.T) { | |
| 209 | 204 | ctx := context.Background() | |
| 210 | - | cfg := &config.Config{} | |
| 211 | - | cfg.Workspace.TabMode.ActivationShortcut = "ctrl+t" | |
| 212 | - | cfg.Workspace.PaneMode.ActivationShortcut = "ctrl+p" | |
| 213 | - | cfg.Workspace.ResizeMode.ActivationShortcut = "ctrl+alt+r" | |
| 214 | - | cfg.Session.SessionMode.ActivationShortcut = "ctrl+s" | |
| 205 | + | cfg := newTestConfig() | |
| 215 | 206 | ||
| 216 | 207 | h := NewKeyboardHandler(ctx, cfg) | |
| 217 | 208 | ||
| @@ -9,6 +9,17 @@ import ( | |||||
| 9 | "github.com/stretchr/testify/assert" | 9 | "github.com/stretchr/testify/assert" | ||
| 10 | ) | 10 | ) | ||
| 11 | 11 | ||||
| 12 | + | // newTestConfig creates a minimal Config with activation shortcuts set. | |||
| 13 | + | // Used by tests that construct a KeyboardHandler. | |||
| 14 | + | func newTestConfig() *config.Config { | |||
| 15 | + | cfg := &config.Config{} | |||
| 16 | + | cfg.Workspace.TabMode.ActivationShortcut = "ctrl+t" | |||
| 17 | + | cfg.Workspace.PaneMode.ActivationShortcut = "ctrl+p" | |||
| 18 | + | cfg.Workspace.ResizeMode.ActivationShortcut = "ctrl+alt+r" | |||
| 19 | + | cfg.Session.SessionMode.ActivationShortcut = "ctrl+s" | |||
| 20 | + | return cfg | |||
| 21 | + | } | |||
| 22 | + | ||||
| 12 | func TestIsShortcutModified(t *testing.T) { | 23 | func TestIsShortcutModified(t *testing.T) { | ||
| 13 | tests := []struct { | 24 | tests := []struct { | ||
| 14 | name string | 25 | name string | ||
| @@ -81,11 +92,7 @@ func TestIsTextInputKey(t *testing.T) { | |||||
| 81 | 92 | ||||
| 82 | func TestHandleKeyPress_RoutePassToWidget(t *testing.T) { | 93 | func TestHandleKeyPress_RoutePassToWidget(t *testing.T) { | ||
| 83 | ctx := context.Background() | 94 | ctx := context.Background() | ||
| 84 | - | cfg := &config.Config{} | 95 | + | cfg := newTestConfig() |
| 85 | - | cfg.Workspace.TabMode.ActivationShortcut = "ctrl+t" | |||
| 86 | - | cfg.Workspace.PaneMode.ActivationShortcut = "ctrl+p" | |||
| 87 | - | cfg.Workspace.ResizeMode.ActivationShortcut = "ctrl+alt+r" | |||
| 88 | - | cfg.Session.SessionMode.ActivationShortcut = "ctrl+s" | |||
| 89 | 96 | ||||
| 90 | h := NewKeyboardHandler(ctx, cfg) | 97 | h := NewKeyboardHandler(ctx, cfg) | ||
| 91 | 98 | ||||
| @@ -116,11 +123,7 @@ func TestHandleKeyPress_RoutePassToWidget(t *testing.T) { | |||||
| 116 | 123 | ||||
| 117 | func TestHandleKeyPress_RouteAccentDetection_NoAccent(t *testing.T) { | 124 | func TestHandleKeyPress_RouteAccentDetection_NoAccent(t *testing.T) { | ||
| 118 | ctx := context.Background() | 125 | ctx := context.Background() | ||
| 119 | - | cfg := &config.Config{} | 126 | + | cfg := newTestConfig() |
| 120 | - | cfg.Workspace.TabMode.ActivationShortcut = "ctrl+t" | |||
| 121 | - | cfg.Workspace.PaneMode.ActivationShortcut = "ctrl+p" | |||
| 122 | - | cfg.Workspace.ResizeMode.ActivationShortcut = "ctrl+alt+r" | |||
| 123 | - | cfg.Session.SessionMode.ActivationShortcut = "ctrl+s" | |||
| 124 | 127 | ||||
| 125 | h := NewKeyboardHandler(ctx, cfg) | 128 | h := NewKeyboardHandler(ctx, cfg) | ||
| 126 | 129 | ||||
| @@ -136,11 +139,7 @@ func TestHandleKeyPress_RouteAccentDetection_NoAccent(t *testing.T) { | |||||
| 136 | 139 | ||||
| 137 | func TestHandleKeyPress_ShortcutsWorkWithRouting(t *testing.T) { | 140 | func TestHandleKeyPress_ShortcutsWorkWithRouting(t *testing.T) { | ||
| 138 | ctx := context.Background() | 141 | ctx := context.Background() | ||
| 139 | - | cfg := &config.Config{} | 142 | + | cfg := newTestConfig() |
| 140 | - | cfg.Workspace.TabMode.ActivationShortcut = "ctrl+t" | |||
| 141 | - | cfg.Workspace.PaneMode.ActivationShortcut = "ctrl+p" | |||
| 142 | - | cfg.Workspace.ResizeMode.ActivationShortcut = "ctrl+alt+r" | |||
| 143 | - | cfg.Session.SessionMode.ActivationShortcut = "ctrl+s" | |||
| 144 | 143 | ||||
| 145 | h := NewKeyboardHandler(ctx, cfg) | 144 | h := NewKeyboardHandler(ctx, cfg) | ||
| 146 | 145 | ||||
| @@ -163,11 +162,7 @@ func TestHandleKeyPress_ShortcutsWorkWithRouting(t *testing.T) { | |||||
| 163 | 162 | ||||
| 164 | func TestHandleKeyPress_ModalModeIgnoresRoute(t *testing.T) { | 163 | func TestHandleKeyPress_ModalModeIgnoresRoute(t *testing.T) { | ||
| 165 | ctx := context.Background() | 164 | ctx := context.Background() | ||
| 166 | - | cfg := &config.Config{} | 165 | + | cfg := newTestConfig() |
| 167 | - | cfg.Workspace.TabMode.ActivationShortcut = "ctrl+t" | |||
| 168 | - | cfg.Workspace.PaneMode.ActivationShortcut = "ctrl+p" | |||
| 169 | - | cfg.Workspace.ResizeMode.ActivationShortcut = "ctrl+alt+r" | |||
| 170 | - | cfg.Session.SessionMode.ActivationShortcut = "ctrl+s" | |||
| 171 | 166 | ||||
| 172 | h := NewKeyboardHandler(ctx, cfg) | 167 | h := NewKeyboardHandler(ctx, cfg) | ||
| 173 | h.EnterTabMode() | 168 | h.EnterTabMode() | ||
| @@ -207,11 +202,7 @@ func TestKeyboardHandler_SetRouteKey(t *testing.T) { | |||||
| 207 | 202 | ||||
| 208 | func TestHandleKeyPress_NoRouteCallback_DefaultsToShortcuts(t *testing.T) { | 203 | func TestHandleKeyPress_NoRouteCallback_DefaultsToShortcuts(t *testing.T) { | ||
| 209 | ctx := context.Background() | 204 | ctx := context.Background() | ||
| 210 | - | cfg := &config.Config{} | 205 | + | cfg := newTestConfig() |
| 211 | - | cfg.Workspace.TabMode.ActivationShortcut = "ctrl+t" | |||
| 212 | - | cfg.Workspace.PaneMode.ActivationShortcut = "ctrl+p" | |||
| 213 | - | cfg.Workspace.ResizeMode.ActivationShortcut = "ctrl+alt+r" | |||
| 214 | - | cfg.Session.SessionMode.ActivationShortcut = "ctrl+s" | |||
| 215 | 206 | ||||
| 216 | h := NewKeyboardHandler(ctx, cfg) | 207 | h := NewKeyboardHandler(ctx, cfg) | ||
| 217 | 208 | ||||