mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-10 01:06:37 +02:00
When removing the node containing the cursor, always prefer placing the cursor in a sibling text node (#5923)
* Add tests describing the selection after the current node is removed * Always prefer placing the cursor in a sibling text node after removal * Add changeset
This commit is contained in:
9
.changeset/stupid-ants-buy.md
Normal file
9
.changeset/stupid-ants-buy.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
'slate': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
- When removing a text node containing the cursor, always perfer placing the cursor in a sibling text node if one exists.
|
||||||
|
- Previously, the selection would enter a sibling inline in some circumstances, even when a sibling text node was available.
|
||||||
|
- The most noticeable effect of this change occurs when pressing backspace at the start of line N when the last non-empty node in line N-1 is an inline.
|
||||||
|
- Before, the cursor would be placed inside the inline.
|
||||||
|
- Now, the cursor is placed outside the inline.
|
@@ -246,8 +246,10 @@ export const GeneralTransforms: GeneralTransforms = {
|
|||||||
|
|
||||||
let preferNext = false
|
let preferNext = false
|
||||||
if (prev && next) {
|
if (prev && next) {
|
||||||
if (Path.equals(next[1], path)) {
|
if (Path.isSibling(prev[1], path)) {
|
||||||
preferNext = !Path.hasPrevious(next[1])
|
preferNext = false
|
||||||
|
} else if (Path.equals(next[1], path)) {
|
||||||
|
preferNext = true
|
||||||
} else {
|
} else {
|
||||||
preferNext =
|
preferNext =
|
||||||
Path.common(prev[1], path).length <
|
Path.common(prev[1], path).length <
|
||||||
|
@@ -0,0 +1,37 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
import { jsx } from '../../'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<element>
|
||||||
|
<text />
|
||||||
|
<inline>
|
||||||
|
<text id="0">a</text>
|
||||||
|
<text id="1">
|
||||||
|
<cursor />
|
||||||
|
</text>
|
||||||
|
</inline>
|
||||||
|
<text>b</text>
|
||||||
|
</element>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
export const operations = [
|
||||||
|
{
|
||||||
|
type: 'remove_node',
|
||||||
|
path: [0, 1, 1],
|
||||||
|
node: { text: '', id: '1' },
|
||||||
|
},
|
||||||
|
]
|
||||||
|
export const output = (
|
||||||
|
<editor>
|
||||||
|
<element>
|
||||||
|
<text />
|
||||||
|
<inline>
|
||||||
|
<text id="0">
|
||||||
|
a<cursor />
|
||||||
|
</text>
|
||||||
|
</inline>
|
||||||
|
<text>b</text>
|
||||||
|
</element>
|
||||||
|
</editor>
|
||||||
|
)
|
@@ -0,0 +1,37 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
import { jsx } from '../../'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<element>
|
||||||
|
<text>a</text>
|
||||||
|
<inline>
|
||||||
|
<text id="0">
|
||||||
|
<cursor />
|
||||||
|
</text>
|
||||||
|
<text id="1">b</text>
|
||||||
|
</inline>
|
||||||
|
<text />
|
||||||
|
</element>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
export const operations = [
|
||||||
|
{
|
||||||
|
type: 'remove_node',
|
||||||
|
path: [0, 1, 0],
|
||||||
|
node: { text: '', id: '0' },
|
||||||
|
},
|
||||||
|
]
|
||||||
|
export const output = (
|
||||||
|
<editor>
|
||||||
|
<element>
|
||||||
|
<text>a</text>
|
||||||
|
<inline>
|
||||||
|
<text id="1">
|
||||||
|
<cursor />b
|
||||||
|
</text>
|
||||||
|
</inline>
|
||||||
|
<text />
|
||||||
|
</element>
|
||||||
|
</editor>
|
||||||
|
)
|
@@ -0,0 +1,35 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
import { jsx } from '../../'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<element>a</element>
|
||||||
|
<element>
|
||||||
|
<text>
|
||||||
|
<cursor />
|
||||||
|
</text>
|
||||||
|
<inline>b</inline>
|
||||||
|
<text />
|
||||||
|
</element>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
export const operations = [
|
||||||
|
{
|
||||||
|
type: 'remove_node',
|
||||||
|
path: [1, 0],
|
||||||
|
node: { text: '' },
|
||||||
|
},
|
||||||
|
]
|
||||||
|
export const output = (
|
||||||
|
<editor>
|
||||||
|
<element>a</element>
|
||||||
|
<element>
|
||||||
|
{/* Recreated by normalizer */}
|
||||||
|
<text />
|
||||||
|
<inline>
|
||||||
|
<cursor />b
|
||||||
|
</inline>
|
||||||
|
<text />
|
||||||
|
</element>
|
||||||
|
</editor>
|
||||||
|
)
|
@@ -0,0 +1,33 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
import { jsx } from '../../'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<element>
|
||||||
|
<text />
|
||||||
|
<inline>a</inline>
|
||||||
|
<text id="0">
|
||||||
|
<cursor />
|
||||||
|
</text>
|
||||||
|
<text id="1">b</text>
|
||||||
|
</element>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
export const operations = [
|
||||||
|
{
|
||||||
|
type: 'remove_node',
|
||||||
|
path: [0, 2],
|
||||||
|
node: { text: '', id: '0' },
|
||||||
|
},
|
||||||
|
]
|
||||||
|
export const output = (
|
||||||
|
<editor>
|
||||||
|
<element>
|
||||||
|
<text />
|
||||||
|
<inline>a</inline>
|
||||||
|
<text id="1">
|
||||||
|
<cursor />b
|
||||||
|
</text>
|
||||||
|
</element>
|
||||||
|
</editor>
|
||||||
|
)
|
@@ -0,0 +1,35 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
import { jsx } from '../../'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<element>
|
||||||
|
<text />
|
||||||
|
<inline>a</inline>
|
||||||
|
<text>
|
||||||
|
<cursor />
|
||||||
|
</text>
|
||||||
|
</element>
|
||||||
|
<element>b</element>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
export const operations = [
|
||||||
|
{
|
||||||
|
type: 'remove_node',
|
||||||
|
path: [0, 2],
|
||||||
|
node: { text: '' },
|
||||||
|
},
|
||||||
|
]
|
||||||
|
export const output = (
|
||||||
|
<editor>
|
||||||
|
<element>
|
||||||
|
<text />
|
||||||
|
<inline>
|
||||||
|
a<cursor />
|
||||||
|
</inline>
|
||||||
|
{/* Recreated by normalizer */}
|
||||||
|
<text />
|
||||||
|
</element>
|
||||||
|
<element>b</element>
|
||||||
|
</editor>
|
||||||
|
)
|
@@ -0,0 +1,31 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
import { jsx } from 'slate-hyperscript'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<element>a</element>
|
||||||
|
<element>
|
||||||
|
<text id="0">
|
||||||
|
<cursor />
|
||||||
|
</text>
|
||||||
|
<text id="1">b</text>
|
||||||
|
</element>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
export const operations = [
|
||||||
|
{
|
||||||
|
type: 'remove_node',
|
||||||
|
path: [1, 0],
|
||||||
|
node: { text: '', id: '0' },
|
||||||
|
},
|
||||||
|
]
|
||||||
|
export const output = (
|
||||||
|
<editor>
|
||||||
|
<element>a</element>
|
||||||
|
<element>
|
||||||
|
<text id="1">
|
||||||
|
<cursor />b
|
||||||
|
</text>
|
||||||
|
</element>
|
||||||
|
</editor>
|
||||||
|
)
|
@@ -0,0 +1,33 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
import { jsx } from '../../'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<element>
|
||||||
|
<text id="0">a</text>
|
||||||
|
<text id="1">
|
||||||
|
<cursor />
|
||||||
|
</text>
|
||||||
|
<inline>b</inline>
|
||||||
|
<text />
|
||||||
|
</element>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
export const operations = [
|
||||||
|
{
|
||||||
|
type: 'remove_node',
|
||||||
|
path: [0, 1],
|
||||||
|
node: { text: '', id: '1' },
|
||||||
|
},
|
||||||
|
]
|
||||||
|
export const output = (
|
||||||
|
<editor>
|
||||||
|
<element>
|
||||||
|
<text id="0">
|
||||||
|
a<cursor />
|
||||||
|
</text>
|
||||||
|
<inline>b</inline>
|
||||||
|
<text />
|
||||||
|
</element>
|
||||||
|
</editor>
|
||||||
|
)
|
@@ -0,0 +1,31 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
import { jsx } from 'slate-hyperscript'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<element>
|
||||||
|
<text id="0">a</text>
|
||||||
|
<text id="1">
|
||||||
|
<cursor />
|
||||||
|
</text>
|
||||||
|
</element>
|
||||||
|
<element>b</element>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
export const operations = [
|
||||||
|
{
|
||||||
|
type: 'remove_node',
|
||||||
|
path: [0, 1],
|
||||||
|
node: { text: '', id: '1' },
|
||||||
|
},
|
||||||
|
]
|
||||||
|
export const output = (
|
||||||
|
<editor>
|
||||||
|
<element>
|
||||||
|
<text id="0">
|
||||||
|
a<cursor />
|
||||||
|
</text>
|
||||||
|
</element>
|
||||||
|
<element>b</element>
|
||||||
|
</editor>
|
||||||
|
)
|
@@ -0,0 +1,31 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
import { jsx } from 'slate-hyperscript'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<element>
|
||||||
|
<text id="0">a</text>
|
||||||
|
<text id="1">
|
||||||
|
<cursor />
|
||||||
|
</text>
|
||||||
|
<text id="2">b</text>
|
||||||
|
</element>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
export const operations = [
|
||||||
|
{
|
||||||
|
type: 'remove_node',
|
||||||
|
path: [0, 1],
|
||||||
|
node: { text: '', id: '1' },
|
||||||
|
},
|
||||||
|
]
|
||||||
|
export const output = (
|
||||||
|
<editor>
|
||||||
|
<element>
|
||||||
|
<text id="0">
|
||||||
|
a<cursor />
|
||||||
|
</text>
|
||||||
|
<text id="2">b</text>
|
||||||
|
</element>
|
||||||
|
</editor>
|
||||||
|
)
|
@@ -25,10 +25,9 @@ export const output = (
|
|||||||
<block>
|
<block>
|
||||||
<text />
|
<text />
|
||||||
<inline void>
|
<inline void>
|
||||||
<text>
|
<text />
|
||||||
<cursor />
|
|
||||||
</text>
|
|
||||||
</inline>
|
</inline>
|
||||||
|
<cursor />
|
||||||
word
|
word
|
||||||
</block>
|
</block>
|
||||||
</editor>
|
</editor>
|
||||||
|
Reference in New Issue
Block a user