Skip to content

Commit

Permalink
Added insert_node path checking to match how other operations are app…
Browse files Browse the repository at this point in the history
…lied (#4230)

* Added try/finally to editor.apply and Editor.withoutNormalizing for state cleanup

* Added insert_node path checking to match how other operations are applied
  • Loading branch information
TheSpyder authored May 5, 2021
1 parent c14e1fb commit 796389c
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 228 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-pants-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate': minor
---

Applying invalid `insert_node` operations will now throw an exception for all invalid paths, not just invalid parent paths.
5 changes: 5 additions & 0 deletions .changeset/sixty-glasses-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate': patch
---

Exceptions in `editor.apply()` and `Editor.withoutNormalizing()` will no longer leave the editor in an invalid state
7 changes: 5 additions & 2 deletions packages/slate/src/interfaces/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1648,8 +1648,11 @@ export const Editor: EditorInterface = {
withoutNormalizing(editor: Editor, fn: () => void): void {
const value = Editor.isNormalizing(editor)
NORMALIZING.set(editor, false)
fn()
NORMALIZING.set(editor, value)
try {
fn()
} finally {
NORMALIZING.set(editor, value)
}
Editor.normalize(editor)
},
}
Expand Down
Loading

0 comments on commit 796389c

Please sign in to comment.