Fix duplicate key binding detection with proper normalization#870
Fix duplicate key binding detection with proper normalization#870
Conversation
- Add normalizeKey() and normalizeKeyWithPrefix() functions to handle key notation variations (e.g., "ctrl+c" vs "Ctrl+C") - Update findDuplicateKeyBind() to return both duplicates and errors - Improve error handling to collect all validation issues instead of stopping at first error - Enhance DuplicateKeyBind() to display invalid key bindings with clear error messages - Rename duplicate struct to keyActionMapping for clarity - Fix ov.yaml: change toggle_mouse key from "ctrl+f3" to "ctrl+F4" to resolve duplicate binding issue This ensures more robust key binding validation and helps users identify and fix configuration issues more effectively.
There was a problem hiding this comment.
Pull Request Overview
This PR improves key binding validation in the oviewer configuration system to handle key notation variations and provide better error reporting. The changes focus on normalizing key representations to detect duplicates accurately and collecting all validation errors instead of stopping at the first one.
- Added key normalization functions to handle case variations in key bindings (e.g., "ctrl+c" vs "Ctrl+C")
- Enhanced duplicate detection to return both duplicates and validation errors
- Improved error display in the help system to show invalid key bindings with clear messages
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| oviewer/keybind.go | Core implementation of key normalization and improved duplicate detection logic |
| oviewer/help.go | Enhanced error display to show invalid key bindings alongside duplicates |
| ov.yaml | Fixed duplicate key binding by changing toggle_mouse from "ctrl+f3" to "ctrl+F4" |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| for _, key := range keys { | ||
| normalizedKey, err := normalizeKeyWithPrefix(key, action) | ||
| if err != nil { | ||
| errors = append(errors, fmt.Errorf("key %s for action %s", key, action)) |
There was a problem hiding this comment.
The error message is incomplete and unclear. It should describe what the actual problem is with the key binding.
| errors = append(errors, fmt.Errorf("key %s for action %s", key, action)) | |
| errors = append(errors, fmt.Errorf("failed to normalize key %q for action %q: %v", key, action, err)) |
There was a problem hiding this comment.
It's obvious that the key name is incorrect, so I'll omit it here.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Modify setHandler() to properly bind both Enter and Ctrl+J events when "ctrl+j" is specified in key bindings - Update normalizeKey() to distinguish between "ctrl+j" and "Enter" even though cbind.Decode unifies them - Restructure key binding logic to handle special cases more clearly - Remove redundant continue statement and improve code flow This change ensures Ctrl+J key bindings work correctly across different terminals where Ctrl+J and Enter may be reported as separate events, while maintaining backward compatibility with existing configurations.
…-duplicatekeybind
This ensures more robust key binding validation and helps users identify and fix configuration issues more effectively.