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:
5
.changeset/odd-falcons-hang.md
Normal file
5
.changeset/odd-falcons-hang.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate': patch
|
||||
---
|
||||
|
||||
fix marks at the start of the selection
|
@@ -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.
|
||||
|
@@ -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 }
|
Reference in New Issue
Block a user