UX: Allow CTRL+ENTER to save topic title edits
This commit is contained in:
parent
3964929c75
commit
df213639f1
|
@ -3,8 +3,9 @@ import Composer from 'discourse/models/composer';
|
||||||
import afterTransition from 'discourse/lib/after-transition';
|
import afterTransition from 'discourse/lib/after-transition';
|
||||||
import positioningWorkaround from 'discourse/lib/safari-hacks';
|
import positioningWorkaround from 'discourse/lib/safari-hacks';
|
||||||
import { headerHeight } from 'discourse/components/site-header';
|
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',
|
elementId: 'reply-control',
|
||||||
|
|
||||||
classNameBindings: ['composer.creatingPrivateMessage:private-message',
|
classNameBindings: ['composer.creatingPrivateMessage:private-message',
|
||||||
|
@ -65,17 +66,6 @@ export default Ember.Component.extend({
|
||||||
}, 1000);
|
}, 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')
|
@observes('composeState')
|
||||||
disableFullscreen() {
|
disableFullscreen() {
|
||||||
if (this.get('composeState') !== Composer.OPEN && positioningWorkaround.blur) {
|
if (this.get('composeState') !== Composer.OPEN && positioningWorkaround.blur) {
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
import KeyEnterEscape from 'discourse/mixins/key-enter-escape';
|
||||||
|
|
||||||
|
export default Ember.Component.extend(KeyEnterEscape, {
|
||||||
|
elementId: 'topic-title',
|
||||||
|
});
|
|
@ -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;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
<div class="container">
|
||||||
|
<div class="title-wrapper">
|
||||||
|
{{yield}}
|
||||||
|
</div>
|
||||||
|
{{plugin-outlet name="topic-title" args=(hash model=model)}}
|
||||||
|
</div>
|
|
@ -10,59 +10,53 @@
|
||||||
|
|
||||||
{{#if model.postStream.loaded}}
|
{{#if model.postStream.loaded}}
|
||||||
{{#if model.postStream.firstPostPresent}}
|
{{#if model.postStream.firstPostPresent}}
|
||||||
<div id="topic-title">
|
{{#topic-title cancelled="cancelEditingTopic" save="finishedEditingTopic"}}
|
||||||
<div class="container">
|
{{#if editingTopic}}
|
||||||
|
{{#if model.isPrivateMessage}}
|
||||||
|
<span class="private-message-glyph">{{fa-icon "envelope"}}</span>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<div class="title-wrapper">
|
{{text-field id="edit-title" value=buffered.title maxlength=siteSettings.max_topic_title_length autofocus="true"}}
|
||||||
{{#if editingTopic}}
|
{{#if showCategoryChooser}}
|
||||||
{{#if model.isPrivateMessage}}
|
<br>
|
||||||
|
{{category-chooser valueAttribute="id" value=buffered.category_id}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if canEditTags}}
|
||||||
|
<br>
|
||||||
|
{{tag-chooser tags=buffered.tags categoryId=buffered.category_id}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{plugin-outlet name="edit-topic" args=(hash model=model buffered=buffered)}}
|
||||||
|
|
||||||
|
<br>
|
||||||
|
{{d-button action="finishedEditingTopic" class="btn-primary btn-small submit-edit" icon="check"}}
|
||||||
|
{{d-button action="cancelEditingTopic" class="btn-small cancel-edit" icon="times"}}
|
||||||
|
{{else}}
|
||||||
|
<h1>
|
||||||
|
{{#unless model.is_warning}}
|
||||||
|
<a href={{pmPath}}>
|
||||||
<span class="private-message-glyph">{{fa-icon "envelope"}}</span>
|
<span class="private-message-glyph">{{fa-icon "envelope"}}</span>
|
||||||
{{/if}}
|
</a>
|
||||||
|
{{/unless}}
|
||||||
|
|
||||||
{{text-field id="edit-title" value=buffered.title maxlength=siteSettings.max_topic_title_length autofocus="true"}}
|
{{#if model.details.loaded}}
|
||||||
{{#if showCategoryChooser}}
|
{{topic-status topic=model}}
|
||||||
<br>
|
<a href="{{unbound model.url}}" {{action "jumpTop"}} class="fancy-title">
|
||||||
{{category-chooser valueAttribute="id" value=buffered.category_id}}
|
{{{model.fancyTitle}}}
|
||||||
{{/if}}
|
</a>
|
||||||
|
|
||||||
{{#if canEditTags}}
|
|
||||||
<br>
|
|
||||||
{{tag-chooser tags=buffered.tags categoryId=buffered.category_id}}
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
{{plugin-outlet name="edit-topic" args=(hash model=model buffered=buffered)}}
|
|
||||||
|
|
||||||
<br>
|
|
||||||
{{d-button action="finishedEditingTopic" class="btn-primary btn-small submit-edit" icon="check"}}
|
|
||||||
{{d-button action="cancelEditingTopic" class="btn-small cancel-edit" icon="times"}}
|
|
||||||
{{else}}
|
|
||||||
<h1>
|
|
||||||
{{#unless model.is_warning}}
|
|
||||||
<a href={{pmPath}}>
|
|
||||||
<span class="private-message-glyph">{{fa-icon "envelope"}}</span>
|
|
||||||
</a>
|
|
||||||
{{/unless}}
|
|
||||||
|
|
||||||
{{#if model.details.loaded}}
|
|
||||||
{{topic-status topic=model}}
|
|
||||||
<a href="{{unbound model.url}}" {{action "jumpTop"}} class="fancy-title">
|
|
||||||
{{{model.fancyTitle}}}
|
|
||||||
</a>
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
{{#if model.details.can_edit}}
|
|
||||||
<a href {{action "editTopic"}} class="edit-topic" title="{{i18n "edit"}}">{{fa-icon "pencil"}}</a>
|
|
||||||
{{/if}}
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
{{#unless model.isPrivateMessage}}
|
|
||||||
{{topic-category topic=model class="topic-category"}}
|
|
||||||
{{/unless}}
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
|
||||||
{{plugin-outlet name="topic-title" args=(hash model=model)}}
|
{{#if model.details.can_edit}}
|
||||||
</div>
|
<a href {{action "editTopic"}} class="edit-topic" title="{{i18n "edit"}}">{{fa-icon "pencil"}}</a>
|
||||||
</div>
|
{{/if}}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
{{#unless model.isPrivateMessage}}
|
||||||
|
{{topic-category topic=model class="topic-category"}}
|
||||||
|
{{/unless}}
|
||||||
|
{{/if}}
|
||||||
|
{{/topic-title}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<div class="container posts">
|
<div class="container posts">
|
||||||
|
|
Loading…
Reference in New Issue