diff --git a/app/assets/javascripts/discourse/components/composer-title.js.es6 b/app/assets/javascripts/discourse/components/composer-title.js.es6 index 8ede0fd3d69..3d806ca0f7d 100644 --- a/app/assets/javascripts/discourse/components/composer-title.js.es6 +++ b/app/assets/javascripts/discourse/components/composer-title.js.es6 @@ -1,12 +1,12 @@ -import { default as computed, on } from 'ember-addons/ember-computed-decorators'; +import computed from 'ember-addons/ember-computed-decorators'; import InputValidation from 'discourse/models/input-validation'; export default Ember.Component.extend({ classNames: ['title-input'], - @on('didInsertElement') - _focusOnTitle() { - if (!this.capabilities.isIOS) { + didInsertElement() { + this._super(); + if (this.get('focusTarget') === 'title') { this.$('input').putCursorAtEnd(); } }, diff --git a/app/assets/javascripts/discourse/components/composer-user-selector.js.es6 b/app/assets/javascripts/discourse/components/composer-user-selector.js.es6 index d977d6e3093..4d440091f56 100644 --- a/app/assets/javascripts/discourse/components/composer-user-selector.js.es6 +++ b/app/assets/javascripts/discourse/components/composer-user-selector.js.es6 @@ -5,6 +5,14 @@ export default Ember.Component.extend({ shouldHide: false, defaultUsernameCount: 0, + didInsertElement() { + this._super(); + + if (this.get('focusTarget') === 'usernames') { + this.$('input').putCursorAtEnd(); + } + }, + @observes('usernames') _checkWidth() { let width = 0; diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6 index 0903a274719..f896464a18e 100644 --- a/app/assets/javascripts/discourse/controllers/composer.js.es6 +++ b/app/assets/javascripts/discourse/controllers/composer.js.es6 @@ -64,6 +64,21 @@ export default Ember.Controller.extend({ topic: null, linkLookup: null, + @computed('model.replyingToTopic', 'model.creatingPrivateMessage', 'model.targetUsernames') + focusTarget(replyingToTopic, creatingPM, usernames) { + if (this.capabilities.isIOS) { return "none"; } + + if (creatingPM && usernames === this.currentUser.get('username')) { + return 'usernames'; + } + + if (replyingToTopic) { + return 'reply'; + } + + return 'title'; + }, + showToolbar: Em.computed({ get(){ const keyValueStore = this.container.lookup('key-value-store:main'); diff --git a/app/assets/javascripts/discourse/templates/composer.hbs b/app/assets/javascripts/discourse/templates/composer.hbs index 0680e931a12..acb26b18540 100644 --- a/app/assets/javascripts/discourse/templates/composer.hbs +++ b/app/assets/javascripts/discourse/templates/composer.hbs @@ -49,9 +49,9 @@
{{#if model.creatingPrivateMessage}} {{composer-user-selector topicId=topicModel.id - usernames=model.targetUsernames - hasGroups=model.hasTargetGroups - }} + usernames=model.targetUsernames + hasGroups=model.hasTargetGroups + focusTarget=focusTarget}} {{#if showWarning}}