Skip to content

fix: escape key navigates back from search, lyrics, favorites, and plugin manager#14

Open
pipe-code wants to merge 4 commits into
involvex:mainfrom
pipe-code:fix/escape-navigation
Open

fix: escape key navigates back from search, lyrics, favorites, and plugin manager#14
pipe-code wants to merge 4 commits into
involvex:mainfrom
pipe-code:fix/escape-navigation

Conversation

@pipe-code

@pipe-code pipe-code commented Mar 24, 2026

Copy link
Copy Markdown

What's the issue?

Pressing Escape in several views either did nothing or only partially worked:

  • Search — clears the input when it has text, but pressing Escape again (empty input) or pressing it while browsing results did nothing.
  • Lyrics — the UI hint said "Press Esc to go back" but the key was never bound.
  • Favorites — same: no Escape binding at all.
  • Plugin Manager — same: showed Esc=Back in the shortcuts bar but never wired it up.

What's the fix?

SearchBar.tsx (original fix)

The clearSearch callback now checks whether the input is empty before deciding what to do:

  • Input has text → clears it (same as before)
  • Input is empty, or the bar is inactive (browsing results) → dispatches GO_BACK
// Before
const clearSearch = useCallback(() => {
    if (isActive) {
        setInput('');
        onInput('');
    }
}, [isActive, onInput]);

// After
const clearSearch = useCallback(() => {
    if (isActive && input !== '') {
        setInput('');
        onInput('');
    } else {
        dispatch({category: 'GO_BACK'});
    }
}, [isActive, onInput, input, dispatch]);

LyricsLayout.tsx, FavoritesList.tsx, PluginsLayout.tsx (expanded fix)

Each view now imports useNavigation and registers an escape binding with bypassBlock: true so it always fires:

useKeyBinding(['escape'], goBack, {bypassBlock: true});

For Plugin Manager specifically, Escape first closes the install dialog if it's open, and only dispatches GO_BACK if already on the list view.

The root cause across all views is the same: SearchBar registers its escape binding with bypassBlock: true, intercepting the key before the global handler can fire. Views without their own escape binding were simply left without any back navigation on keyboard.

Files changed

File Change
source/components/search/SearchBar.tsx GO_BACK fallback when input is empty
source/components/layouts/LyricsLayout.tsx Add escape → GO_BACK binding
source/components/favorites/FavoritesList.tsx Add escape → GO_BACK binding
source/components/layouts/PluginsLayout.tsx Add escape → GO_BACK (or close install dialog) binding

Summary by Sourcery

Bug Fixes:

  • Allow Escape to navigate back from search, lyrics, favorites, and plugin manager views instead of doing nothing.

@changeset-bot

changeset-bot Bot commented Mar 24, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 980197e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@sourcery-ai

sourcery-ai Bot commented Mar 24, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the search bar’s Escape-key handler so that it either clears non-empty input or triggers a GO_BACK navigation action when the input is empty or the bar is inactive, ensuring keyboard navigation back from search/results views.

Sequence diagram for Escape key handling in SearchBar

sequenceDiagram
    actor User
    participant SearchView
    participant SearchBar
    participant KeyBinding
    participant Store

    User->>SearchView: press escape key
    SearchView->>KeyBinding: onKeyDown(escape)
    KeyBinding->>SearchBar: clearSearch(bypassBlock=true)

    alt SearchBar isActive and input not empty
        SearchBar->>SearchBar: setInput("")
        SearchBar->>SearchView: onInput("")
    else input empty or SearchBar inactive
        SearchBar->>Store: dispatch(GO_BACK)
        Store-->>SearchView: navigate back
    end
Loading

File-Level Changes

Change Details Files
Adjust Escape-key clear behavior in the search bar to fall back to GO_BACK navigation when there is no text to clear.
  • Update clearSearch callback to clear input only when active and non-empty, otherwise dispatch a GO_BACK action
  • Expand clearSearch hook dependencies to include input and dispatch so the callback stays up to date
  • Clarify the comment above clearSearch to describe both clearing and back-navigation behavior
  • Preserve the existing Escape key binding but route it through the updated clearSearch logic
source/components/search/SearchBar.tsx

Possibly linked issues

  • [FEATURE] Pull lyrics from lrclib? #9: PR adds Escape behavior that goes back when search input is empty, resolving search mode’s lack of exit shortcut.
  • #[BUG] no way to exit from searching mode: PR changes Escape handling so empty search or inactive bar triggers GO_BACK, letting users exit search mode.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the search functionality's keyboard navigation by refining the behavior of the Escape key. It ensures that users can consistently navigate back from the search view or results, even when the search input is empty, by intelligently dispatching a 'GO_BACK' action instead of merely clearing an already empty input. This improves the overall user experience for keyboard-driven interactions.

Highlights

  • Issue Addressed: The Escape key in the search view previously only cleared the input text. Once the input was empty, pressing Escape again did nothing, preventing keyboard navigation back to the previous view from search or results.
  • Logic Change: The clearSearch callback in SearchBar.tsx was modified to check the input state. If the input contains text, Escape clears it. If the input is empty or the search bar is inactive (e.g., browsing results), Escape now dispatches a GO_BACK action.
  • Root Cause Resolution: This change resolves the issue where SearchBar's escape key binding, set with bypassBlock: true, would intercept the key press but perform no action when the input was empty, effectively blocking the default browser back behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the SearchBar component by modifying the clearSearch function. The escape key now provides dual functionality: it clears the search input if text is present, or navigates back if the input is already empty. The useCallback dependencies for clearSearch were correctly updated to include input and dispatch to ensure proper behavior. There is no further feedback to provide.

dispatch({category: 'GO_BACK'});
}
}, [isActive, onInput]);
}, [isActive, onInput, input, dispatch]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The inclusion of dispatch in the useCallback dependency array for clearSearch is important for robustness. While dispatch from useReducer is stable, the useNavigation hook's context value is memoized based on state and dispatch. As state can change, the dispatch function reference returned by useNavigation might not be stable across renders. Explicitly including it ensures that the clearSearch callback always uses the most current dispatch function, preventing potential stale closure issues or unexpected behavior.

@kilo-code-bot

kilo-code-bot Bot commented Mar 24, 2026

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 0

Files Reviewed (4 files)

  • source/components/favorites/FavoritesList.tsx - Escape key navigation added with proper type-safe useCallback and useKeyBinding
  • source/components/layouts/LyricsLayout.tsx - Escape key navigation added with proper imports and type-safe dispatch
  • source/components/layouts/PluginsLayout.tsx - Conditional escape handling (close install dialog OR go back) implemented correctly
  • source/components/search/SearchBar.tsx - Modified clearSearch to navigate back when input is empty, with correct dependency array updates

Type Safety Verification

All changes use the properly typed GoBackAction from source/types/actions.ts which is included in the NavigationAction union type in source/types/navigation.types.ts. The dispatch function from useNavigation() correctly accepts NavigationAction types.

Security Check

No secrets, API keys, or credentials introduced in this diff. All token/secret references in the codebase are pre-existing patterns for user configuration.

Changeset Note

⚠️ This PR is missing a changeset. If this change should result in a version bump, a changeset file needs to be added.

@pipe-code pipe-code changed the title fix: escape key navigates back when search input is empty fix: escape key navigates back from search, lyrics, favorites, and plugin manager Mar 24, 2026
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.

1 participant