WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit c56a98f

Browse files
authored
skip nonselectable nodes when move (#5885)
* skip nonselectable nodes when move * fix * docs * remove ignoreNonSelectable * docs * revert
1 parent 86e1411 commit c56a98f

File tree

13 files changed

+46
-108
lines changed

13 files changed

+46
-108
lines changed

.changeset/nice-deers-hammer.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'slate': minor
3+
---
4+
5+
- Remove `ignoreNonSelectable` option from positions,before,after,nodes.
6+
- Fix move behavior when encounter non-selectable inline voids.

docs/api/nodes/editor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Options: `depth?: number, edge?: 'start' | 'end'`
141141

142142
At any given `Location` or `Span` in the editor provided by `at` (default is the current selection), the method returns a Generator of `NodeEntry` objects that represent the nodes that include `at`. At the top of the hierarchy is the `Editor` object itself.
143143

144-
Options: `{at?: Location | Span, match?: NodeMatch, mode?: 'all' | 'highest' | 'lowest', universal?: boolean, reverse?: boolean, voids?: boolean, pass?: (node: NodeEntry => boolean), ignoreNonSelectable?: boolean}`
144+
Options: `{at?: Location | Span, match?: NodeMatch, mode?: 'all' | 'highest' | 'lowest', universal?: boolean, reverse?: boolean, voids?: boolean, pass?: (node: NodeEntry => boolean)}`
145145

146146
`options.match`: Provide a value to the `match?` option to limit the `NodeEntry` objects that are returned.
147147

packages/slate/src/editor/nodes.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export function* nodes<T extends Node>(
1616
reverse = false,
1717
voids = false,
1818
pass,
19-
ignoreNonSelectable = false,
2019
} = options
2120
let { match } = options
2221

@@ -53,7 +52,7 @@ export function* nodes<T extends Node>(
5352
(Editor.isVoid(editor, node) || Editor.isElementReadOnly(editor, node))
5453
)
5554
return true
56-
if (ignoreNonSelectable && !Editor.isSelectable(editor, node)) return true
55+
5756
return false
5857
},
5958
})
@@ -62,14 +61,6 @@ export function* nodes<T extends Node>(
6261
let hit: NodeEntry<T> | undefined
6362

6463
for (const [node, path] of nodeEntries) {
65-
if (
66-
ignoreNonSelectable &&
67-
Element.isElement(node) &&
68-
!Editor.isSelectable(editor, node)
69-
) {
70-
continue
71-
}
72-
7364
const isLower = hit && Path.compare(path, hit[1]) === 0
7465

7566
// In highest mode any node lower than the last hit is not a match.

packages/slate/src/editor/positions.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export function* positions(
1919
unit = 'offset',
2020
reverse = false,
2121
voids = false,
22-
ignoreNonSelectable = false,
2322
} = options
2423

2524
if (!at) {
@@ -63,12 +62,24 @@ export function* positions(
6362
at,
6463
reverse,
6564
voids,
66-
ignoreNonSelectable,
6765
})) {
6866
/*
6967
* ELEMENT NODE - Yield position(s) for voids, collect blockText for blocks
7068
*/
7169
if (Element.isElement(node)) {
70+
if (!editor.isSelectable(node)) {
71+
/**
72+
* If the node is not selectable, skip it
73+
*/
74+
if (reverse) {
75+
yield Editor.end(editor, Path.previous(path))
76+
continue
77+
} else {
78+
yield Editor.start(editor, Path.next(path))
79+
continue
80+
}
81+
}
82+
7283
// Void nodes are a special case, so by default we will always
7384
// yield their first point. If the `voids` option is set to true,
7485
// then we will iterate over their content.

packages/slate/src/interfaces/editor.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ export interface EditorNodesOptions<T extends Node> {
255255
reverse?: boolean
256256
voids?: boolean
257257
pass?: (entry: NodeEntry) => boolean
258-
ignoreNonSelectable?: boolean
259258
}
260259

261260
export interface EditorNormalizeOptions {
@@ -290,7 +289,6 @@ export interface EditorPositionsOptions {
290289
unit?: TextUnitAdjustment
291290
reverse?: boolean
292291
voids?: boolean
293-
ignoreNonSelectable?: boolean
294292
}
295293

296294
export interface EditorPreviousOptions<T extends Node> {

packages/slate/src/transforms-selection/move.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const move: SelectionTransforms['move'] = (editor, options = {}) => {
2121
}
2222

2323
const { anchor, focus } = selection
24-
const opts = { distance, unit, ignoreNonSelectable: true }
24+
const opts = { distance, unit }
2525
const props: Partial<Range> = {}
2626

2727
if (edge == null || edge === 'anchor') {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/** @jsx jsx */
2+
3+
import { Editor } from 'slate'
4+
import { jsx } from '../../..'
5+
6+
export const input = (
7+
<editor>
8+
<block>
9+
one
10+
<inline void nonSelectable>
11+
<text />
12+
</inline>
13+
three
14+
</block>
15+
</editor>
16+
)
17+
18+
export const test = editor => {
19+
return Editor.after(editor, { path: [0, 0], offset: 3 })
20+
}
21+
22+
export const output = { path: [0, 2], offset: 0 }

packages/slate/test/interfaces/Editor/after/non-selectable-inline.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ export const input = (
1212
)
1313

1414
export const test = editor => {
15-
return Editor.after(
16-
editor,
17-
{ path: [0, 0], offset: 3 },
18-
{ ignoreNonSelectable: true }
19-
)
15+
return Editor.after(editor, { path: [0, 0], offset: 3 })
2016
}
2117

2218
export const output = { path: [0, 2], offset: 0 }

packages/slate/test/interfaces/Editor/before/non-selectable-inline.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ export const input = (
1212
)
1313

1414
export const test = editor => {
15-
return Editor.before(
16-
editor,
17-
{ path: [0, 2], offset: 0 },
18-
{ ignoreNonSelectable: true }
19-
)
15+
return Editor.before(editor, { path: [0, 2], offset: 0 })
2016
}
2117

2218
export const output = { path: [0, 0], offset: 3 }

packages/slate/test/interfaces/Editor/nodes/ignore-non-selectable/block.tsx

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)