Skip to content

Commit

Permalink
Fix firefox newline crash (#5549)
Browse files Browse the repository at this point in the history
  • Loading branch information
12joan committed Nov 9, 2023
1 parent 47498cf commit f9cca97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-chefs-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

Firefox compat: Fix incorrect focus.offset when text node ends with \n
11 changes: 11 additions & 0 deletions packages/slate-react/src/plugin/react-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,17 @@ export const ReactEditor: ReactEditorInterface = {
)
}

// COMPAT: Firefox sometimes includes an extra \n (rendered by TextString
// when isTrailing is true) in the focusOffset, resulting in an invalid
// Slate point. (2023/11/01)
if (
IS_FIREFOX &&
focusNode.textContent?.endsWith('\n\n') &&
focusOffset === focusNode.textContent.length
) {
focusOffset--
}

// COMPAT: Triple-clicking a word in chrome will sometimes place the focus
// inside a `contenteditable="false"` DOM node following the word, which
// will cause `toSlatePoint` to throw an error. (2023/03/07)
Expand Down

0 comments on commit f9cca97

Please sign in to comment.