Skip to content

fix: Add reverse-search in console-v2#5985

Open
snghnl wants to merge 2 commits intopyodide:mainfrom
snghnl:xterm-reverse-search
Open

fix: Add reverse-search in console-v2#5985
snghnl wants to merge 2 commits intopyodide:mainfrom
snghnl:xterm-reverse-search

Conversation

@snghnl
Copy link
Contributor

@snghnl snghnl commented Nov 2, 2025

Description

This PR adds reverse-search in console-v2. (resolves #5961)

It supports:

Ctrl+R: Enter the reverse-search, and find next one
Ctrl+C, Ctrl+G: Cancel the reverse-search
Arrows(Up, Down, Left, Right), TAB: Cancel the reverse-search with statement now focusing.

Copy link
Member

@ryanking13 ryanking13 left a comment

Choose a reason for hiding this comment

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

Thanks! It looks good to me overall. I left some minor comments

- allow unicode
- accept r-search even when there is not history
- make new function applyReverseSearchSelection
@snghnl
Copy link
Contributor Author

snghnl commented Nov 4, 2025

Thanks for your review, @ryanking13. I have just reflected your comment.

Comment on lines 188 to +195
const history = [];
let historyIndex = null; // null means not navigating history

// Reverse search state
let reverseSearchMode = false;
let reverseSearchQuery = "";
let reverseSearchIndex = -1; // index in history
let savedBuffer = ""; // buffer before entering search mode
Copy link
Member

Choose a reason for hiding this comment

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

How about extracting the history state, the history loading logic, searching etc into a class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for you review, @hoodmane. Actually I made them class in #5986 (following PR), not only them also normal state, commands, pyodide console, etc. Is it better to make them class in this PR first?

Copy link
Member

Choose a reason for hiding this comment

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

I think we can merge this first as this is already reviewed.

Comment on lines +296 to +297
reverseSearchQuery += char;
reverseSearchIndex = searchHistory(reverseSearchQuery);
Copy link
Member

Choose a reason for hiding this comment

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

The original console does not add a character if there is no matching history. But this will always add the charactor to the query.

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.

console-v2 doesn't remember terminal history after refresh or support reverse search

3 participants