mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-04-16 03:12:48 +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:
parent
100448d55c
commit
482b090e6f
5
.changeset/fast-doors-peel.md
Normal file
5
.changeset/fast-doors-peel.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate': minor
|
||||
---
|
||||
|
||||
fix point transform for insert_text operations to account for affinity
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
}
|
@ -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,
|
||||
}
|
@ -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,
|
||||
}
|
@ -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,
|
||||
}
|
@ -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,
|
||||
}
|
@ -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,
|
||||
}
|
@ -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,
|
||||
},
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user