FEATURE: focus on composer TEXTAREA when iPad has a physical keyboard

FEATURE: focus on composer TEXTAREA when iPad has a physical keyboard

This disables a bunch of hacks that bypassed “focus” on iOS (cause focus events that involve a virtual keyboard on iOS cause browser havoc unless a physical keyboard is attached)

Also will focus on title on new topic

diff --git a/app/assets/javascripts/discourse/components/composer-editor.js.es6 b/app/assets/javascripts/discourse/components/composer-editor.js.es6
index c15bd51..c27db9e 100644
--- a/app/assets/javascripts/discourse/components/composer-editor.js.es6
+++ b/app/assets/javascripts/discourse/components/composer-editor.js.es6
@@ -30,7 +30,8 @@ import {
   validateUploadedFiles,
   authorizesOneOrMoreImageExtensions,
   formatUsername,
-  clipboardData
+  clipboardData,
+  safariHacksDisabled
 } from "discourse/lib/utilities";
 import {
   cacheShortUploadUrl,
@@ -201,7 +202,10 @@ export default Ember.Component.extend({
     }
 
     // Focus on the body unless we have a title
-    if (!this.get("composer.canEditTitle") && !this.capabilities.isIOS) {
+    if (
+      !this.get("composer.canEditTitle") &&
+      (!this.capabilities.isIOS || safariHacksDisabled())
+    ) {
       this.$(".d-editor-input").putCursorAtEnd();
     }
 
diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6
index 4b67908..bc9240d 100644
--- a/app/assets/javascripts/discourse/components/d-editor.js.es6
+++ b/app/assets/javascripts/discourse/components/d-editor.js.es6
@@ -12,7 +12,8 @@ import { findRawTemplate } from "discourse/lib/raw-templates";
 import { siteDir } from "discourse/lib/text-direction";
 import {
   determinePostReplaceSelection,
-  clipboardData
+  clipboardData,
+  safariHacksDisabled
 } from "discourse/lib/utilities";
 import toMarkdown from "discourse/lib/to-markdown";
 import deprecated from "discourse-common/lib/deprecated";
@@ -524,7 +525,7 @@ export default Ember.Component.extend({
       const $textarea = this.$("textarea.d-editor-input");
       const textarea = $textarea[0];
       const oldScrollPos = $textarea.scrollTop();
-      if (!this.capabilities.isIOS) {
+      if (!this.capabilities.isIOS || safariHacksDisabled()) {
         $textarea.focus();
       }
       textarea.selectionStart = from;
diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6
index 7ef2397..8156df8 100644
--- a/app/assets/javascripts/discourse/controllers/composer.js.es6
+++ b/app/assets/javascripts/discourse/controllers/composer.js.es6
@@ -12,7 +12,8 @@ import { getOwner } from "discourse-common/lib/get-owner";
 import {
   escapeExpression,
   uploadIcon,
-  authorizesOneOrMoreExtensions
+  authorizesOneOrMoreExtensions,
+  safariHacksDisabled
 } from "discourse/lib/utilities";
 import { emojiUnescape } from "discourse/lib/text";
 import { shortDate } from "discourse/lib/formatter";
@@ -137,7 +138,7 @@ export default Ember.Controller.extend({
     "model.composeState"
   )
   focusTarget(replyingToTopic, creatingPM, usernames, composeState) {
-    if (this.capabilities.isIOS) {
+    if (this.capabilities.isIOS && !safariHacksDisabled()) {
       return "none";
     }

GitHub sha: cdf34657

2 Likes

This commit has been mentioned on Discourse Meta. There might be relevant details there: