Add hot keys feature
This commit is contained in:
parent
435e94c186
commit
016985d2cb
9 changed files with 41 additions and 6 deletions
|
|
@ -6,4 +6,3 @@ import * as bootstrap from "bootstrap"
|
|||
import "trix"
|
||||
import "@rails/actiontext"
|
||||
|
||||
Trix.config.blockAttributes.default.tagName = 'p';
|
||||
22
app/javascript/controllers/hotkey_controller.js
Normal file
22
app/javascript/controllers/hotkey_controller.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { Controller } from "@hotwired/stimulus"
|
||||
import { install } from '@github/hotkey'
|
||||
|
||||
// Connects to data-controller="hotkey"
|
||||
export default class extends Controller {
|
||||
connect() {
|
||||
// Install all the hotkeys on the page
|
||||
console.log("hotkey connect", this.element)
|
||||
this.element.addEventListener("turbo:load", this.handleTurboLoad)
|
||||
for (const el of this.element.parentNode.querySelectorAll('[data-hotkey]')) {
|
||||
console.log(el)
|
||||
install(el)
|
||||
}
|
||||
}
|
||||
|
||||
handleTurboLoad(event) {
|
||||
for (const el of event.getTarget().querySelectorAll('[data-hotkey]')) {
|
||||
console.log(el)
|
||||
install(el)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -22,6 +22,9 @@ application.register("drag", DragController)
|
|||
import HelloController from "./hello_controller"
|
||||
application.register("hello", HelloController)
|
||||
|
||||
import HotkeyController from "./hotkey_controller"
|
||||
application.register("hotkey", HotkeyController)
|
||||
|
||||
import RichTextLinkTargetsController from "./rich_text_link_targets_controller"
|
||||
application.register("rich-text-link-targets", RichTextLinkTargetsController)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue