Ctrl or Cmd + S should save code, not open save html dialog
Should override the Ctrl/Cmd+S binding in browser, so that the code is saved.
There was a recent article about someone finding a bug in their implementation of this, “The curious case of the disappearing Polish Ś”. This is the code that worked for them in the end:
if ((e.metaKey || (e.ctrlKey && !e.altKey)) && e.keyCode === goog.events.KeyCodes.S) {
this._editors.save()
e.preventDefault()
}
I assume that code goes in some keypress event handler for the textarea, into which the keypress event is passed as e.
Do you think it needs to be handled in code mirror or in the input element?
I suppose capturing the key combination with a CodeMirror binding would be easier and more consistent. But you would have to check first that CodeMirror supports that logic about holding keys.
I can see from “Key Maps” in the CodeMirror manual that CodeMirror supports both the Meta (Command) key and the Ctrl key. The code would just have to pass a reference to the same function to those two separate bindings. But you would have to confirm through testing that CodeMirror doesn’t fire a “Ctrl+S” keybinding when “Ctrl+Alt+S” is pressed.
Though isn't the special case just for not interfering with typing of special characters? I suppose you don't write a lot of special characters in JavaScript code normally, right?
Yes, handling Ctrl+Alt+S correctly lets users type special characters, which are not normally used in JavaScript. But it is possible that programmers would write foreign-language strings like console.log("Winda zatrzymała") or comments like // ten kod nie działa, especially since they are writing the elevator algorithm just for themselves. Supporting typing of foreign languages seems like the right thing to do, even though it will rarely be used, to avoid making some foreign-language programmer annoyed.
A more likely problem is that Ctrl+Alt+S might be bound to a user command. In Firefox for Mac, Command+Alt+S is bound to opening the JavaScript debugger, and the Windows keybinding is probably the same with Command changed to Ctrl. A user might write their code and then type Ctrl+Alt+S to open the debugger. They would be annoyed if it their code was saved instead, because they would have to open the debugger from the menu with the mouse.
Browsers seem to capture this event on a very high level, probably need keypress event handler outside codemirror.