UX: Allow CTRL+ENTER to save topic title edits

This commit is contained in:
Robin Ward 2017-07-04 14:23:35 -04:00
parent 3964929c75
commit df213639f1
5 changed files with 70 additions and 61 deletions

View File

@ -3,8 +3,9 @@ import Composer from 'discourse/models/composer';
import afterTransition from 'discourse/lib/after-transition';
import positioningWorkaround from 'discourse/lib/safari-hacks';
import { headerHeight } from 'discourse/components/site-header';
import KeyEnterEscape from 'discourse/mixins/key-enter-escape';
export default Ember.Component.extend({
export default Ember.Component.extend(KeyEnterEscape, {
elementId: 'reply-control',
classNameBindings: ['composer.creatingPrivateMessage:private-message',
@ -65,17 +66,6 @@ export default Ember.Component.extend({
}, 1000);
},
keyDown(e) {
if (e.which === 27) {
this.sendAction('cancelled');
return false;
} else if (e.which === 13 && (e.ctrlKey || e.metaKey)) {
// CTRL+ENTER or CMD+ENTER
this.sendAction('save');
return false;
}
},
@observes('composeState')
disableFullscreen() {
if (this.get('composeState') !== Composer.OPEN && positioningWorkaround.blur) {

View File

@ -0,0 +1,5 @@
import KeyEnterEscape from 'discourse/mixins/key-enter-escape';
export default Ember.Component.extend(KeyEnterEscape, {
elementId: 'topic-title',
});

View File

@ -0,0 +1,14 @@
// A mixin where hitting ESC calls `cancelled` and ctrl+enter calls `save.
export default {
keyDown(e) {
if (e.which === 27) {
this.sendAction('cancelled');
return false;
} else if (e.which === 13 && (e.ctrlKey || e.metaKey)) {
// CTRL+ENTER or CMD+ENTER
this.sendAction('save');
return false;
}
},
};

View File

@ -0,0 +1,6 @@
<div class="container">
<div class="title-wrapper">
{{yield}}
</div>
{{plugin-outlet name="topic-title" args=(hash model=model)}}
</div>

View File

@ -10,10 +10,7 @@
{{#if model.postStream.loaded}}
{{#if model.postStream.firstPostPresent}}
<div id="topic-title">
<div class="container">
<div class="title-wrapper">
{{#topic-title cancelled="cancelEditingTopic" save="finishedEditingTopic"}}
{{#if editingTopic}}
{{#if model.isPrivateMessage}}
<span class="private-message-glyph">{{fa-icon "envelope"}}</span>
@ -59,10 +56,7 @@
{{topic-category topic=model class="topic-category"}}
{{/unless}}
{{/if}}
</div>
{{plugin-outlet name="topic-title" args=(hash model=model)}}
</div>
</div>
{{/topic-title}}
{{/if}}
<div class="container posts">