Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
12joan committed Dec 9, 2023
1 parent 82b7cde commit a58c546
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/slate/src/editor/marks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,26 @@ export const marks: EditorInterface['marks'] = (editor, options = {}) => {
}

if (Range.isExpanded(selection)) {
/**
* COMPAT: Make sure hanging ranges (caused by double clicking in Firefox)
* do not adversely affect the returned marks.
*/
const isEnd = Editor.isEnd(editor, anchor, anchor.path)
if (isEnd) {
const after = Editor.after(editor, anchor as Point)
// Editor.after() might return undefined
anchor = after || anchor
if (after) {
anchor = after
}
}

const [match] = Editor.nodes(editor, {
match: Text.isText,
at: {
anchor,
focus,
},
})

if (match) {
const [node] = match as NodeEntry<Text>
const { text, ...rest } = node
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/** @jsx jsx */
import { Editor } from 'slate'
import { jsx } from '../../..'

/**
* This test verifies that when double clicking a marked word in Firefox,
* Editor.marks for the resulting selection includes the marked word. Double
* clicking a marked word in Firefox results in a selection that starts at the
* end of the previous text node and ends at the end of the marked text node.
*/

export const input = (
<editor>
<block>
plain <anchor />
<text bold>
bold
<focus />
</text>
<text> plain</text>
</block>
<block>block two</block>
</editor>
)
export const test = editor => {
return Editor.marks(editor)
}
export const output = { bold: true }

0 comments on commit a58c546

Please sign in to comment.