diff --git a/app/assets/javascripts/discourse/components/autofocus-text-field.js.es6 b/app/assets/javascripts/discourse/components/autofocus-text-field.js.es6 new file mode 100644 index 000000000..29ecbb0d3 --- /dev/null +++ b/app/assets/javascripts/discourse/components/autofocus-text-field.js.es6 @@ -0,0 +1,7 @@ +export default Ember.TextField.extend({ + becomeFocused: function() { + var input = this.get("element"); + input.focus(); + input.selectionStart = input.selectionEnd = input.value.length; + }.on('didInsertElement') +}); diff --git a/app/assets/javascripts/discourse/templates/topic.hbs b/app/assets/javascripts/discourse/templates/topic.hbs index 5bf289e72..5f251277b 100644 --- a/app/assets/javascripts/discourse/templates/topic.hbs +++ b/app/assets/javascripts/discourse/templates/topic.hbs @@ -17,9 +17,9 @@ {{#if editingTopic}} {{#if isPrivateMessage}} {{fa-icon envelope}} - {{text-field id='edit-title' value=newTitle maxLength=maxTitleLength}} + {{autofocus-text-field id='edit-title' value=newTitle maxLength=maxTitleLength}} {{else}} - {{text-field id='edit-title' value=newTitle maxLength=maxTitleLength}} + {{autofocus-text-field id='edit-title' value=newTitle maxLength=maxTitleLength}}
{{category-chooser valueAttribute="id" value=newCategoryId source=category_id}} {{/if}}