Skip to content

Commit 790653e

Browse files
committed
refactor
1 parent cd05445 commit 790653e

File tree

9 files changed

+38
-38
lines changed

9 files changed

+38
-38
lines changed

packages/slate/src/interfaces/text.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export type Leaf = Text & {
2222
position?: {
2323
start: number
2424
end: number
25-
isFirst: boolean
26-
isLast: boolean
25+
isFirst?: true
26+
isLast?: true
2727
}
2828
}
2929

@@ -199,12 +199,12 @@ export const Text: TextInterface = {
199199
for (const [index, leaf] of leaves.entries()) {
200200
const start = currentOffset
201201
const end = start + leaf.text.length
202-
leaf.position = {
203-
start,
204-
end,
205-
isFirst: index === 0,
206-
isLast: index === leaves.length - 1,
207-
}
202+
const position: Leaf['position'] = { start, end }
203+
204+
if (index === 0) position.isFirst = true
205+
if (index === leaves.length - 1) position.isLast = true
206+
207+
leaf.position = position
208208
currentOffset = end
209209
}
210210
}

packages/slate/test/interfaces/Text/decorations/adjacent.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ export const output = [
3333
{
3434
text: 'a',
3535
mark: 'mark',
36-
position: { start: 0, end: 1, isFirst: true, isLast: false },
36+
position: { start: 0, end: 1, isFirst: true },
3737
},
3838
{
3939
text: 'b',
4040
mark: 'mark',
4141
decoration1: 'decoration1',
42-
position: { start: 1, end: 2, isFirst: false, isLast: false },
42+
position: { start: 1, end: 2 },
4343
},
4444
{
4545
text: 'c',
4646
mark: 'mark',
4747
decoration2: 'decoration2',
48-
position: { start: 2, end: 3, isFirst: false, isLast: false },
48+
position: { start: 2, end: 3 },
4949
},
5050
{
5151
text: 'd',
5252
mark: 'mark',
53-
position: { start: 3, end: 4, isFirst: false, isLast: true },
53+
position: { start: 3, end: 4, isLast: true },
5454
},
5555
]

packages/slate/test/interfaces/Text/decorations/collapse.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,37 +55,37 @@ export const output = [
5555
{
5656
text: 'a',
5757
mark: 'mark',
58-
position: { start: 0, end: 1, isFirst: true, isLast: false },
58+
position: { start: 0, end: 1, isFirst: true },
5959
},
6060
{
6161
text: 'b',
6262
mark: 'mark',
6363
decoration1: 'decoration1',
64-
position: { start: 1, end: 2, isFirst: false, isLast: false },
64+
position: { start: 1, end: 2 },
6565
},
6666
{
6767
text: '',
6868
mark: 'mark',
6969
decoration1: 'decoration1',
7070
decoration2: 'decoration2',
7171
decoration3: 'decoration3',
72-
position: { start: 2, end: 2, isFirst: false, isLast: false },
72+
position: { start: 2, end: 2 },
7373
},
7474
{
7575
text: 'c',
7676
mark: 'mark',
7777
decoration3: 'decoration3',
78-
position: { start: 2, end: 3, isFirst: false, isLast: false },
78+
position: { start: 2, end: 3 },
7979
},
8080
{
8181
text: 'd',
8282
mark: 'mark',
83-
position: { start: 3, end: 4, isFirst: false, isLast: false },
83+
position: { start: 3, end: 4 },
8484
},
8585
{
8686
text: '',
8787
mark: 'mark',
8888
decoration4: 'decoration4',
89-
position: { start: 4, end: 4, isFirst: false, isLast: true },
89+
position: { start: 4, end: 4, isLast: true },
9090
},
9191
]

packages/slate/test/interfaces/Text/decorations/end.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ export const output = [
2020
{
2121
text: 'ab',
2222
mark: 'mark',
23-
position: { start: 0, end: 2, isFirst: true, isLast: false },
23+
position: { start: 0, end: 2, isFirst: true },
2424
},
2525
{
2626
text: 'c',
2727
mark: 'mark',
2828
decoration: 'decoration',
29-
position: { start: 2, end: 3, isFirst: false, isLast: true },
29+
position: { start: 2, end: 3, isLast: true },
3030
},
3131
]

