mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 06:01:24 +02:00
marks on double click selection using firefox fix (#5580)
* fixed: marks on double click selection using firefox * adding changeset * minor -> patch * removing useless platform check * yarn fix * Add test --------- Co-authored-by: Joe Anderson <joe@mousetrapped.co.uk>
This commit is contained in:
5
.changeset/blue-flies-decide.md
Normal file
5
.changeset/blue-flies-decide.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate': patch
|
||||
---
|
||||
|
||||
Fix firefox double-click marks issue
|
@@ -4,6 +4,7 @@ import { Range } from '../interfaces/range'
|
||||
import { Path } from '../interfaces/path'
|
||||
import { Text } from '../interfaces/text'
|
||||
import { Element } from '../interfaces/element'
|
||||
import { Point } from '../interfaces'
|
||||
|
||||
export const marks: EditorInterface['marks'] = (editor, options = {}) => {
|
||||
const { marks, selection } = editor
|
||||
@@ -11,13 +12,32 @@ export const marks: EditorInterface['marks'] = (editor, options = {}) => {
|
||||
if (!selection) {
|
||||
return null
|
||||
}
|
||||
let { anchor, focus } = selection
|
||||
|
||||
if (marks) {
|
||||
return marks
|
||||
}
|
||||
|
||||
if (Range.isExpanded(selection)) {
|
||||
const [match] = Editor.nodes(editor, { match: Text.isText })
|
||||
/**
|
||||
* 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)
|
||||
if (after) {
|
||||
anchor = after
|
||||
}
|
||||
}
|
||||
|
||||
const [match] = Editor.nodes(editor, {
|
||||
match: Text.isText,
|
||||
at: {
|
||||
anchor,
|
||||
focus,
|
||||
},
|
||||
})
|
||||
|
||||
if (match) {
|
||||
const [node] = match as NodeEntry<Text>
|
||||
@@ -28,8 +48,8 @@ export const marks: EditorInterface['marks'] = (editor, options = {}) => {
|
||||
}
|
||||
}
|
||||
|
||||
const { anchor } = selection
|
||||
const { path } = anchor
|
||||
|
||||
let [node] = Editor.leaf(editor, path)
|
||||
|
||||
if (anchor.offset === 0) {
|
||||
|
@@ -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 }
|
Reference in New Issue
Block a user