Wrapper for keybindings (codemirror and app) (#2421)
* start Signed-off-by: Jess Frazelle <github@jessfraz.com> * add hotkey wrapper Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
@ -6,6 +6,7 @@ import { isTauri } from 'lib/isTauri'
|
||||
import { writeTextFile } from '@tauri-apps/plugin-fs'
|
||||
import toast from 'react-hot-toast'
|
||||
import { editorManager } from 'lib/singletons'
|
||||
import { KeyBinding } from '@uiw/react-codemirror'
|
||||
|
||||
const PERSIST_CODE_TOKEN = 'persistCode'
|
||||
|
||||
@ -13,6 +14,7 @@ export default class CodeManager {
|
||||
private _code: string = bracket
|
||||
#updateState: (arg: string) => void = () => {}
|
||||
private _currentFilePath: string | null = null
|
||||
private _hotkeys: { [key: string]: () => void } = {}
|
||||
|
||||
constructor() {
|
||||
if (isTauri()) {
|
||||
@ -48,6 +50,20 @@ export default class CodeManager {
|
||||
this.#updateState = setCode
|
||||
}
|
||||
|
||||
registerHotkey(hotkey: string, callback: () => void) {
|
||||
this._hotkeys[hotkey] = callback
|
||||
}
|
||||
|
||||
getCodemirrorHotkeys(): KeyBinding[] {
|
||||
return Object.keys(this._hotkeys).map((key) => ({
|
||||
key,
|
||||
run: () => {
|
||||
this._hotkeys[key]()
|
||||
return false
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
updateCurrentFilePath(path: string) {
|
||||
this._currentFilePath = path
|
||||
}
|
||||
|
Reference in New Issue
Block a user