marzer / poxy

Documentation generator for C++
https://pypi.org/project/poxy
MIT License
137 stars 5 forks source link

Please support accesskey="f" for Search #22

Closed tim-janik closed 10 months ago

tim-janik commented 1 year ago

Is your feature request related to a problem? Please describe.

Wikipedia and many other sites support starting up Search on Shift+Alt+F. That'd be nice to have in Poxy output as well.

Describe the solution you'd like

I.e. please add code to achieve the equivalent of:

sed -r '0,/<a class="m-doc-search-icon" href="#search" /s/(<a class="m-doc-search-icon")/\1 accesskey="f"/' -i html/*.html

Additional context

Other keys are also supported by Wikipedia, e.g. accesskey="z" to go to the Home/front page, but those aren't as frequently used/missed as Shift+Alt+F for search.

wroyca commented 1 year ago

We discussed something similar on Element a few months back, the suggested alternative for now was to add the search field as a search engine and then add a shortcut to it:

mosra (Vladimír Vondruš):

about the search, you can right click into the search field and "add as a search engine" on browsers that support custom search (vivaldi, firefox, opera does, not sure about plain chrome) i can even add a shortcut (such as mn for magnum) so e.g. mn pixelf in the url bar leads me straight to search results for pixel format

and if you don't have a browser with custom search engines you can bookmark ?query=#search at least, to lead you to a page that has a search box with results already opened

That said, I'd also like to see integrated binding as well :)

mosra commented 1 year ago

You can open it by pressing T, which is consistent with GitHub file search (when you're on a file listing page, pressing that will allow you to quickly search for files with a fuzzy pattern). You can also use Tab that achieves the same. I chose that because on many websites it highlights the first form input, which is usually the search.

I think those two are more than enough. But I'll make sure to have them documented somewhere visible, for some reason it isn't. Actually it is shown, right at the top of the search box :eyes:

GitHub doesn't seem to understand Shift Alt F, so I don't think that's a "standardized" key binding. Plus, since it has to open a popup, just an accesskey wouldn't be enough I think.

marzer commented 1 year ago

@mosra

Plus, since it has to open a popup, just an accesskey wouldn't be enough I think.

I just tested it via DOM editing and it seems to work OK (on Firefox, at least). It does do something slightly odd with the page layout if you press it twice (i.e. pressing it once again when the search dialog is visible), though it's a pretty minor cosmetic issue.

EDIT: Oh, I see. It's because pressing it multiple times causes showSearch() to be called repeatedly, whereas normally this isn't possible without there first being a call to hideSearch(). Hmmm. Probably just a if (window.location.hash == '#search') return false; inside showSearch() would be sufficient to prevent this.

mosra commented 1 year ago

I don't know, if anything I'd just add the key binding next to the other two in the javascript code, I don't see a reason to implement it in a completely different way.

And, again, I think two bindings are enough already, no need to have three. Having this configurable would mean each m.css-based site could have the hotkeys slightly different, which isn't any good for usability. There isn't any consistency across the web with Shift Alt F either, so let's don't mess it up further by also having each m.css search box behave differently.

marzer commented 1 year ago

And, again, I think two bindings are enough already, no need to have three.

Yeh, I'm inclined to agree. I'm just doing a bit of testing for the sake of learning how accesskey works. @tim-janik I don't really think this adds any value, personally.

marzer commented 1 year ago

@tim-janik I'll add a hook to catch multiple calls to the search function so you can do your own overrides to it without worrying about breaking page state (e.g. using sed to apply an accesskey in your CI pipeline or wherever). I think that's a good middle ground, since T and TAB are already sufficient for the vast majority of users.

tim-janik commented 1 year ago

Thanks, I'm just used to accesskey="F" from Wikipedia, and indeed I'm using sed atm to add that to the first <a class="m-doc-search-icon"/> element. You can test it out here: https://tim-janik.github.io/docs/anklang/

I don't see any page layout issues in Firefox though, and AFAICS a second/third key press does nothing if the search field is already activated.

marzer commented 1 year ago

I don't see any page layout issues in Firefox though, and AFAICS a second/third key press does nothing if the search field is already activated.

On my machine I see the RHS page margin being set to 17px first time, then auto after that. It's not a catastrophic effect by any measure; just looks a bit weird.