Skip to content

Quick jump to a specific file - #3239

Open
major1201 wants to merge 2 commits into
rust-lang:mainfrom
major1201:quickjump
Open

major1201 wants to merge 2 commits into
rust-lang:mainfrom
major1201:quickjump

Conversation

@major1201

Copy link
Copy Markdown

Added a new feature which allows you to quickly search a file by its filename or title when you press Cmd/Ctrl-k

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Oct 19, 2026

@Chocorean Chocorean 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.

Great contribution! I would advise to add a gui test, such as the search test

View changes since this review

@major1201

Copy link
Copy Markdown
Author

Thank you for reminding me, I've added a few ui test cases which included in tests/gui/quickjump.goml.

@Chocorean

Copy link
Copy Markdown
Contributor

The last thing I can think of is I have managed to spawn both the S bar and the Ctrl+K bar by playing with the browser ; they can be both displayed at the same time and it looks odd, but you have to really look for it to make it happen. Not sure this is an issue!

Otherwise I think it's good for official review, if you are satisfied you may ping guillaume I believe

@major1201

Copy link
Copy Markdown
Author

Currently it is not allowed to switch between search mode and quick-jump mode when either is activated.
I would like to make it free to switch anytime you want, let's discuss that in detail:

  • When search mode is on, once you press ctrl-k, the search input can be switched the quickjump mode, that should be easy to make it work
  • When quickjump mode is on, once you press 's', I don't know whether you want to search an expression which starts with 's' or you want to switch to search mode

So I'm hesitated to keep it as is (not allowed to switch between different modes) or allow switching to quickjump mode from search mode only.

@Chocorean

Copy link
Copy Markdown
Contributor

Well technically you can switch from one bar to the other by doing Esc then shortcut

Another way could be to merge these two bars, but file lookup would be triggered by a prefix, like >
Ctrl+K would be kept and would automatically preppend the search value with said prefix

I feel like introducing a shortcut to switch bars it counter intuitive, if one already could not remember the proper shortcut, now they are expected to remember a third to fix their mistake rather than knowing it from the first place

Wdyt?

@GuillaumeGomez

Copy link
Copy Markdown
Member

I like the feature idea, but not so much the idea of adding another shortcut. Why not a button instead?

@major1201

Copy link
Copy Markdown
Author

Thanks @Chocorean @GuillaumeGomez you guys inspired me, I just inserted the chapter and files results into the search results. Once you press s the filename and title matches first and then the search results. So there's gonna be no new keyboard shortcut comes out and no more keyboard collisions would happen which looks much more elegant.

What do you think of that?

I still keep two commits now. I'll squash into one once it looks good to you

@Chocorean

Copy link
Copy Markdown
Contributor

For reference:

Actual: image
Proposed: image

I find the proposed a bit empty ; maybe showing the beginning of the article would help fill the blank?

Also, something I think is not super relevant is to search the whole path:
image
I would expect the search to limit its area to what's after the output directory of the book

@major1201

Copy link
Copy Markdown
Author

That make sense, optimized to add excerpt of that file

@Chocorean

Copy link
Copy Markdown
Contributor

Great, that is much better now!

Last comment from me is I would limit the number of search results somehow:
image

Maybe max 10 chapters and 10 search results to keep the default 20 search results, idk if there is an option for that

@major1201

Copy link
Copy Markdown
Author

Great advice, added a new option limit-chapter-results in output.html.search to limit the max results which defaults to 20.

[output.html.search]
limit-results = 30       # maximum number of search results
limit-chapter-results = 20 # maximum number of chapter/file-name matches shown before search results

@major1201

Copy link
Copy Markdown
Author

@GuillaumeGomez Hi, gently ping in case this PR is ignored

@GuillaumeGomez

Copy link
Copy Markdown
Member

Some extra thoughts about this: the files are listed in the sidebar, so not sure to see the added value here. What do you think @rust-lang/mdbook ?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: waiting on a review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants