add basic enter command

This commit is contained in:
Philipp Kühn
2021-02-09 10:06:13 +01:00
parent 2bd3033207
commit e8232dd737
4 changed files with 81 additions and 0 deletions

View File

@@ -307,12 +307,40 @@ export class Editor extends EventEmitter {
return this.createDocument('')
}
public isCapturingTransaction = false
private capturedTransaction: Transaction | null = null
public captureTransaction(fn: Function) {
this.isCapturingTransaction = true
fn()
this.isCapturingTransaction = false
const tr = this.capturedTransaction
this.capturedTransaction = null
return tr
}
/**
* The callback over which to send transactions (state updates) produced by the view.
*
* @param transaction An editor state transaction
*/
private dispatchTransaction(transaction: Transaction): void {
if (this.isCapturingTransaction) {
if (!this.capturedTransaction) {
this.capturedTransaction = transaction
return
}
transaction.steps.forEach(step => this.capturedTransaction?.step(step))
return
}
const state = this.state.apply(transaction)
const selectionHasChanged = !this.state.selection.eq(state.selection)