From 06abecdb418fe2f34a1e957b3ea09c19bcf5c727 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 28 Feb 2019 16:41:31 +1100 Subject: [PATCH] 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. --- .../controllers/preferences/interface.js.es6 | 7 ++----- app/assets/javascripts/discourse/lib/utilities.js.es6 | 11 +++++++++++ .../discourse/mixins/key-enter-escape.js.es6 | 10 +++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/preferences/interface.js.es6 b/app/assets/javascripts/discourse/controllers/preferences/interface.js.es6 index 16f1c8b19d..3b9d6e6a63 100644 --- a/app/assets/javascripts/discourse/controllers/preferences/interface.js.es6 +++ b/app/assets/javascripts/discourse/controllers/preferences/interface.js.es6 @@ -10,7 +10,7 @@ import { setLocalTheme } from "discourse/lib/theme-selector"; import { popupAjaxError } from "discourse/lib/ajax-error"; -import { safariHacksDisabled } from "discourse/lib/utilities"; +import { safariHacksDisabled, isiPad } from "discourse/lib/utilities"; const USER_HOMES = { 1: "latest", @@ -49,10 +49,7 @@ export default Ember.Controller.extend(PreferencesTabController, { @computed() isiPad() { - return ( - navigator.userAgent.match(/iPad/g) && - !navigator.userAgent.match(/Trident/g) - ); + return isiPad(); }, @computed() diff --git a/app/assets/javascripts/discourse/lib/utilities.js.es6 b/app/assets/javascripts/discourse/lib/utilities.js.es6 index 23e024874f..60fbf6d7d2 100644 --- a/app/assets/javascripts/discourse/lib/utilities.js.es6 +++ b/app/assets/javascripts/discourse/lib/utilities.js.es6 @@ -550,6 +550,17 @@ export function isAppleDevice() { ); } +let iPadDetected = undefined; + +export function isiPad() { + if (iPadDetected === undefined) { + iPadDetected = + navigator.userAgent.match(/iPad/g) && + !navigator.userAgent.match(/Trident/g); + } + return iPadDetected; +} + export function safariHacksDisabled() { let pref = localStorage.getItem("safari-hacks-disabled"); let result = false; diff --git a/app/assets/javascripts/discourse/mixins/key-enter-escape.js.es6 b/app/assets/javascripts/discourse/mixins/key-enter-escape.js.es6 index 8019870114..d3949f9581 100644 --- a/app/assets/javascripts/discourse/mixins/key-enter-escape.js.es6 +++ b/app/assets/javascripts/discourse/mixins/key-enter-escape.js.es6 @@ -1,11 +1,19 @@ +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)) { + } 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; }