Skip to content

Commit

Permalink
Revert "Pop up shortcuts on meta hold"
Browse files Browse the repository at this point in the history
  • Loading branch information
krschacht committed May 15, 2024
1 parent e840d1d commit 88e1590
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 44 deletions.
43 changes: 0 additions & 43 deletions app/javascript/stimulus/modal_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "dialog" ]

connect() {
window.addEventListener('blur', this.boundEndDelayedModal)
document.addEventListener('mousedown', this.boundEndDelayedModal)
}

disconnect() {
window.removeEventListener('blur', this.boundEndDelayedModal)
document.removeEventListener('mousedown', this.boundEndDelayedModal)
}

open() {
let element

Expand All @@ -24,41 +14,8 @@ export default class extends Controller {
element.showModal()
}

close() {
let element

if (this.hasDialogTarget)
element = this.dialogTarget
else
element = this.element

element.close()
}

keydownQuestionOpen(event) {
this.endDelayedModal()
this.startDelayedModal(event)

if (event.key != '?' || !event.shiftKey || ["INPUT", "TEXTAREA"].includes(event.target.tagName)) return
this.open()
}

keyupQuestionClose(event) {
this.endDelayedModal()
}

startDelayedModal(event) {
if (event.key == 'Meta' || event.key == 'Control') {
this.holdingHandler = runAfter(1, () => this.open())
this.questionDialog = this
}
}

boundEndDelayedModal = () => { this.endDelayedModal() }
endDelayedModal() {
if (this.holdingHandler) {
this.holdingHandler.end()
this.close()
}
}
}
2 changes: 1 addition & 1 deletion app/views/messages/_main_column.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@
id="tooltip-dialog"
class="modal no-focus-outline"
data-controller="modal"
data-action="keydown@document->modal#keydownQuestionOpen keyup@document->modal#keyupQuestionClose"
data-action="keydown@document->modal#keydownQuestionOpen"
>
<main class="modal-box max-w-5xl">
<header class="font-bold text-lg mb-5">
Expand Down

0 comments on commit 88e1590

Please sign in to comment.