Skip to content

Commit

Permalink
fix: marks at the start of the selection (#5725)
Browse files Browse the repository at this point in the history
* fix: marks at the start of the selection

* chore: modify unit test description
  • Loading branch information
WindRunnerMax authored Sep 26, 2024
1 parent 85a1e1d commit f31167c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-falcons-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate': patch
---

fix marks at the start of the selection
4 changes: 4 additions & 0 deletions packages/slate/src/editor/marks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export const marks: EditorInterface['marks'] = (editor, options = {}) => {
}

if (Range.isExpanded(selection)) {
const isBackward = Range.isBackward(selection)
if (isBackward) {
;[focus, anchor] = [anchor, focus]
}
/**
* COMPAT: Make sure hanging ranges (caused by double clicking in Firefox)
* do not adversely affect the returned marks.
Expand Down
36 changes: 36 additions & 0 deletions packages/slate/test/interfaces/Editor/marks/focus-block-end.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/** @jsx jsx */
import { Editor } from 'slate'
import { jsx } from '../../..'

/**
* Similar to firefox-double-click.tsx, when the selection is at the end of
* the previous node's path, using Editor.marks retrieves the marks of that node.
* However, when addMark is triggered, that node is not within the range for
* adding marks, thus failing to transfer the state correctly.
*/

export const input = (
<editor>
<block>
<text>
block one
<focus />
</text>
</block>
<block>
<text bold>block two</text>
</block>
<block>
<text bold>
block three
<anchor />
</text>
</block>
</editor>
)

export const test = editor => {
return Editor.marks(editor)
}

export const output = { bold: true }

0 comments on commit f31167c

Please sign in to comment.