Skip to content

Fix duplicate key binding detection with proper normalization#870

Merged
noborus merged 4 commits intomasterfrom
fix-duplicatekeybind
Oct 6, 2025
Merged

Fix duplicate key binding detection with proper normalization#870
noborus merged 4 commits intomasterfrom
fix-duplicatekeybind

Conversation

@noborus
Copy link
Owner

@noborus noborus commented Oct 6, 2025

  • 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.

- 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.
@noborus noborus requested a review from Copilot October 6, 2025 05:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message is incomplete and unclear. It should describe what the actual problem is with the key binding.

Suggested change
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))

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's obvious that the key name is incorrect, so I'll omit it here.

noborus and others added 3 commits October 6, 2025 14:31
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.
@noborus noborus merged commit 3507b8c into master Oct 6, 2025
9 checks passed
@noborus noborus deleted the fix-duplicatekeybind branch October 8, 2025 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants