From 6c7e46a32fa9c652130a1959b4be798ad297d7dc Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Fri, 26 Apr 2024 16:42:22 +0200 Subject: [PATCH] DEV: Remove key-enter-escape mixin (#26759) Was used in only two places, just inline it to unblock conversion to glimmer --- .../discourse/app/components/composer-body.js | 24 ++++++++++++++++-- .../app/components/search-menu/search-term.js | 1 - .../discourse/app/components/topic-title.js | 24 ++++++++++++++++-- .../discourse/app/mixins/key-enter-escape.js | 25 ------------------- 4 files changed, 44 insertions(+), 30 deletions(-) delete mode 100644 app/assets/javascripts/discourse/app/mixins/key-enter-escape.js diff --git a/app/assets/javascripts/discourse/app/components/composer-body.js b/app/assets/javascripts/discourse/app/components/composer-body.js index 45ef331dfef..74b356c3be6 100644 --- a/app/assets/javascripts/discourse/app/components/composer-body.js +++ b/app/assets/javascripts/discourse/app/components/composer-body.js @@ -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); + } + }, }); diff --git a/app/assets/javascripts/discourse/app/components/search-menu/search-term.js b/app/assets/javascripts/discourse/app/components/search-menu/search-term.js index 1c804e3840b..7a399221eb6 100644 --- a/app/assets/javascripts/discourse/app/components/search-menu/search-term.js +++ b/app/assets/javascripts/discourse/app/components/search-menu/search-term.js @@ -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 || diff --git a/app/assets/javascripts/discourse/app/components/topic-title.js b/app/assets/javascripts/discourse/app/components/topic-title.js index 4328da817da..107590f7f69 100644 --- a/app/assets/javascripts/discourse/app/components/topic-title.js +++ b/app/assets/javascripts/discourse/app/components/topic-title.js @@ -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); + } + }, }); diff --git a/app/assets/javascripts/discourse/app/mixins/key-enter-escape.js b/app/assets/javascripts/discourse/app/mixins/key-enter-escape.js deleted file mode 100644 index 5c80b74b7d9..00000000000 --- a/app/assets/javascripts/discourse/app/mixins/key-enter-escape.js +++ /dev/null @@ -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; - } - }, -};