tiptap/packages/core/src/plugins/focus.ts

29 lines
605 B
TypeScript
Raw Normal View History

2020-08-21 23:32:47 +08:00
import { Plugin } from 'prosemirror-state'
import Editor from '../..'
export default (editor: Editor) => new Plugin({
props: {
attributes: {
tabindex: '0',
},
handleDOMEvents: {
focus: () => {
editor.isFocused = true
const transaction = editor.state.tr.setMeta('focused', true)
editor.view.dispatch(transaction)
return true
},
blur: () => {
editor.isFocused = false
const transaction = editor.state.tr.setMeta('focused', false)
editor.view.dispatch(transaction)
return true
},
},
},
2020-09-24 06:29:05 +08:00
})