packages/slate/test/interfaces/Text/decorations/intersect.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ export const output = [
5555
{
5656
text: 'a',
5757
mark: 'mark',
58-
position: { start: 0, end: 1, isFirst: true, isLast: false },
58+
position: { start: 0, end: 1, isFirst: true },
5959
},
6060
{
6161
text: 'b',
6262
mark: 'mark',
6363
decoration1: 'decoration1',
6464
decoration2: 'decoration2',
65-
position: { start: 1, end: 2, isFirst: false, isLast: false },
65+
position: { start: 1, end: 2 },
6666
},
6767
{
6868
text: '',
@@ -71,32 +71,32 @@ export const output = [
7171
decoration2: 'decoration2',
7272
decoration3: 'decoration3',
7373
decoration4: 'decoration4',
74-
position: { start: 2, end: 2, isFirst: false, isLast: false },
74+
position: { start: 2, end: 2 },
7575
},
7676
{
7777
text: 'c',
7878
mark: 'mark',
7979
decoration1: 'decoration1',
8080
decoration2: 'decoration2',
8181
decoration4: 'decoration4',
82-
position: { start: 2, end: 3, isFirst: false, isLast: false },
82+
position: { start: 2, end: 3 },
8383
},
8484
{
8585
text: 'd',
8686
mark: 'mark',
8787
decoration1: 'decoration1',
8888
decoration4: 'decoration4',
89-
position: { start: 3, end: 4, isFirst: false, isLast: false },
89+
position: { start: 3, end: 4 },
9090
},
9191
{
9292
text: 'e',
9393
mark: 'mark',
9494
decoration1: 'decoration1',
95-
position: { start: 4, end: 5, isFirst: false, isLast: false },
95+
position: { start: 4, end: 5 },
9696
},
9797
{
9898
text: 'f',
9999
mark: 'mark',
100-
position: { start: 5, end: 6, isFirst: false, isLast: true },
100+
position: { start: 5, end: 6, isLast: true },
101101
},
102102
]

packages/slate/test/interfaces/Text/decorations/merge.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ export const output = [
4040
text: 'a',
4141
mark: 'mark',
4242
decoration: [1, 2, 3],
43-
position: { start: 0, end: 1, isFirst: true, isLast: false },
43+
position: { start: 0, end: 1, isFirst: true },
4444
},
4545
{
4646
text: 'b',
4747
mark: 'mark',
4848
decoration: [1, 2, 3, 4, 5, 6],
49-
position: { start: 1, end: 2, isFirst: false, isLast: false },
49+
position: { start: 1, end: 2 },
5050
},
5151
{
5252
text: 'c',
5353
mark: 'mark',
5454
decoration: [4, 5, 6],
55-
position: { start: 2, end: 3, isFirst: false, isLast: true },
55+
position: { start: 2, end: 3, isLast: true },
5656
},
5757
]

packages/slate/test/interfaces/Text/decorations/middle.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ export const output = [
2020
{
2121
text: 'a',
2222
mark: 'mark',
23-
position: { start: 0, end: 1, isFirst: true, isLast: false },
23+
position: { start: 0, end: 1, isFirst: true },
2424
},
2525
{
2626
text: 'b',
2727
mark: 'mark',
2828
decoration: 'decoration',
29-
position: { start: 1, end: 2, isFirst: false, isLast: false },
29+
position: { start: 1, end: 2 },
3030
},
3131
{
3232
text: 'c',
3333
mark: 'mark',
34-
position: { start: 2, end: 3, isFirst: false, isLast: true },
34+
position: { start: 2, end: 3, isLast: true },
3535
},
3636
]

packages/slate/test/interfaces/Text/decorations/overlapping.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ export const output = [
3232
text: 'a',
3333
mark: 'mark',
3434
decoration2: 'decoration2',
35-
position: { start: 0, end: 1, isFirst: true, isLast: false },
35+
position: { start: 0, end: 1, isFirst: true },
3636
},
3737
{
3838
text: 'b',
3939
mark: 'mark',
4040
decoration1: 'decoration1',
4141
decoration2: 'decoration2',
42-
position: { start: 1, end: 2, isFirst: false, isLast: false },
42+
position: { start: 1, end: 2 },
4343
},
4444
{
4545
text: 'c',
4646
mark: 'mark',
4747
decoration2: 'decoration2',
48-
position: { start: 2, end: 3, isFirst: false, isLast: true },
48+
position: { start: 2, end: 3, isLast: true },
4949
},
5050
]

packages/slate/test/interfaces/Text/decorations/start.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ export const output = [
2121
text: 'a',
2222
mark: 'mark',
2323
decoration: 'decoration',
24-
position: { start: 0, end: 1, isFirst: true, isLast: false },
24+
position: { start: 0, end: 1, isFirst: true },
2525
},
2626
{
2727
text: 'bc',
2828
mark: 'mark',
29-
position: { start: 1, end: 3, isFirst: false, isLast: true },
29+
position: { start: 1, end: 3, isLast: true },
3030
},
3131
]

0 commit comments

Comments
 (0)