Skip to content

[Hide Channels] Channel list toggles on unintended key combinations (e.g. Ctrl+Backspace) #175

@aphirst

Description

@aphirst

Describe the bug

The plugin toggles channel visibility when pressing Ctrl+Backspace (commonly used to delete words while editing longer messages), even though the default and only documented keybind is Ctrl+H. This appears to affect any key combination that shares the Ctrl modifier.

Expected behavior

The channel list should only toggle when pressing the actual configured keybind (Ctrl+H by default), not other key combinations that happen to share the same modifier key.

To reproduce

  1. Install plugin with default keybind (Ctrl+H)
  2. Start typing a message in Discord
  3. Press Ctrl+Backspace to delete a word
  4. Channel list unexpectedly toggles

Screenshots

No response

OS version

Windows 11

Discord version

Stable

BetterDiscord version

1.12.1

Plugin version

2.2.14

Additional context

Suspected cause
I suspect the keyup event handler (lines 251-261) checks whether all keybind keys are pressed without verifying the released key is actually part of the keybind. If I'm right, the condition triggers whenever Ctrl is held and any key is released, rather than only when releasing a key that's part of the configured keybind combination.

Possible fix
Adding a check to verify the released key is part of the keybind before evaluating the toggle condition might resolve this. Maybe something like:

//Keyup event
useListener("keyup", e => {
    //Check if this is the last key of our keybind being released
    //AND all other keybind keys are still pressed
    const releasedKey = e.key.toLowerCase();
    const isKeybindKey = this.keybind.some(key => key.toLowerCase() === releasedKey);
    
    if (isKeybindKey && 
        this.keybind.every(key => this.currentlyPressed[key.toLowerCase()] === true)) {
        //Toggle the sidebar and rerender on toggle; change the state
        setHidden(toggleSidebar(sidebarNode));
    }

    //Current key goes up, so clear it
    this.currentlyPressed[releasedKey] = false;

    //Account for bubbling
}, true);

On initial testing this seems to have fixed it for me, but of course I may have overlooked something important, so don't take it too seriously.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions