1
1
import { describe , expect , it } from "vitest" ;
2
2
import { deleteEdit , insertEdit } from "./edit" ;
3
- import type { DomSnapshot , SelectionSnapshot , Writeable } from "../types" ;
3
+ import type { DocFragment , SelectionSnapshot , Writeable } from "../types" ;
4
4
5
5
const splitAt = ( targetStr : string , index : number ) : [ string , string ] => {
6
6
return [ targetStr . slice ( 0 , index ) , targetStr . slice ( index ) ] ;
@@ -43,7 +43,7 @@ describe(insertEdit.name, () => {
43
43
it ( "insert text at line before caret" , ( ) => {
44
44
const docText = "abcde" ;
45
45
const docText2 = "fghij" ;
46
- const doc : Writeable < DomSnapshot > = [ [ docText ] , [ docText2 ] ] ;
46
+ const doc : Writeable < DocFragment > = [ [ docText ] , [ docText2 ] ] ;
47
47
const sel : Writeable < SelectionSnapshot > = [
48
48
[ 1 , 2 ] ,
49
49
[ 1 , 2 ] ,
@@ -59,7 +59,7 @@ describe(insertEdit.name, () => {
59
59
it ( "insert lines at line before caret" , ( ) => {
60
60
const docText = "abcde" ;
61
61
const docText2 = "fghij" ;
62
- const doc : Writeable < DomSnapshot > = [ [ docText ] , [ docText2 ] ] ;
62
+ const doc : Writeable < DocFragment > = [ [ docText ] , [ docText2 ] ] ;
63
63
const sel : Writeable < SelectionSnapshot > = [
64
64
[ 1 , 2 ] ,
65
65
[ 1 , 2 ] ,
@@ -76,7 +76,7 @@ describe(insertEdit.name, () => {
76
76
77
77
it ( "insert text before caret" , ( ) => {
78
78
const docText = "abcde" ;
79
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
79
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
80
80
const sel : Writeable < SelectionSnapshot > = [
81
81
[ 0 , 2 ] ,
82
82
[ 0 , 2 ] ,
@@ -91,7 +91,7 @@ describe(insertEdit.name, () => {
91
91
92
92
it ( "insert lines before caret" , ( ) => {
93
93
const docText = "abcde" ;
94
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
94
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
95
95
const sel : Writeable < SelectionSnapshot > = [
96
96
[ 0 , 2 ] ,
97
97
[ 0 , 2 ] ,
@@ -110,7 +110,7 @@ describe(insertEdit.name, () => {
110
110
111
111
it ( "insert text on caret" , ( ) => {
112
112
const docText = "abcde" ;
113
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
113
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
114
114
const sel : Writeable < SelectionSnapshot > = [
115
115
[ 0 , 2 ] ,
116
116
[ 0 , 2 ] ,
@@ -125,7 +125,7 @@ describe(insertEdit.name, () => {
125
125
126
126
it ( "insert lines on caret" , ( ) => {
127
127
const docText = "abcde" ;
128
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
128
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
129
129
const sel : Writeable < SelectionSnapshot > = [
130
130
[ 0 , 2 ] ,
131
131
[ 0 , 2 ] ,
@@ -144,7 +144,7 @@ describe(insertEdit.name, () => {
144
144
145
145
it ( "insert text inside selection" , ( ) => {
146
146
const docText = "abcde" ;
147
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
147
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
148
148
const sel : Writeable < SelectionSnapshot > = [
149
149
[ 0 , 1 ] ,
150
150
[ 0 , 3 ] ,
@@ -159,7 +159,7 @@ describe(insertEdit.name, () => {
159
159
160
160
it ( "insert lines inside selection" , ( ) => {
161
161
const docText = "abcde" ;
162
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
162
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
163
163
const sel : Writeable < SelectionSnapshot > = [
164
164
[ 0 , 1 ] ,
165
165
[ 0 , 3 ] ,
@@ -181,7 +181,7 @@ describe(insertEdit.name, () => {
181
181
182
182
it ( "insert text after caret" , ( ) => {
183
183
const docText = "abcde" ;
184
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
184
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
185
185
const sel : Writeable < SelectionSnapshot > = [
186
186
[ 0 , 2 ] ,
187
187
[ 0 , 2 ] ,
@@ -196,7 +196,7 @@ describe(insertEdit.name, () => {
196
196
197
197
it ( "insert lines after caret" , ( ) => {
198
198
const docText = "abcde" ;
199
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
199
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
200
200
const sel : Writeable < SelectionSnapshot > = [
201
201
[ 0 , 2 ] ,
202
202
[ 0 , 2 ] ,
@@ -214,7 +214,7 @@ describe(insertEdit.name, () => {
214
214
it ( "insert text at line after caret" , ( ) => {
215
215
const docText = "abcde" ;
216
216
const docText2 = "fghij" ;
217
- const doc : Writeable < DomSnapshot > = [ [ docText ] , [ docText2 ] ] ;
217
+ const doc : Writeable < DocFragment > = [ [ docText ] , [ docText2 ] ] ;
218
218
const sel : Writeable < SelectionSnapshot > = [
219
219
[ 0 , 2 ] ,
220
220
[ 0 , 2 ] ,
@@ -230,7 +230,7 @@ describe(insertEdit.name, () => {
230
230
it ( "insert lines at line after caret" , ( ) => {
231
231
const docText = "abcde" ;
232
232
const docText2 = "fghij" ;
233
- const doc : Writeable < DomSnapshot > = [ [ docText ] , [ docText2 ] ] ;
233
+ const doc : Writeable < DocFragment > = [ [ docText ] , [ docText2 ] ] ;
234
234
const sel : Writeable < SelectionSnapshot > = [
235
235
[ 0 , 2 ] ,
236
236
[ 0 , 2 ] ,
@@ -249,12 +249,12 @@ describe(insertEdit.name, () => {
249
249
describe ( deleteEdit . name , ( ) => {
250
250
it ( "do nothing if start and end is the same" , ( ) => {
251
251
const docText = "abcde" ;
252
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
252
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
253
253
const sel : Writeable < SelectionSnapshot > = [
254
254
[ 0 , 2 ] ,
255
255
[ 0 , 2 ] ,
256
256
] ;
257
- const initialDoc : DomSnapshot = structuredClone ( doc ) ;
257
+ const initialDoc : DocFragment = structuredClone ( doc ) ;
258
258
const initialSel : SelectionSnapshot = structuredClone ( sel ) ;
259
259
deleteEdit ( doc , sel , [ 0 , 1 ] , [ 0 , 1 ] ) ;
260
260
@@ -265,7 +265,7 @@ describe(deleteEdit.name, () => {
265
265
it ( "delete text at line before caret" , ( ) => {
266
266
const docText = "abcde" ;
267
267
const docText2 = "fghij" ;
268
- const doc : Writeable < DomSnapshot > = [ [ docText ] , [ docText2 ] ] ;
268
+ const doc : Writeable < DocFragment > = [ [ docText ] , [ docText2 ] ] ;
269
269
const sel : Writeable < SelectionSnapshot > = [
270
270
[ 1 , 2 ] ,
271
271
[ 1 , 2 ] ,
@@ -280,7 +280,7 @@ describe(deleteEdit.name, () => {
280
280
it ( "delete linebreak at line before caret" , ( ) => {
281
281
const docText = "abcde" ;
282
282
const docText2 = "fghij" ;
283
- const doc : Writeable < DomSnapshot > = [ [ docText ] , [ docText2 ] ] ;
283
+ const doc : Writeable < DocFragment > = [ [ docText ] , [ docText2 ] ] ;
284
284
const sel : Writeable < SelectionSnapshot > = [
285
285
[ 1 , 3 ] ,
286
286
[ 1 , 3 ] ,
@@ -299,7 +299,7 @@ describe(deleteEdit.name, () => {
299
299
300
300
it ( "delete text before caret" , ( ) => {
301
301
const docText = "abcde" ;
302
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
302
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
303
303
const sel : Writeable < SelectionSnapshot > = [
304
304
[ 0 , 3 ] ,
305
305
[ 0 , 3 ] ,
@@ -313,7 +313,7 @@ describe(deleteEdit.name, () => {
313
313
314
314
it ( "delete text just before caret" , ( ) => {
315
315
const docText = "abcde" ;
316
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
316
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
317
317
const sel : Writeable < SelectionSnapshot > = [
318
318
[ 0 , 3 ] ,
319
319
[ 0 , 3 ] ,
@@ -327,7 +327,7 @@ describe(deleteEdit.name, () => {
327
327
328
328
it ( "delete text around caret" , ( ) => {
329
329
const docText = "abcde" ;
330
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
330
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
331
331
const sel : Writeable < SelectionSnapshot > = [
332
332
[ 0 , 3 ] ,
333
333
[ 0 , 3 ] ,
@@ -341,7 +341,7 @@ describe(deleteEdit.name, () => {
341
341
342
342
it ( "delete text around selection" , ( ) => {
343
343
const docText = "abcde" ;
344
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
344
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
345
345
const sel : Writeable < SelectionSnapshot > = [
346
346
[ 0 , 2 ] ,
347
347
[ 0 , 4 ] ,
@@ -357,7 +357,7 @@ describe(deleteEdit.name, () => {
357
357
358
358
it ( "delete text around selection anchor" , ( ) => {
359
359
const docText = "abcde" ;
360
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
360
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
361
361
const sel : Writeable < SelectionSnapshot > = [
362
362
[ 0 , 2 ] ,
363
363
[ 0 , 4 ] ,
@@ -371,7 +371,7 @@ describe(deleteEdit.name, () => {
371
371
372
372
it ( "delete text around selection focus" , ( ) => {
373
373
const docText = "abcde" ;
374
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
374
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
375
375
const sel : Writeable < SelectionSnapshot > = [
376
376
[ 0 , 2 ] ,
377
377
[ 0 , 4 ] ,
@@ -386,7 +386,7 @@ describe(deleteEdit.name, () => {
386
386
it ( "delete linebreak inside selection" , ( ) => {
387
387
const docText = "abcde" ;
388
388
const docText2 = "fghij" ;
389
- const doc : Writeable < DomSnapshot > = [ [ docText ] , [ docText2 ] ] ;
389
+ const doc : Writeable < DocFragment > = [ [ docText ] , [ docText2 ] ] ;
390
390
const sel : Writeable < SelectionSnapshot > = [
391
391
[ 0 , 2 ] ,
392
392
[ 1 , 2 ] ,
@@ -402,7 +402,7 @@ describe(deleteEdit.name, () => {
402
402
403
403
it ( "delete text just after caret" , ( ) => {
404
404
const docText = "abcde" ;
405
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
405
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
406
406
const sel : Writeable < SelectionSnapshot > = [
407
407
[ 0 , 3 ] ,
408
408
[ 0 , 3 ] ,
@@ -416,7 +416,7 @@ describe(deleteEdit.name, () => {
416
416
417
417
it ( "delete text after caret" , ( ) => {
418
418
const docText = "abcde" ;
419
- const doc : Writeable < DomSnapshot > = [ [ docText ] ] ;
419
+ const doc : Writeable < DocFragment > = [ [ docText ] ] ;
420
420
const sel : Writeable < SelectionSnapshot > = [
421
421
[ 0 , 3 ] ,
422
422
[ 0 , 3 ] ,
@@ -431,7 +431,7 @@ describe(deleteEdit.name, () => {
431
431
it ( "delete text at line after caret" , ( ) => {
432
432
const docText = "abcde" ;
433
433
const docText2 = "fghij" ;
434
- const doc : Writeable < DomSnapshot > = [ [ docText ] , [ docText2 ] ] ;
434
+ const doc : Writeable < DocFragment > = [ [ docText ] , [ docText2 ] ] ;
435
435
const sel : Writeable < SelectionSnapshot > = [
436
436
[ 0 , 2 ] ,
437
437
[ 0 , 2 ] ,
@@ -447,7 +447,7 @@ describe(deleteEdit.name, () => {
447
447
const docText = "abcde" ;
448
448
const docText2 = "fghij" ;
449
449
const docText3 = "klmno" ;
450
- const doc : Writeable < DomSnapshot > = [ [ docText ] , [ docText2 ] , [ docText3 ] ] ;
450
+ const doc : Writeable < DocFragment > = [ [ docText ] , [ docText2 ] , [ docText3 ] ] ;
451
451
const sel : Writeable < SelectionSnapshot > = [
452
452
[ 0 , 2 ] ,
453
453
[ 0 , 2 ] ,
0 commit comments