DEV: removes a setTimeout and ensure shorcut is not propagated (#9702)

This commit is contained in:
Joffrey JAFFEUX 2020-05-08 16:46:13 +02:00 committed by GitHub
parent e46bf15407
commit 646bee2efe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 21 deletions

View File

@ -23,7 +23,7 @@ import { shortDate } from "discourse/lib/formatter";
import { SAVE_LABELS, SAVE_ICONS } from "discourse/models/composer";
import { Promise } from "rsvp";
import ENV from "discourse-common/config/environment";
import EmberObject, { computed } from "@ember/object";
import EmberObject, { computed, action } from "@ember/object";
import deprecated from "discourse-common/lib/deprecated";
function loadDraft(store, opts) {
@ -219,26 +219,26 @@ export default Controller.extend({
isWhispering: or("replyingToWhisper", "model.whisper"),
@discourseComputed("model.action", "isWhispering")
saveIcon(action, isWhispering) {
saveIcon(modelAction, isWhispering) {
if (isWhispering) return "far-eye-slash";
return SAVE_ICONS[action];
return SAVE_ICONS[modelAction];
},
@discourseComputed("model.action", "isWhispering", "model.editConflict")
saveLabel(action, isWhispering, editConflict) {
saveLabel(modelAction, isWhispering, editConflict) {
if (editConflict) return "composer.overwrite_edit";
else if (isWhispering) return "composer.create_whisper";
return SAVE_LABELS[action];
return SAVE_LABELS[modelAction];
},
@discourseComputed("isStaffUser", "model.action")
canWhisper(isStaffUser, action) {
canWhisper(isStaffUser, modelAction) {
return (
this.siteSettings.enable_whispers &&
isStaffUser &&
Composer.REPLY === action
Composer.REPLY === modelAction
);
},
@ -329,6 +329,20 @@ export default Controller.extend({
return uploadIcon(this.currentUser.staff);
},
@action
openIfDraft(event) {
if (this.get("model.viewDraft")) {
// when called from shortcut, ensure we don't propagate the key to
// the composer input title
if (event) {
event.preventDefault();
event.stopPropagation();
}
this.set("model.composeState", Composer.OPEN);
}
},
actions: {
togglePreview() {
this.toggleProperty("showPreview");
@ -368,8 +382,8 @@ export default Controller.extend({
this.set("model.uploadCancelled", true);
},
onPopupMenuAction(action) {
this.send(action);
onPopupMenuAction(menuAction) {
this.send(menuAction);
},
storeToolbarState(toolbarEvent) {
@ -539,12 +553,6 @@ export default Controller.extend({
}
},
openIfDraft() {
if (this.get("model.viewDraft")) {
this.set("model.composeState", Composer.OPEN);
}
},
groupsMentioned(groups) {
if (
!this.get("model.creatingPrivateMessage") &&
@ -1161,8 +1169,8 @@ export default Controller.extend({
},
@discourseComputed("model.action")
canEdit(action) {
return action === "edit" && this.currentUser.can_edit;
canEdit(modelAction) {
return modelAction === "edit" && this.currentUser.can_edit;
},
@discourseComputed("model.composeState")

View File

@ -3,7 +3,7 @@ import DiscourseURL from "discourse/lib/url";
import Composer from "discourse/models/composer";
import { minimumOffset } from "discourse/lib/offset-calculator";
import { ajax } from "discourse/lib/ajax";
import { throttle } from "@ember/runloop";
import { throttle, schedule } from "@ember/runloop";
import { INPUT_DELAY } from "discourse-common/config/environment";
const DEFAULT_BINDINGS = {
@ -330,12 +330,17 @@ export default {
});
},
focusComposer() {
focusComposer(event) {
const composer = this.container.lookup("controller:composer");
if (composer.get("model.viewOpen")) {
setTimeout(() => $("textarea.d-editor-input").focus(), 0);
preventKeyboardEvent(event);
schedule("afterRender", () => {
const input = document.querySelector("textarea.d-editor-input");
input && input.focus();
});
} else {
composer.send("openIfDraft");
composer.openIfDraft(event);
}
},