Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

Let every script that reacts to Escape say when the key is its own

Guido Boyke17c679605160
diff --git a/app/javascript/controllers/admin_user_delete_modal_controller.js b/app/javascript/controllers/admin_user_delete_modal_controller.js
index 2f6b9c9..36676c0 100644
--- a/app/javascript/controllers/admin_user_delete_modal_controller.js
+++ b/app/javascript/controllers/admin_user_delete_modal_controller.js
@@ -32,8 +32,13 @@ export default class extends Controller {
if (event.target === event.currentTarget) this.close()
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasModalTarget && !this.modalTarget.classList.contains("hidden")
+ }
+
closeOnEscape(event) {
- if (event.key === "Escape" && !this.modalTarget.classList.contains("hidden")) this.close()
+ if (event.key === "Escape" && this.ownsEscape()) this.close()
}
validate() {
diff --git a/app/javascript/controllers/assistant_panel_controller.js b/app/javascript/controllers/assistant_panel_controller.js
index c99278a..126e0a2 100644
--- a/app/javascript/controllers/assistant_panel_controller.js
+++ b/app/javascript/controllers/assistant_panel_controller.js
@@ -319,6 +319,12 @@ export default class extends Controller {
else if (this.hasCapsuleInputTarget) this.capsuleInputTarget.focus()
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // Its Escape is bound to the panel, so only a key pressed inside it counts.
+ ownsEscape() {
+ return this.openValue && this.hasPanelTarget && this.panelTarget.contains(document.activeElement)
+ }
+
// Escape closes, like every other layer here. Bound to the panel, not to the
// document: a modal opened on top of the page must keep its own Escape.
closeOnEscape(event) {
diff --git a/app/javascript/controllers/billing_modal_controller.js b/app/javascript/controllers/billing_modal_controller.js
index 6b51712..75d3cd1 100644
--- a/app/javascript/controllers/billing_modal_controller.js
+++ b/app/javascript/controllers/billing_modal_controller.js
@@ -82,8 +82,13 @@ export default class extends Controller {
}
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasModalTarget && !this.modalTarget.classList.contains("hidden")
+ }
+
closeOnEscape(event) {
- if (event.key === "Escape" && !this.modalTarget.classList.contains("hidden")) {
+ if (event.key === "Escape" && this.ownsEscape()) {
this.close()
}
}
diff --git a/app/javascript/controllers/changelog_lightbox_controller.js b/app/javascript/controllers/changelog_lightbox_controller.js
index 4d0d87c..e52828e 100644
--- a/app/javascript/controllers/changelog_lightbox_controller.js
+++ b/app/javascript/controllers/changelog_lightbox_controller.js
@@ -20,6 +20,11 @@ export default class extends Controller {
document.body.classList.remove("overflow-hidden")
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasOverlayTarget && !this.overlayTarget.classList.contains("hidden")
+ }
+
// Close on Escape key
keydown(event) {
if (event.key === "Escape") this.close()
diff --git a/app/javascript/controllers/cockpit_settings_modal_controller.js b/app/javascript/controllers/cockpit_settings_modal_controller.js
index 87e5784..94a702e 100644
--- a/app/javascript/controllers/cockpit_settings_modal_controller.js
+++ b/app/javascript/controllers/cockpit_settings_modal_controller.js
@@ -31,8 +31,13 @@ export default class extends Controller {
if (event.target === event.currentTarget) this.close()
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasModalTarget && !this.modalTarget.classList.contains("hidden")
+ }
+
closeOnEscape(event) {
- if (event.key === "Escape" && !this.modalTarget.classList.contains("hidden")) this.close()
+ if (event.key === "Escape" && this.ownsEscape()) this.close()
}
// Grey out + disable the importance radios while "show actions" is unchecked.
diff --git a/app/javascript/controllers/column_picker_controller.js b/app/javascript/controllers/column_picker_controller.js
index eb6e4ed..3b4a3b8 100644
--- a/app/javascript/controllers/column_picker_controller.js
+++ b/app/javascript/controllers/column_picker_controller.js
@@ -186,6 +186,11 @@ export default class extends Controller {
document.removeEventListener("pointerdown", this.onPointerDown, true)
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.open
+ }
+
// Escape closes the panel and nothing else: the detail behind it has an
// Escape of its own on window, which runs after this document listener.
onKeydown(event) {
diff --git a/app/javascript/controllers/contextual_help_drawer_controller.js b/app/javascript/controllers/contextual_help_drawer_controller.js
index b56c4c6..b6b7c26 100644
--- a/app/javascript/controllers/contextual_help_drawer_controller.js
+++ b/app/javascript/controllers/contextual_help_drawer_controller.js
@@ -128,8 +128,13 @@ export default class extends Controller {
this.close()
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasOverlayTarget && !this.overlayTarget.classList.contains("hidden")
+ }
+
handleKeydown(event) {
- if (!this.hasOverlayTarget || this.overlayTarget.classList.contains("hidden")) return
+ if (!this.ownsEscape()) return
if (event.key === "Escape") {
this.close()
diff --git a/app/javascript/controllers/dashboard_inline_edit_controller.js b/app/javascript/controllers/dashboard_inline_edit_controller.js
index 0fcba3a..1ccb7b2 100644
--- a/app/javascript/controllers/dashboard_inline_edit_controller.js
+++ b/app/javascript/controllers/dashboard_inline_edit_controller.js
@@ -98,6 +98,13 @@ export default class extends Controller {
this.element.removeEventListener("keydown", this.boundKeydown)
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // Its Escape listens on the dashboard, so only a key pressed inside it counts.
+ ownsEscape() {
+ return this.element.contains(document.activeElement) &&
+ Boolean(this.element.querySelector("[data-slot].is-flipped, [data-add-picker-host]:not(.hidden)"))
+ }
+
onKeydown(event) {
if (event.key === "Escape") { this.closeMenus(); return }
const meta = event.metaKey || event.ctrlKey
diff --git a/app/javascript/controllers/detail_settings_modal_controller.js b/app/javascript/controllers/detail_settings_modal_controller.js
index 45f0788..1c23bea 100644
--- a/app/javascript/controllers/detail_settings_modal_controller.js
+++ b/app/javascript/controllers/detail_settings_modal_controller.js
@@ -57,8 +57,13 @@ export default class extends Controller {
}
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasModalTarget && !this.modalTarget.classList.contains("hidden")
+ }
+
closeOnEscape(event) {
- if (event.key === "Escape" && !this.modalTarget.classList.contains("hidden")) {
+ if (event.key === "Escape" && this.ownsEscape()) {
this.close()
}
}
diff --git a/app/javascript/controllers/details_autoclose_controller.js b/app/javascript/controllers/details_autoclose_controller.js
index 837b029..a739500 100644
--- a/app/javascript/controllers/details_autoclose_controller.js
+++ b/app/javascript/controllers/details_autoclose_controller.js
@@ -143,6 +143,11 @@ export default class extends Controller {
}
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.element.open && this.element.contains(document.activeElement)
+ }
+
closeOnEscape(event) {
if (event.key !== "Escape" || !this.element.open) return
// Only act while focus is still inside the open menu. A native <details> does not close
diff --git a/app/javascript/controllers/dropdown_controller.js b/app/javascript/controllers/dropdown_controller.js
index 2f6dbf6..a731fd5 100644
--- a/app/javascript/controllers/dropdown_controller.js
+++ b/app/javascript/controllers/dropdown_controller.js
@@ -93,6 +93,11 @@ export default class extends Controller {
}
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasMenuTarget && !this.menuTarget.classList.contains("hidden")
+ }
+
closeOnEscape(event) {
if (event.key === "Escape") {
this.close()
diff --git a/app/javascript/controllers/filter_bar_controller.js b/app/javascript/controllers/filter_bar_controller.js
index c98daf5..31da106 100644
--- a/app/javascript/controllers/filter_bar_controller.js
+++ b/app/javascript/controllers/filter_bar_controller.js
@@ -1385,12 +1385,22 @@ export default class extends Controller {
if (!this.element.isConnected) return
document.addEventListener('click', this._boundCloseMenus)
document.addEventListener('keydown', this._boundEscape)
+ this._escapeArmed = true
})
}
_disarmOutsideClose() {
document.removeEventListener('click', this._boundCloseMenus)
document.removeEventListener('keydown', this._boundEscape)
+ this._escapeArmed = false
+ }
+
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // True exactly while the Escape listener of an open layer is armed. The
+ // search field's own Escape (closeSearch) folds the field and owns nothing:
+ // the lane closes with it, as it did before.
+ ownsEscape() {
+ return Boolean(this._escapeArmed)
}
_layers() {
diff --git a/app/javascript/controllers/frame_search_controller.js b/app/javascript/controllers/frame_search_controller.js
index f30d958..41272f7 100644
--- a/app/javascript/controllers/frame_search_controller.js
+++ b/app/javascript/controllers/frame_search_controller.js
@@ -135,6 +135,12 @@ export default class extends Controller {
this.setSelectedIndex(-1)
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // Its Escape listens on its own field, so only a key pressed there counts.
+ ownsEscape() {
+ return this.selectedIndex >= 0 && this.element.contains(document.activeElement)
+ }
+
onKeydown(event) {
if (!this.keyboardEnabled) return
const count = this.resultTargets.length
diff --git a/app/javascript/controllers/help_modal_controller.js b/app/javascript/controllers/help_modal_controller.js
index 6dbcc52..68cebf7 100644
--- a/app/javascript/controllers/help_modal_controller.js
+++ b/app/javascript/controllers/help_modal_controller.js
@@ -94,6 +94,11 @@ export default class extends Controller {
}, 200)
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return Boolean(this._modal) && !this._modal.classList.contains("hidden")
+ }
+
handleKeydown(event) {
if (event.key === "Escape") {
this.close()
diff --git a/app/javascript/controllers/image_lightbox_controller.js b/app/javascript/controllers/image_lightbox_controller.js
index d863755..874bf3c 100644
--- a/app/javascript/controllers/image_lightbox_controller.js
+++ b/app/javascript/controllers/image_lightbox_controller.js
@@ -62,6 +62,12 @@ export default class extends Controller {
document.body.style.overflow = 'hidden'
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // The lightbox stands exactly while its Escape listener is attached.
+ ownsEscape() {
+ return Boolean(this.boundEscHandler)
+ }
+
closeLightbox(modal) {
if (modal) {
modal.remove()
diff --git a/app/javascript/controllers/inline_assignees_controller.js b/app/javascript/controllers/inline_assignees_controller.js
index e7eb0a3..6adeaa5 100644
--- a/app/javascript/controllers/inline_assignees_controller.js
+++ b/app/javascript/controllers/inline_assignees_controller.js
@@ -86,6 +86,11 @@ export default class extends Controller {
if (!this.element.contains(event.target)) this.close()
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.isOpen
+ }
+
closeOnEscape(event) {
if (event.key !== "Escape") return
// The menu takes the Escape; the lane behind it stays open (see open()).
diff --git a/app/javascript/controllers/inline_status_controller.js b/app/javascript/controllers/inline_status_controller.js
index a94cee3..f8fab39 100644
--- a/app/javascript/controllers/inline_status_controller.js
+++ b/app/javascript/controllers/inline_status_controller.js
@@ -59,6 +59,11 @@ export default class extends Controller {
}
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasMenuTarget && !this.menuTarget.classList.contains("hidden")
+ }
+
closeOnEscape(event) {
if (event.key === "Escape") {
this.close()
diff --git a/app/javascript/controllers/kanban_board_controller.js b/app/javascript/controllers/kanban_board_controller.js
index 7eb1434..43648eb 100644
--- a/app/javascript/controllers/kanban_board_controller.js
+++ b/app/javascript/controllers/kanban_board_controller.js
@@ -254,6 +254,12 @@ export default class extends Controller {
// === The keys (S3, S4, S6) ===
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // A carried card: Escape puts it back.
+ ownsEscape() {
+ return Boolean(this.carried)
+ }
+
key(event) {
const stop = event.target.closest(STOP_SELECTOR)
if (!stop || !this.element.contains(stop)) return
diff --git a/app/javascript/controllers/meeting_modal_controller.js b/app/javascript/controllers/meeting_modal_controller.js
index 21aaf03..43b9088 100644
--- a/app/javascript/controllers/meeting_modal_controller.js
+++ b/app/javascript/controllers/meeting_modal_controller.js
@@ -127,8 +127,13 @@ export default class extends Controller {
}
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.isOpen
+ }
+
closeOnEscape(event) {
- if (event.key === "Escape" && this.isOpen) {
+ if (event.key === "Escape" && this.ownsEscape()) {
this.close()
}
}
diff --git a/app/javascript/controllers/membership_workspace_controller.js b/app/javascript/controllers/membership_workspace_controller.js
index 23b4e06..94f6b98 100644
--- a/app/javascript/controllers/membership_workspace_controller.js
+++ b/app/javascript/controllers/membership_workspace_controller.js
@@ -67,6 +67,13 @@ export default class extends Controller {
event.target.form.requestSubmit()
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // Its Escape is bound inside the workspace: an open menu, else the open panel.
+ ownsEscape() {
+ return this.element.contains(document.activeElement) &&
+ (this.hasCloseTarget || Boolean(this.element.querySelector("details[open]")))
+ }
+
closeMenu(event) {
event.stopPropagation()
event.currentTarget.open = false
diff --git a/app/javascript/controllers/move_ticket_modal_controller.js b/app/javascript/controllers/move_ticket_modal_controller.js
index f93a25f..a4407ff 100644
--- a/app/javascript/controllers/move_ticket_modal_controller.js
+++ b/app/javascript/controllers/move_ticket_modal_controller.js
@@ -40,8 +40,13 @@ export default class extends Controller {
}
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasModalTarget && !this.modalTarget.classList.contains("hidden")
+ }
+
closeOnEscape(event) {
- if (event.key === "Escape" && this.hasModalTarget && !this.modalTarget.classList.contains("hidden")) {
+ if (event.key === "Escape" && this.ownsEscape()) {
this.close()
}
}
diff --git a/app/javascript/controllers/neo_activity_filter_controller.js b/app/javascript/controllers/neo_activity_filter_controller.js
index 1254747..9758864 100644
--- a/app/javascript/controllers/neo_activity_filter_controller.js
+++ b/app/javascript/controllers/neo_activity_filter_controller.js
@@ -36,6 +36,14 @@ export default class extends Controller {
requestAnimationFrame(() => this.searchInputTarget.focus())
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // The same conditions as closeSearch, bound to the search field.
+ ownsEscape() {
+ return this.hasSearchTarget && this.hasSearchInputTarget &&
+ this.searchTarget.hasAttribute("data-fb-search-open") && !this.searchInputTarget.value &&
+ this.searchTarget.contains(document.activeElement)
+ }
+
closeSearch(event) {
if (this.searchInputTarget.value) return
diff --git a/app/javascript/controllers/neo_ai_disclosure_controller.js b/app/javascript/controllers/neo_ai_disclosure_controller.js
index 795bd3d..2710f8a 100644
--- a/app/javascript/controllers/neo_ai_disclosure_controller.js
+++ b/app/javascript/controllers/neo_ai_disclosure_controller.js
@@ -47,6 +47,12 @@ export default class extends Controller {
}
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // The same two conditions as its Escape listener in connect().
+ ownsEscape() {
+ return this.element.open && this.element.contains(document.activeElement)
+ }
+
disconnect() {
this.stopListening()
}
diff --git a/app/javascript/controllers/neo_autosuggest_controller.js b/app/javascript/controllers/neo_autosuggest_controller.js
index cec48f2..e59661d 100644
--- a/app/javascript/controllers/neo_autosuggest_controller.js
+++ b/app/javascript/controllers/neo_autosuggest_controller.js
@@ -214,6 +214,12 @@ export default class extends Controller {
}
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // Its Escape listens on its own field, so only a key pressed there counts.
+ ownsEscape() {
+ return this.isOpen && this.element.contains(document.activeElement)
+ }
+
handleKeydown(event) {
if (!this.isOpen) {
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
diff --git a/app/javascript/controllers/neo_dropdown_controller.js b/app/javascript/controllers/neo_dropdown_controller.js
index c31fe7b..ff42c64 100644
--- a/app/javascript/controllers/neo_dropdown_controller.js
+++ b/app/javascript/controllers/neo_dropdown_controller.js
@@ -134,6 +134,11 @@ export default class extends Controller {
}
// Keyboard navigation
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return Boolean(this.isOpen)
+ }
+
handleGlobalKeydown(event) {
if (!this.isOpen) return
diff --git a/app/javascript/controllers/neo_inline_popover_controller.js b/app/javascript/controllers/neo_inline_popover_controller.js
index 5997fc7..a9fe6f6 100644
--- a/app/javascript/controllers/neo_inline_popover_controller.js
+++ b/app/javascript/controllers/neo_inline_popover_controller.js
@@ -81,8 +81,13 @@ export default class extends Controller {
}
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasPanelTarget && !this.panelTarget.classList.contains("hidden")
+ }
+
closeOnEscape(event) {
- if (event.key === "Escape" && !this.panelTarget.classList.contains("hidden")) {
+ if (event.key === "Escape" && this.ownsEscape()) {
this.close()
}
}
diff --git a/app/javascript/controllers/neo_writing_surface_controller.js b/app/javascript/controllers/neo_writing_surface_controller.js
index 516fd41..868a92c 100644
--- a/app/javascript/controllers/neo_writing_surface_controller.js
+++ b/app/javascript/controllers/neo_writing_surface_controller.js
@@ -15,6 +15,12 @@ export default class extends Controller {
if (this.hasTitleTarget && !this.titleTarget.value) this.titleTarget.focus()
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // The surface stands in the page only while it is open: closing removes it.
+ ownsEscape() {
+ return true
+ }
+
escape(event) {
// Lexxy and the tag picker use Escape themselves; only react when nothing else did.
if (event.defaultPrevented) return
diff --git a/app/javascript/controllers/new_organisation_modal_controller.js b/app/javascript/controllers/new_organisation_modal_controller.js
index 22c9914..d6dcc25 100644
--- a/app/javascript/controllers/new_organisation_modal_controller.js
+++ b/app/javascript/controllers/new_organisation_modal_controller.js
@@ -35,8 +35,13 @@ export default class extends Controller {
}
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasModalTarget && !this.modalTarget.classList.contains("hidden")
+ }
+
closeOnEscape(event) {
- if (event.key === "Escape" && !this.modalTarget.classList.contains("hidden")) {
+ if (event.key === "Escape" && this.ownsEscape()) {
this.close()
}
}
diff --git a/app/javascript/controllers/personal_tasks_drawer_controller.js b/app/javascript/controllers/personal_tasks_drawer_controller.js
index bf97460..7a7ed63 100644
--- a/app/javascript/controllers/personal_tasks_drawer_controller.js
+++ b/app/javascript/controllers/personal_tasks_drawer_controller.js
@@ -85,8 +85,13 @@ export default class extends Controller {
this.close()
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasOverlayTarget && !this.overlayTarget.classList.contains("hidden")
+ }
+
handleKeydown(event) {
- if (!this.hasOverlayTarget || this.overlayTarget.classList.contains("hidden")) return
+ if (!this.ownsEscape()) return
if (event.key === "Escape") {
this.close()
diff --git a/app/javascript/controllers/post_reaction_tooltip_controller.js b/app/javascript/controllers/post_reaction_tooltip_controller.js
index 4197598..e5183d4 100644
--- a/app/javascript/controllers/post_reaction_tooltip_controller.js
+++ b/app/javascript/controllers/post_reaction_tooltip_controller.js
@@ -32,6 +32,12 @@ export default class extends Controller {
window.addEventListener('resize', this.boundHide)
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // Its Escape listens on its own field, so only a key pressed there counts.
+ ownsEscape() {
+ return Boolean(this.tooltip) && this.element.contains(document.activeElement)
+ }
+
hide(event) {
if (event?.key === 'Escape' && this.tooltip) {
event.preventDefault()
diff --git a/app/javascript/controllers/project_delete_modal_controller.js b/app/javascript/controllers/project_delete_modal_controller.js
index 835e2b0..0c3ce51 100644
--- a/app/javascript/controllers/project_delete_modal_controller.js
+++ b/app/javascript/controllers/project_delete_modal_controller.js
@@ -48,8 +48,13 @@ export default class extends Controller {
}
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasModalTarget && !this.modalTarget.classList.contains("hidden")
+ }
+
closeOnEscape(event) {
- if (event.key === "Escape" && this.hasModalTarget && !this.modalTarget.classList.contains("hidden")) {
+ if (event.key === "Escape" && this.ownsEscape()) {
this.close()
}
}
diff --git a/app/javascript/controllers/search_overlay_controller.js b/app/javascript/controllers/search_overlay_controller.js
index a69ae51..64950c1 100644
--- a/app/javascript/controllers/search_overlay_controller.js
+++ b/app/javascript/controllers/search_overlay_controller.js
@@ -91,9 +91,13 @@ export default class extends Controller {
this.toggle(event)
}
- if (event.key === "Escape" && this.hasOverlayTarget &&
- !this.overlayTarget.classList.contains("hidden")) {
+ if (event.key === "Escape" && this.ownsEscape()) {
this.close()
}
}
+
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasOverlayTarget && !this.overlayTarget.classList.contains("hidden")
+ }
}
diff --git a/app/javascript/controllers/session_timeout_controller.js b/app/javascript/controllers/session_timeout_controller.js
index 63d6492..e39a9a9 100644
--- a/app/javascript/controllers/session_timeout_controller.js
+++ b/app/javascript/controllers/session_timeout_controller.js
@@ -126,6 +126,12 @@ export default class extends Controller {
this.checkSession()
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // The warning holds Escape while it shows (guardEscape).
+ ownsEscape() {
+ return Boolean(this.warningVisible)
+ }
+
guardEscape(event) {
if (!this.warningVisible || event.key !== "Escape") return
event.preventDefault()
diff --git a/app/javascript/controllers/smart_folder_form_controller.js b/app/javascript/controllers/smart_folder_form_controller.js
index 0bfbb8c..9f93b42 100644
--- a/app/javascript/controllers/smart_folder_form_controller.js
+++ b/app/javascript/controllers/smart_folder_form_controller.js
@@ -953,6 +953,13 @@ export default class extends Controller {
}
// Advanced keyboard commands in the tag input
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // Its Escape listens on its own field, so only a key pressed there counts.
+ ownsEscape() {
+ return this.element.contains(document.activeElement) &&
+ Boolean(this.element.querySelector('[data-smart-folder-form-target="tagSuggestions"]:not(.hidden)'))
+ }
+
handleSimpleTagInputKey(event) {
const tagInput = event.target;
const rule = tagInput.closest('.smart-folder-rule');
diff --git a/app/javascript/controllers/smart_folder_modal_controller.js b/app/javascript/controllers/smart_folder_modal_controller.js
index d990ccf..42c8ff3 100644
--- a/app/javascript/controllers/smart_folder_modal_controller.js
+++ b/app/javascript/controllers/smart_folder_modal_controller.js
@@ -24,6 +24,12 @@ export default class extends Controller {
this.element.remove();
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // The modal stands in the page only while it is open: Escape removes it.
+ ownsEscape() {
+ return true
+ }
+
closeOnEsc(event) {
if (event.key === "Escape") {
this.element.remove();
diff --git a/app/javascript/controllers/subscriber_picker_controller.js b/app/javascript/controllers/subscriber_picker_controller.js
index 726376b..310c6ee 100644
--- a/app/javascript/controllers/subscriber_picker_controller.js
+++ b/app/javascript/controllers/subscriber_picker_controller.js
@@ -78,6 +78,11 @@ export default class extends Controller {
}
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasDropdownTarget && !this.dropdownTarget.classList.contains("hidden")
+ }
+
_onKeydown(event) {
if (event.key === "Escape") {
this._close()
diff --git a/app/javascript/controllers/summary_modal_controller.js b/app/javascript/controllers/summary_modal_controller.js
index d28885e..e295604 100644
--- a/app/javascript/controllers/summary_modal_controller.js
+++ b/app/javascript/controllers/summary_modal_controller.js
@@ -25,8 +25,13 @@ export default class extends Controller {
}
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return this.hasModalTarget && !this.modalTarget.classList.contains("hidden")
+ }
+
closeOnEscape(event) {
- if (event.key === "Escape" && !this.modalTarget.classList.contains("hidden")) {
+ if (event.key === "Escape" && this.ownsEscape()) {
this.close()
}
}
diff --git a/app/javascript/controllers/tag_input_controller.js b/app/javascript/controllers/tag_input_controller.js
index 15e999d..716db11 100644
--- a/app/javascript/controllers/tag_input_controller.js
+++ b/app/javascript/controllers/tag_input_controller.js
@@ -287,6 +287,14 @@ export default class extends Controller {
});
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // Its Escape listens on its own field, so only a key pressed there counts.
+ ownsEscape() {
+ const suggestions = this._suggestionsContainer
+ return Boolean(suggestions) && !suggestions.classList.contains('hidden') &&
+ Boolean(suggestions.parentElement?.contains(document.activeElement))
+ }
+
getExistingTagNames(container) {
return Array.from(container.querySelectorAll('.ss-value-text')).map(tag => tag.textContent.toLowerCase());
}
diff --git a/app/javascript/controllers/ticket_bulk_panel_controller.js b/app/javascript/controllers/ticket_bulk_panel_controller.js
index aca9496..66553b7 100644
--- a/app/javascript/controllers/ticket_bulk_panel_controller.js
+++ b/app/javascript/controllers/ticket_bulk_panel_controller.js
@@ -343,6 +343,11 @@ export default class extends Controller {
if (this.hasPickerSearchTarget) this.pickerSearchTarget.value = ""
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ ownsEscape() {
+ return Boolean(this.openedLayer) || (this.hasPickerMenuTarget && !this.pickerMenuTarget.hidden)
+ }
+
// Escape closes what is open: a layer (values or options) first, then the picker.
closePickerOnEscape(event) {
if (event.key !== "Escape") return
diff --git a/app/javascript/controllers/ticket_relation_modal_controller.js b/app/javascript/controllers/ticket_relation_modal_controller.js
index a6a0b62..98c13f1 100644
--- a/app/javascript/controllers/ticket_relation_modal_controller.js
+++ b/app/javascript/controllers/ticket_relation_modal_controller.js
@@ -113,6 +113,12 @@ export default class extends Controller {
if (event.target === event.currentTarget) this.close()
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // The modal is the content of its frame: it stands in the page only while open.
+ ownsEscape() {
+ return true
+ }
+
// An Escape the ticket picker already used (to close its list) closes nothing else.
closeOnEscape(event) {
if (event.key === "Escape" && !event.defaultPrevented) this.close()
diff --git a/app/javascript/controllers/time_sessions_index_controller.js b/app/javascript/controllers/time_sessions_index_controller.js
index 517bbb4..c48d86b 100644
--- a/app/javascript/controllers/time_sessions_index_controller.js
+++ b/app/javascript/controllers/time_sessions_index_controller.js
@@ -168,6 +168,13 @@ export default class extends Controller {
}
}
+ // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
+ // Its Escape is bound to the modal, so only a key pressed inside it counts.
+ ownsEscape() {
+ return this.hasModalTarget && !this.modalTarget.classList.contains("hidden") &&
+ this.modalTarget.contains(document.activeElement)
+ }
+
closeModal(event) {
if (event) event.preventDefault()
diff --git a/app/javascript/lib/escape_owner.js b/app/javascript/lib/escape_owner.js
new file mode 100644
index 0000000..f6250e8
--- /dev/null
+++ b/app/javascript/lib/escape_owner.js
@@ -0,0 +1,32 @@
+// Who takes an Escape. Menus, modals, drawers and the like close on Escape,
+// and so does the detail lane behind them; only the topmost thing may react.
+// Their listeners sit on the element, the document or the window, so the order
+// in which they run proves nothing, and event.defaultPrevented alone depends
+// on that order.
+//
+// The rule, one per owner instead of one list in the lane:
+// * every Stimulus controller that reacts to Escape answers ownsEscape():
+// true while its next Escape would close or undo something of its own;
+// * a layer a script builds outside any controller carries
+// data-owns-escape while it stands in the page;
+// * a native <dialog open> owns it by itself.
+// The lane asks before any listener has run (layout_toggle_controller).
+// Guard: spec/architecture/escape_owner_guard_spec.rb.
+export const OWNS_ESCAPE_ATTRIBUTE = 'data-owns-escape'
+
+export function escapeOwned(controllers, root) {
+ if (root.querySelector(`dialog[open], [${OWNS_ESCAPE_ATTRIBUTE}]`)) return true
+
+ return controllers.some((controller) => typeof controller?.ownsEscape === 'function' && answers(controller))
+}
+
+// One owner that throws must not take Escape away from every lane: it is
+// reported and counts as not owning.
+function answers(controller) {
+ try {
+ return Boolean(controller.ownsEscape())
+ } catch (error) {
+ console.error('ownsEscape() failed', controller.identifier, error)
+ return false
+ }
+}
diff --git a/app/javascript/lib/time_session_modal.js b/app/javascript/lib/time_session_modal.js
index d48c6f3..eb8af8e 100644
--- a/app/javascript/lib/time_session_modal.js
+++ b/app/javascript/lib/time_session_modal.js
@@ -36,6 +36,8 @@ function createOverlay(timeSessionId, onClose) {
if (!overlay) {
overlay = document.createElement('div')
overlay.id = overlayId
+ // Owns Escape while it stands (lib/escape_owner.js): the lane behind stays open.
+ overlay.setAttribute('data-owns-escape', '')
overlay.style.cssText = 'position:fixed;inset:0;z-index:999999;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.5);backdrop-filter:blur(4px)'
overlay.addEventListener('click', (e) => {
diff --git a/config/importmap.rb b/config/importmap.rb
index dda9f86..9958723 100644
--- a/config/importmap.rb
+++ b/config/importmap.rb
@@ -46,6 +46,8 @@ pin 'list_row/address', to: 'lib/list_row/address.js'
# The lane's parameter groups and what Back restores (doc/dateivorschau_plan.md, D9 and D2).
pin 'lane/params', to: 'lib/lane/params.js'
pin 'lane/history', to: 'lib/lane/history.js'
+# Who takes an Escape: the topmost menu, modal or drawer, before the lane.
+pin 'escape_owner', to: 'lib/escape_owner.js'
# The document forms' drop zone: the title a file suggests (S4 of doc/dokumentansicht_plan.md).
pin 'upload_zone/title', to: 'lib/upload_zone/title.js'
# The folder target a type condition becomes (pure, node:test).
diff --git a/spec/architecture/escape_owner_guard_spec.rb b/spec/architecture/escape_owner_guard_spec.rb
new file mode 100644
index 0000000..1c7fe64
--- /dev/null
+++ b/spec/architecture/escape_owner_guard_spec.rb
@@ -0,0 +1,119 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+# What: Every script that reacts to Escape says when that Escape is its own, so the
+# detail lane behind a menu, a modal or a drawer stays open
+# (app/javascript/lib/escape_owner.js).
+# Type: Static guard with a closed list of scripts that react to Escape without
+# owning it, each with its reason.
+# Why: Until 2026-10-17 the lane kept its own list of the overlays that may take
+# Escape first, nine CSS selectors written by hand. Every overlay that was not
+# on it closed the lane behind itself: the "Link" modal of a ticket, the "+"
+# modal of "Alle Meetings" (with an unsaved edit in the lane), the value menu of
+# the filter bar. The list asked the wrong place; the owner knows when it is
+# open.
+#
+# a Stimulus controller that reacts to Escape -> defines ownsEscape()
+# a script that builds a layer outside any controller -> sets data-owns-escape on it
+#
+# What passes, and has to be caught by the person who reads the diff: an ownsEscape()
+# that answers wrong (true while nothing is open keeps the lane open for good), a key
+# read in another spelling than the literal 'Escape' or keyCode 27.
+module EscapeOwnerGuard
+ ESCAPE_KEY = /(['"`])Esc(?:ape)?\1|keyCode\s*===?\s*27|\.esc\b/
+ OWNS_ESCAPE = /^\s+(?:get\s+)?ownsEscape\s*\(\s*\)\s*\{/
+ # A Stimulus action bound to the key in markup: keydown.esc->name#method.
+ TEMPLATE_ESCAPE = /key(?:down|up)\.esc(?:@\w+)?->([\w-]+)#/
+ MARKS_LAYER = /data-owns-escape/
+
+ # Scripts that react to Escape and never own it. Closed: a new script that reacts
+ # to Escape answers ownsEscape(), or comes here with its reason.
+ NOT_OWNERS = {
+ 'app/javascript/controllers/layout_toggle_controller.js' =>
+ 'The lane asks the owners; it is what they are asked about.',
+ 'app/javascript/controllers/keyboard_navigation_controller.js' =>
+ 'Escape on a row goes back to the search field and closes the lane with it, ' \
+ 'as it did before this rule: the row and the lane are left together.',
+ 'app/javascript/controllers/neo_notification_controller.js' =>
+ 'Its Escape case does nothing; the bulk selection handles that key.'
+ }.freeze
+
+ module_function
+
+ def scripts
+ Rails.root.glob('app/javascript/{controllers,lib}/**/*.js').map { |path| path.relative_path_from(Rails.root).to_s }.sort
+ end
+
+ def controller?(path) = path.start_with?('app/javascript/controllers/')
+
+ # The controllers that templates bind to the key, by their files.
+ def bound_in_templates
+ identifiers = Rails.root.glob('app/{views,components}/**/*.{erb,rb}').flat_map { |file| file.read.scan(TEMPLATE_ESCAPE).flatten }
+ identifiers.uniq.map { |identifier| "app/javascript/controllers/#{identifier.gsub('--', '/').tr('-', '_')}_controller.js" }
+ end
+
+ def source(path) = Rails.root.join(path).read
+
+ def reacts_to_escape?(path) = source(path).match?(ESCAPE_KEY)
+
+ def answers?(path)
+ controller?(path) ? source(path).match?(OWNS_ESCAPE) : source(path).match?(MARKS_LAYER)
+ end
+end
+
+RSpec.describe EscapeOwnerGuard do
+ let(:escape_scripts) do
+ (described_class.scripts.select { |path| described_class.reacts_to_escape?(path) } +
+ described_class.bound_in_templates).uniq.sort
+ end
+
+ it 'finds the scripts that react to Escape (the guard is not empty)' do
+ expect(escape_scripts).to include('app/javascript/controllers/meeting_modal_controller.js',
+ 'app/javascript/controllers/filter_bar_controller.js',
+ 'app/javascript/lib/time_session_modal.js',
+ # bound to the key only in its template
+ 'app/javascript/controllers/time_sessions_index_controller.js')
+ expect(escape_scripts.size).to be > 30
+ end
+
+ it 'has every script that reacts to Escape say when the Escape is its own' do
+ silent = escape_scripts.reject do |path|
+ described_class.answers?(path) || described_class::NOT_OWNERS.key?(path)
+ end
+
+ expect(silent).to be_empty, <<~MSG
+ These scripts react to Escape and do not say when it is theirs, so the detail lane
+ closes behind them (app/javascript/lib/escape_owner.js):
+ #{silent.join("\n ")}
+ A controller defines ownsEscape(): true while its next Escape closes or undoes
+ something of its own. A script that builds a layer outside any controller sets
+ data-owns-escape on it while it stands. Only if it never owns the key: add it to
+ NOT_OWNERS with the reason.
+ MSG
+ end
+
+ it 'keeps NOT_OWNERS to scripts that still react to Escape and do not own it' do
+ described_class::NOT_OWNERS.each do |path, reason|
+ expect(Rails.root.join(path)).to exist, "#{path} is gone: remove it from NOT_OWNERS"
+ expect(escape_scripts).to include(path), "#{path} no longer reacts to Escape: remove it"
+ expect(described_class.answers?(path)).to be(false), "#{path} answers ownsEscape() now: remove it from NOT_OWNERS"
+ expect(reason).to be_present
+ end
+ end
+
+ it 'sees the spellings of the key it claims to see' do
+ expect("if (event.key === 'Escape')").to match(described_class::ESCAPE_KEY)
+ expect('case "Esc":').to match(described_class::ESCAPE_KEY)
+ expect('if (event.keyCode === 27)').to match(described_class::ESCAPE_KEY)
+ expect('data-action="keydown.esc@window->x#close"').to match(described_class::ESCAPE_KEY)
+ expect('// Escape closes the menu').not_to match(described_class::ESCAPE_KEY)
+ expect('keydown.esc@window->neo-writing-surface#escape'[described_class::TEMPLATE_ESCAPE, 1]).to eq('neo-writing-surface')
+ end
+
+ it 'finds every controller a template binds to the key' do
+ missing = described_class.bound_in_templates.reject { |path| Rails.root.join(path).exist? }
+
+ expect(missing).to be_empty, "Bound to Escape in a template, but no such controller file: #{missing.join(', ')}"
+ end
+end
diff --git a/spec/javascript/lib/escape_owner.test.js b/spec/javascript/lib/escape_owner.test.js
new file mode 100644
index 0000000..943cc78
--- /dev/null
+++ b/spec/javascript/lib/escape_owner.test.js
@@ -0,0 +1,45 @@
+import { test } from 'node:test'
+import assert from 'node:assert/strict'
+import { escapeOwned, OWNS_ESCAPE_ATTRIBUTE } from '../../../app/javascript/lib/escape_owner.js'
+
+const emptyPage = { querySelector: () => null }
+
+test('nobody owns Escape when no controller claims it and no layer stands', () => {
+ const controllers = [{}, { ownsEscape: () => false }, null]
+
+ assert.equal(escapeOwned(controllers, emptyPage), false)
+})
+
+test('a controller that claims Escape owns it', () => {
+ const controllers = [{ ownsEscape: () => false }, { ownsEscape: () => true }]
+
+ assert.equal(escapeOwned(controllers, emptyPage), true)
+})
+
+test('an open native dialog or a marked layer owns Escape without a controller', () => {
+ let asked = null
+ const page = { querySelector: (selector) => { asked = selector; return {} } }
+
+ assert.equal(escapeOwned([], page), true)
+ assert.match(asked, /dialog\[open\]/)
+ assert.ok(asked.includes(`[${OWNS_ESCAPE_ATTRIBUTE}]`))
+})
+
+test('a property named ownsEscape that is not a method claims nothing', () => {
+ assert.equal(escapeOwned([{ ownsEscape: true }], emptyPage), false)
+})
+
+test('an owner that throws counts as not owning and does not hide the others', () => {
+ const original = console.error
+ const reported = []
+ console.error = (...args) => reported.push(args)
+ try {
+ const broken = { identifier: 'broken', ownsEscape: () => { throw new Error('missing target') } }
+
+ assert.equal(escapeOwned([broken], emptyPage), false)
+ assert.equal(escapeOwned([broken, { ownsEscape: () => true }], emptyPage), true)
+ assert.equal(reported[0][1], 'broken')
+ } finally {
+ console.error = original
+ }
+})