Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: marks at the start of the selection #5725

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
Loading