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 { cancel, schedule, throttle } from "@ember/runloop";
import { headerOffset } from "discourse/lib/offset-calculator"; import { headerOffset } from "discourse/lib/offset-calculator";
import positioningWorkaround from "discourse/lib/safari-hacks"; 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 Composer from "discourse/models/composer";
import discourseDebounce from "discourse-common/lib/debounce"; import discourseDebounce from "discourse-common/lib/debounce";
import discourseLater from "discourse-common/lib/later"; 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); return e.clientY || (e.touches && e.touches[0] && e.touches[0].clientY);
} }
export default Component.extend(KeyEnterEscape, { export default Component.extend({
elementId: "reply-control", elementId: "reply-control",
classNameBindings: [ classNameBindings: [
@ -205,4 +205,24 @@ export default Component.extend(KeyEnterEscape, {
click() { click() {
this.openIfDraft(); 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 && this.lastEnterTimestamp &&
Date.now() - this.lastEnterTimestamp < SECOND_ENTER_MAX_DELAY; Date.now() - this.lastEnterTimestamp < SECOND_ENTER_MAX_DELAY;
// same combination as key-enter-escape mixin
if ( if (
e.ctrlKey || e.ctrlKey ||
e.metaKey || e.metaKey ||

View File

@ -1,6 +1,6 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { schedule } from "@ember/runloop"; import { schedule } from "@ember/runloop";
import KeyEnterEscape from "discourse/mixins/key-enter-escape"; import { isiPad } from "discourse/lib/utilities";
export let topicTitleDecorators = []; export let topicTitleDecorators = [];
@ -12,7 +12,7 @@ export function resetTopicTitleDecorators() {
topicTitleDecorators.length = 0; topicTitleDecorators.length = 0;
} }
export default Component.extend(KeyEnterEscape, { export default Component.extend({
elementId: "topic-title", elementId: "topic-title",
didInsertElement() { 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;
}
},
};