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