1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-07-31 04:20:26 +02:00

fix point transform for insert_text to account for affinity (#4848)

* fix point transform for insert_text

* add changeset
This commit is contained in:
Samu
2022-02-23 21:08:00 +01:00
committed by GitHub
parent 100448d55c
commit 482b090e6f
9 changed files with 193 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
'slate': minor
---
fix point transform for insert_text operations to account for affinity

View File

@@ -110,7 +110,11 @@ export const Point: PointInterface = {
}
case 'insert_text': {
if (Path.equals(op.path, path) && op.offset <= offset) {
if (
Path.equals(op.path, path) &&
(op.offset < offset ||
(op.offset === offset && affinity === 'forward'))
) {
p.offset += op.text.length
}

View File

@@ -0,0 +1,24 @@
import { Point } from 'slate'
export const input = {
path: [0, 0],
offset: 0,
}
export const test = value => {
return Point.transform(
value,
{
type: 'insert_text',
path: [0, 0],
text: 'a',
offset: 1,
properties: {},
},
{ affinity: 'backward' }
)
}
export const output = {
path: [0, 0],
offset: 0,
}

View File

@@ -0,0 +1,24 @@
import { Point } from 'slate'
export const input = {
path: [0, 0],
offset: 1,
}
export const test = value => {
return Point.transform(
value,
{
type: 'insert_text',
path: [0, 0],
text: 'a',
offset: 1,
properties: {},
},
{ affinity: 'backward' }
)
}
export const output = {
path: [0, 0],
offset: 1,
}

View File

@@ -0,0 +1,24 @@
import { Point } from 'slate'
export const input = {
path: [0, 0],
offset: 1,
}
export const test = value => {
return Point.transform(
value,
{
type: 'insert_text',
path: [0, 0],
text: 'a',
offset: 0,
properties: {},
},
{ affinity: 'backward' }
)
}
export const output = {
path: [0, 0],
offset: 2,
}

View File

@@ -0,0 +1,24 @@
import { Point } from 'slate'
export const input = {
path: [0, 0],
offset: 0,
}
export const test = value => {
return Point.transform(
value,
{
type: 'insert_text',
path: [0, 0],
text: 'a',
offset: 1,
properties: {},
},
{ affinity: 'forward' }
)
}
export const output = {
path: [0, 0],
offset: 0,
}

View File

@@ -0,0 +1,24 @@
import { Point } from 'slate'
export const input = {
path: [0, 0],
offset: 1,
}
export const test = value => {
return Point.transform(
value,
{
type: 'insert_text',
path: [0, 0],
text: 'a',
offset: 1,
properties: {},
},
{ affinity: 'forward' }
)
}
export const output = {
path: [0, 0],
offset: 2,
}

View File

@@ -0,0 +1,24 @@
import { Point } from 'slate'
export const input = {
path: [0, 0],
offset: 1,
}
export const test = value => {
return Point.transform(
value,
{
type: 'insert_text',
path: [0, 0],
text: 'a',
offset: 0,
properties: {},
},
{ affinity: 'forward' }
)
}
export const output = {
path: [0, 0],
offset: 2,
}

View File

@@ -0,0 +1,39 @@
import { Range } from 'slate'
/**
* If a collapsed Range is transformed with affinity outward by an insert_text operation, it should expand.
*/
export const input = {
anchor: {
path: [0, 0],
offset: 1,
},
focus: {
path: [0, 0],
offset: 1,
},
}
export const test = value => {
return Range.transform(
value,
{
type: 'insert_text',
path: [0, 0],
text: 'a',
offset: 1,
properties: {},
},
{ affinity: 'outward' }
)
}
export const output = {
anchor: {
path: [0, 0],
offset: 1,
},
focus: {
path: [0, 0],
offset: 2,
},
}