Make hotkeys activate only when not using inputs
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
bar_ask_url_value: conversation_path,
|
||||
bar_ask_turbo_frame_name_value: "conversation",
|
||||
action: "
|
||||
keydown.meta+k@document->bar#search:prevent keydown.ctrl+k@document->bar#search:prevent
|
||||
keydown.meta+a@document->bar#ask:prevent keydown.ctrl+a@document->bar#ask:prevent"
|
||||
keydown.meta+k@document->bar#search keydown.ctrl+k@document->bar#search
|
||||
keydown.meta+a@document->bar#ask keydown.ctrl+a@document->bar#ask"
|
||||
} do %>
|
||||
<div>
|
||||
Search [<%= hotkey_label(["ctrl", "K"]) %>] or Ask [<%= hotkey_label(["ctrl", "A"]) %>]
|
||||
|
||||
Reference in New Issue
Block a user