Skip to content

feat(config): add pre-parsed-default overload for register_key_combo (v3.2.4) #79

@coderabbitai

Description

@coderabbitai

Summary

In src/config.cpp, register_press_combo / register_hold_combo pre-parse default_value into current_combos (lines ~998-1004) and then call register_key_combo, which re-parses the same default_value_str. This causes duplicate WARNING logs when the C++ literal default contains a typo (e.g. register_press_combo(..., "ctrl+xyzzy")).

Root cause

register_key_combo synchronously invokes the setter at line 985 with the re-parsed default. Passing "" to avoid the double-parse regresses behavior: the closure immediately clobbers the pre-parsed current_combos with an empty list, so the binding has no keys unless the INI overrides it.

Proposed fix (Option 2 — cleanest)

Add a pre-parsed-default overload on register_key_combo that accepts a KeyComboList directly instead of string_view, so callers that have already parsed the default can skip the re-parse step:

// New overload
bool register_key_combo(
    std::string_view section,
    std::string_view key,
    KeyComboList      parsed_default,   // pre-parsed
    std::string_view  log_key_name,
    std::function<void(KeyComboList)> setter
);

register_press_combo / register_hold_combo would call this overload after their existing parse, eliminating the double-parse and the spurious WARNING.

Alternatives considered

  1. Skip-initial-seed flag in the closure — works but adds shared mutable state for a developer-error edge case.
  2. Reorder register_press before register_key_combo + skip-seed flag — still needs the flag.

Impact of the current behavior

  • Fires only on C++ literal typos in default_value, once at process startup, and only when the INI does not override the key.
  • Self-correcting: warning vanishes once the developer fixes the typo.
  • User-supplied INI typos go through a single parse path (one WARNING, as documented).

References

Target milestone

v3.2.4

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions