Skip to content

Commit 8c22e90

Browse files
committed
Add a getter and setter for the undo history state.
1 parent c877804 commit 8c22e90

3 files changed

Lines changed: 45 additions & 37 deletions

File tree

package-lock.json

Lines changed: 30 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,8 @@
6363
"webpack": "^5.106.1",
6464
"webpack-cli": "^7.0.2",
6565
"webpack-dev-server": "^5.2.3"
66+
},
67+
"overrides": {
68+
"uuid": "^14.0.0"
6669
}
6770
}

src/pg-codemirror-editor.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
CommentTokens,
2020
defaultKeymap,
2121
history,
22+
historyField,
2223
historyKeymap,
2324
indentWithTab,
2425
toggleLineComment,
@@ -391,6 +392,17 @@ export class View {
391392
key
392393
});
393394
}
395+
396+
get state() {
397+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
398+
return this.view.state.toJSON({ history: historyField });
399+
}
400+
401+
set state(newState) {
402+
this.view.setState(
403+
EditorState.fromJSON(newState, { doc: this.source, extensions: this.extensions }, { history: historyField })
404+
);
405+
}
394406
}
395407

396408
export const runMode = async (source: string, container: HTMLElement) => {

0 commit comments

Comments
 (0)