This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/mixins/key-enter-escape.js.es6
Sam 06abecdb41 FEATURE: on iPad bluetooth keyboard use ALT-ENTER for post submit
Command and Control can not be properly detected via JavaScript so lean on
Alt that can be detected.
2019-02-28 16:41:31 +11:00

22 lines
529 B
JavaScript

import { isiPad } from "discourse/lib/utilities";
// A mixin where hitting ESC calls `cancelled` and ctrl+enter calls `save.
export default {
keyDown(e) {
if (e.which === 27) {
this.cancelled();
return false;
} else if (
e.which === 13 &&
(e.ctrlKey || e.metaKey || (isiPad() && e.altKey))
) {
// CTRL+ENTER or CMD+ENTER
//
// iPad physical keyboard does not offer Command or Control detection
// so use ALT-ENTER
this.save();
return false;
}
}
};