Make hotkeys activate only when not using inputs

This commit is contained in:
Stanko K.R.
2025-08-18 20:23:00 +02:00
parent a580a0ddbf
commit dcffe706a3
2 changed files with 26 additions and 9 deletions
+24 -7
View File
@@ -20,15 +20,32 @@ export default class extends Controller {
this.#clearTurboFrame()
}
search() {
this.#openInTurboFrame(this.searchTurboFrameNameValue, this.searchUrlValue)
this.dialogOutlet.open()
search(event) {
if (this.#shouldExecuteHotkey) {
event.preventDefault()
this.#openInTurboFrame(this.searchTurboFrameNameValue, this.searchUrlValue)
this.dialogOutlet.open()
}
}
async ask() {
this.#initializeConversation()
this.#openInTurboFrame(this.askTurboFrameNameValue, this.askUrlValue)
this.dialogOutlet.open()
ask(event) {
if (this.#shouldExecuteHotkey) {
event.preventDefault()
this.#initializeConversation()
this.#openInTurboFrame(this.askTurboFrameNameValue, this.askUrlValue)
this.dialogOutlet.open()
}
}
get #shouldExecuteHotkey() {
const activeElement = document.activeElement
if (activeElement) {
const usingInput = activeElement.closest("input, textarea, lexical-editor")
return !usingInput
} else {
return true
}
}
#clearTurboFrame() {