mirror of
https://github.com/EthanMarti/infio-copilot.git
synced 2026-05-15 12:11:40 +00:00
init
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
||||
import { COMMAND_PRIORITY_LOW, KEY_ENTER_COMMAND } from 'lexical'
|
||||
import { Platform } from 'obsidian'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
export default function OnEnterPlugin({
|
||||
onEnter,
|
||||
onVaultChat,
|
||||
}: {
|
||||
onEnter: (evt: KeyboardEvent) => void
|
||||
onVaultChat?: () => void
|
||||
}) {
|
||||
const [editor] = useLexicalComposerContext()
|
||||
|
||||
useEffect(() => {
|
||||
const removeListener = editor.registerCommand(
|
||||
KEY_ENTER_COMMAND,
|
||||
(evt: KeyboardEvent) => {
|
||||
console.log('onEnter', evt)
|
||||
if (
|
||||
onVaultChat &&
|
||||
(Platform.isMacOS ? evt.metaKey : evt.ctrlKey)
|
||||
) {
|
||||
evt.preventDefault()
|
||||
evt.stopPropagation()
|
||||
onVaultChat()
|
||||
return true
|
||||
}
|
||||
if (evt.shiftKey) {
|
||||
return false
|
||||
}
|
||||
evt.preventDefault()
|
||||
evt.stopPropagation()
|
||||
onEnter(evt)
|
||||
return true
|
||||
},
|
||||
COMMAND_PRIORITY_LOW,
|
||||
)
|
||||
|
||||
return () => {
|
||||
removeListener()
|
||||
}
|
||||
}, [editor, onEnter, onVaultChat])
|
||||
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user