1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 18:39:51 +02:00

fix: marks at the start of the selection (#5725)

* fix: marks at the start of the selection

* chore: modify unit test description
This commit is contained in:
Czy
2024-09-26 15:21:49 +08:00
committed by GitHub
parent 85a1e1d3f3
commit f31167cf5f
3 changed files with 45 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
'slate': patch
---
fix marks at the start of the selection

View File

@@ -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.

View File

@@ -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 }