Skip to content

Navigate query history with Up/Down arrow keys#26484

Open
kmerz wants to merge 2 commits into
masterfrom
feat/short-cut-for-query-history-26472
Open

Navigate query history with Up/Down arrow keys#26484
kmerz wants to merge 2 commits into
masterfrom
feat/short-cut-for-query-history-26472

Conversation

@kmerz

@kmerz kmerz commented Jun 25, 2026

Copy link
Copy Markdown
Member

Description

When the search bar query input is focused and contains a single-line query, the Up and
Down arrow keys now cycle through query history inline — similar to a terminal's command
history.

  • enters history mode and walks backwards through entries (most recent first); pressing
    repeatedly advances to older entries
  • walks forward again; one step past the most recent entry restores the originally-typed
    query and exits history mode
  • Any manual edit while in history mode resets the navigation index so the next starts
    fresh from the top
  • Multiline queries are unaffected — arrow keys retain normal cursor movement within the editor

The new shortcuts are also listed in the keyboard shortcut help modal under Query Input.

Motivation and Context

Fixes #26472

Reaching query history currently requires either clicking the history icon, pressing
Alt+Shift+H, or pressing Ctrl+Space with an empty input. None of these match the muscle
memory most users have from terminal use. The key is the most natural way to recall a
previous command.

How Has This Been Tested?

  • Added 6 unit tests to ViewsQueryInput.test.tsx covering: entering history on , advancing
    to older entries, returning on , restoring the original query when navigating back past the
    newest entry, no-op without prior , and clamping at the oldest entry without
    wrap-around.
  • Manually verified: empty input → shows most recent entry; repeated walks back;
    returns toward present; past newest restores the original query; multiline query → arrow
    keys move the cursor normally; Alt+Shift+H and history button still work as before.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have requested a documentation update.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

When the search bar input is focused and contains a single-line query,
Up/Down arrows cycle through history inline (terminal-style). The
original query is restored when navigating back past the most recent
entry. Multiline queries retain normal cursor movement.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds terminal-like inline query history navigation to the search bar query input: when the editor contains a single-line query, ↑/↓ cycle through query history entries without opening the history UI, while multiline queries keep default cursor navigation.

Changes:

  • Add ArrowUp/ArrowDown ACE commands to navigate query history inline for single-line queries.
  • Extract and export fetchRawQueryHistory() to share history fetching between the history dropdown and new inline navigation.
  • Extend hotkey help metadata and add unit tests for the new navigation behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
graylog2-web-interface/src/views/components/searchbar/ViewsQueryInput.test.tsx Adds unit tests for inline query history navigation and mocks history fetching.
graylog2-web-interface/src/views/components/searchbar/queryinput/QueryInput.tsx Implements ↑/↓ history navigation commands and tracks navigation state in refs.
graylog2-web-interface/src/views/components/searchbar/queryinput/ace-types.ts Extends ACE Editor typing to support on('change'), navigateUp/Down, and setValue cursor arg.
graylog2-web-interface/src/views/components/searchbar/QueryHistoryButton.tsx Refactors history fetching into fetchRawQueryHistory() and reuses it for completions.
graylog2-web-interface/src/contexts/HotkeysProvider.tsx Adds up/down actions to the Query Input hotkeys collection for the help modal.
changelog/unreleased/issue-26472.toml Adds an unreleased changelog entry for the new shortcut behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +335 to +347
if (historyEntriesRef.current.length === 0) {
historyEntriesRef.current = await fetchRawQueryHistory();
}

if (historyEntriesRef.current.length === 0) return;

const nextIndex = Math.min(historyIndexRef.current + 1, historyEntriesRef.current.length - 1);

if (nextIndex === historyIndexRef.current) return;

if (historyIndexRef.current === -1) {
savedQueryRef.current = editor.getValue();
}
Comment on lines +250 to +261
it('does not navigate history when ArrowDown is pressed without prior ArrowUp', async () => {
const onChange = jest.fn().mockResolvedValue('');
render(<SimpleQueryInput onChange={onChange} />);

const queryInput = await findQueryInput();
queryInput.focus();
await userEvent.keyboard('{ArrowDown}');

// onChange is not called because the Down command falls through to ACE line navigation
expect(onChange).not.toHaveBeenCalled();
});

When the most-recently executed query is still in the editor, the first
Up press now skips history[0] and lands on history[1] so the user
always sees a visible change. Down navigates back symmetrically,
restoring the original query in one step.

  Adds two tests covering this scenario.
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.

Query history arrow key shortcuts for main search input

2 participants