DEV: Remove key-enter-escape mixin (#26759)

Was used in only two places, just inline it to unblock conversion to glimmer
This commit is contained in:
Jarek Radosz 2024-04-26 16:42:22 +02:00 committed by GitHub
parent 9874801f94
commit 6c7e46a32f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 30 deletions

View File

@ -2,7 +2,7 @@ import Component from "@ember/component";
import { cancel, schedule, throttle } from "@ember/runloop";
import { headerOffset } from "discourse/lib/offset-calculator";
import positioningWorkaround from "discourse/lib/safari-hacks";
import KeyEnterEscape from "discourse/mixins/key-enter-escape";
import { isiPad } from "discourse/lib/utilities";
import Composer from "discourse/models/composer";
import discourseDebounce from "discourse-common/lib/debounce";
import discourseLater from "discourse-common/lib/later";
@ -21,7 +21,7 @@ function mouseYPos(e) {
return e.clientY || (e.touches && e.touches[0] && e.touches[0].clientY);
}
export default Component.extend(KeyEnterEscape, {
export default Component.extend({
elementId: "reply-control",
classNameBindings: [
@ -205,4 +205,24 @@ export default Component.extend(KeyEnterEscape, {
click() {
this.openIfDraft();
},
keyDown(e) {
if (document.body.classList.contains("modal-open")) {
return;
}
if (e.key === "Escape") {
e.preventDefault();
this.cancelled();
} else if (
e.key === "Enter" &&
(e.ctrlKey || e.metaKey || (isiPad() && e.altKey))
) {
// Ctrl+Enter or Cmd+Enter
// iPad physical keyboard does not offer Command or Ctrl detection
// so use Alt+Enter
e.preventDefault();
this.save(undefined, e);
}
},
});

View File

@ -77,7 +77,6 @@ export default class SearchTerm extends Component {
this.lastEnterTimestamp &&
Date.now() - this.lastEnterTimestamp < SECOND_ENTER_MAX_DELAY;
// same combination as key-enter-escape mixin
if (
e.ctrlKey ||
e.metaKey ||

View File

@ -1,6 +1,6 @@
import Component from "@ember/component";
import { schedule } from "@ember/runloop";
import KeyEnterEscape from "discourse/mixins/key-enter-escape";
import { isiPad } from "discourse/lib/utilities";
export let topicTitleDecorators = [];
@ -12,7 +12,7 @@ export function resetTopicTitleDecorators() {
topicTitleDecorators.length = 0;
}
export default Component.extend(KeyEnterEscape, {
export default Component.extend({
elementId: "topic-title",
didInsertElement() {
@ -30,4 +30,24 @@ export default Component.extend(KeyEnterEscape, {
}
});
},
keyDown(e) {
if (document.body.classList.contains("modal-open")) {
return;
}
if (e.key === "Escape") {
e.preventDefault();
this.cancelled();
} else if (
e.key === "Enter" &&
(e.ctrlKey || e.metaKey || (isiPad() && e.altKey))
) {
// Ctrl+Enter or Cmd+Enter
// iPad physical keyboard does not offer Command or Ctrl detection
// so use Alt+Enter
e.preventDefault();
this.save(undefined, e);
}
},
});

View File

@ -1,25 +0,0 @@
import { isiPad } from "discourse/lib/utilities";
// A mixin where hitting ESC calls `cancelled` and ctrl+enter calls `save.
export default {
keyDown(e) {
if (document.body.classList.contains("modal-open")) {
return;
}
if (e.which === 27) {
this.cancelled();
return false;
} else if (
e.which === 13 &&
(e.ctrlKey || e.metaKey || (isiPad() && e.altKey))
) {
// CTRL+ENTER or CMD+ENTER
//
// iPad physical keyboard does not offer Command or Control detection
// so use ALT-ENTER
this.save(undefined, e);
return false;
}
},
};