Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hotkey support for saving via Ctrl+S #739

Open
theoricher opened this issue Jan 23, 2021 · 5 comments
Open

Add hotkey support for saving via Ctrl+S #739

theoricher opened this issue Jan 23, 2021 · 5 comments
Labels
enhancement good first issue Contributors could start with this easy task. help wanted

Comments

@theoricher
Copy link

Hello !

I propose the addition of a new feature allowing to publish a paste faster than with the "Upload" button simply by using the CTRL+S keys. :)

What do you think of this idea?

Thanks ;)

@elrido
Copy link
Contributor

elrido commented Jan 23, 2021

I do like the idea and adding shortcuts in JS is not too difficult. I played a bit with some examples, trying to switch them to CTRL+S. Many other combinations work, but CTRL+S and many other sequences seem to be reserved, at least in Firefox on Linux. Basically open the menus (if hidden on your OS, press ALT to enable the menu bar) and all those sequences listed in the menus will not work in JS, but trigger those functions instead. I can see that the don't want to let scammers override standard keypresses.

Would another CTRL combination work for you? If so, which one?

PS: Alternatively, an even simpler to implement way would be the accesskey-HTML-attribute: It would let us set "s" as the accesskey on the send-button and then you'd be able to trigger it with ALT+S or ALT+SHIFT+S or CTRL+ALT+S, depending on your browser or OS.

@theoricher
Copy link
Author

Ok I understand the problem. :)
It seems that the hastebin project has succeeded in doing that.
Can you see if CTRL+S works on this site with Firefox? hastebin.com
This is the project page : seejohnrun/haste-server
If this doesn't work we can think of another combination :)

@rugk
Copy link
Member

rugk commented Jan 23, 2021

Yeah on hastebin it seems to work… I also have in mind that Ctrl+S is one of the keypresses that can actually be overwritten. But we need to investigate that further…

@rugk rugk changed the title [FEATURE] Add support for CTRL+S Add hotkey support for saving via CTRL+S Jan 23, 2021
@rugk rugk changed the title Add hotkey support for saving via CTRL+S Add hotkey support for saving via Ctrl+S Jan 23, 2021
@simonrupf
Copy link

They use the method of key detection I had found as well:
https://github.com/seejohnrun/haste-server/blob/5d2965ffc5d9b309ef6d4be9e8c2288c83d72c73/static/application.js#L268

I think the bit I didn't do properly was hooking the event to keydown instead of keypress:
https://github.com/seejohnrun/haste-server/blob/5d2965ffc5d9b309ef6d4be9e8c2288c83d72c73/static/application.js#L351

Let's see: https://jsfiddle.net/c1vzsg40/ - I tested several browsers and OS combinations using browserstack and it seemed to work fine in all Windows browsers (as well as on Linux for Firefox and Chromium). On the Mac, Ctrl is recognized as a Meta key press instead - AFAIK Mac users would expect the combination to be Cmd+S (that's the button with the ⌘ they have instead of an Alt-key) instead of Ctrl+S - we could just accept both combinations for that action. The Cmd key seems to be detected as Alt key, so we would just trigger the send on both Ctrl+S and Alt+S. And yes, the keypress event doesn't show up at all, probably the preventdefault() on the keyup and -down events suppresses that event as well.

@theoricher
Copy link
Author

On the Mac, Ctrl is recognized as a Meta key press instead - AFAIK Mac users would expect the combination to be Cmd+S (that's the button with the ⌘ they have instead of an Alt-key) instead of Ctrl+S - we could just accept both combinations for that action.

@simonrupf I agree, I think it is the best solution for both.

@elrido elrido added help wanted good first issue Contributors could start with this easy task. labels Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue Contributors could start with this easy task. help wanted
Projects
None yet
Development

No branches or pull requests

4 participants