Skip to content

Commit

Permalink
revert: "revert: "fix(vue-3): fix editor.state updating too late duri…
Browse files Browse the repository at this point in the history
…ng a transaction due to reactiveState fixes #4870 (#5252)""

This reverts commit dbab8e4.
  • Loading branch information
nperez0111 committed Jul 22, 2024
1 parent a64cbf8 commit 260376a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@ export class Editor extends EventEmitter<EditorEvents> {
const state = this.state.apply(transaction)
const selectionHasChanged = !this.state.selection.eq(state.selection)

this.emit('beforeTransaction', {
editor: this,
transaction,
nextState: state,
})
this.view.updateState(state)
this.emit('transaction', {
editor: this,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface EditorEvents {
}
update: { editor: Editor; transaction: Transaction }
selectionUpdate: { editor: Editor; transaction: Transaction }
beforeTransaction: { editor: Editor; transaction: Transaction, nextState: EditorState }
transaction: { editor: Editor; transaction: Transaction }
focus: { editor: Editor; event: FocusEvent; transaction: Transaction }
blur: { editor: Editor; event: FocusEvent; transaction: Transaction }
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-3/src/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export class Editor extends CoreEditor {
this.reactiveState = useDebouncedRef(this.view.state)
this.reactiveExtensionStorage = useDebouncedRef(this.extensionStorage)

this.on('transaction', () => {
this.reactiveState.value = this.view.state
this.on('beforeTransaction', ({ nextState }) => {
this.reactiveState.value = nextState
this.reactiveExtensionStorage.value = this.extensionStorage
})

Expand Down

0 comments on commit 260376a

Please sign in to comment.