add focus transaction

This commit is contained in:
Philipp Kühn
2019-07-31 10:10:34 +02:00
parent b77a31a06e
commit ae33e76feb

View File

@@ -73,6 +73,7 @@ export default class Editor extends Emitter {
...this.defaultOptions,
...options,
})
this.focused = false
this.selection = null
this.element = document.createElement('div')
this.extensions = this.createExtensions()
@@ -219,18 +220,26 @@ export default class Editor extends Emitter {
},
handleDOMEvents: {
focus: (view, event) => {
this.focused = true
this.emit('focus', {
event,
state: view.state,
view,
})
const transaction = this.state.tr.setMeta('focused', true)
this.view.dispatch(transaction)
},
blur: (view, event) => {
this.focused = false
this.emit('blur', {
event,
state: view.state,
view,
})
const transaction = this.state.tr.setMeta('focused', false)
this.view.dispatch(transaction)
},
},
},