easy-richtextarea 4.0.15 → 4.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/example.js +45 -42
- package/lib/operation/delete.js +15 -14
- package/lib/operation/empty.js +8 -8
- package/lib/operation/insert.js +13 -13
- package/lib/richTextarea.js +5 -3
- package/lib/selection.js +8 -8
- package/package.json +1 -1
- package/src/operation/delete.js +21 -19
- package/src/operation/empty.js +6 -6
- package/src/operation/insert.js +18 -18
- package/src/richTextarea.js +10 -2
- package/src/selection.js +11 -7
- package/test/operation/delete.js +107 -2
- package/test/operation/empty.js +22 -2
- package/test/operation/insert.js +91 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easy-richtextarea",
|
|
3
3
|
"author": "James Smith",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.17",
|
|
5
5
|
"license": "MIT, Anti-996",
|
|
6
6
|
"homepage": "https://github.com/djalbat/easy-richtextarea",
|
|
7
7
|
"description": "A textarea element that handles and hands off events well.",
|
package/src/operation/delete.js
CHANGED
|
@@ -23,6 +23,24 @@ export default class DeleteOperation {
|
|
|
23
23
|
return this.position;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
transformContent(content) {
|
|
27
|
+
let start, end;
|
|
28
|
+
|
|
29
|
+
start = 0;
|
|
30
|
+
|
|
31
|
+
end = this.position;
|
|
32
|
+
|
|
33
|
+
const leftContent = content.substring(start, end),
|
|
34
|
+
contentLength = this.content.length;
|
|
35
|
+
|
|
36
|
+
start = this.position + contentLength;
|
|
37
|
+
|
|
38
|
+
const rightContent = content.substring(start),
|
|
39
|
+
transformedContent = leftContent + rightContent;
|
|
40
|
+
|
|
41
|
+
return transformedContent;
|
|
42
|
+
}
|
|
43
|
+
|
|
26
44
|
transformOperation(operation) {
|
|
27
45
|
const type = operation.getType();
|
|
28
46
|
|
|
@@ -98,24 +116,6 @@ export default class DeleteOperation {
|
|
|
98
116
|
}
|
|
99
117
|
}
|
|
100
118
|
|
|
101
|
-
transformContent(content) {
|
|
102
|
-
let start, end;
|
|
103
|
-
|
|
104
|
-
start = 0;
|
|
105
|
-
|
|
106
|
-
end = this.position;
|
|
107
|
-
|
|
108
|
-
const leftContent = content.substring(start, end),
|
|
109
|
-
contentLength = this.content.length;
|
|
110
|
-
|
|
111
|
-
start = this.position + contentLength;
|
|
112
|
-
|
|
113
|
-
const rightContent = content.substring(start),
|
|
114
|
-
transformedContent = leftContent + rightContent;
|
|
115
|
-
|
|
116
|
-
return transformedContent;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
119
|
transformSelection(selection) {
|
|
120
120
|
let transformedSelection;
|
|
121
121
|
|
|
@@ -138,7 +138,9 @@ export default class DeleteOperation {
|
|
|
138
138
|
|
|
139
139
|
transformedSelection = selection.shifted(offset).endPositionShifted(endOffset);
|
|
140
140
|
} else {
|
|
141
|
-
|
|
141
|
+
const offset = startPosition - selectionStartPosition;
|
|
142
|
+
|
|
143
|
+
transformedSelection = selection.emptied().shifted(offset);
|
|
142
144
|
}
|
|
143
145
|
} else if (selectionEndPosition > endPosition) {
|
|
144
146
|
const endOffset = -contentLength;
|
package/src/operation/empty.js
CHANGED
|
@@ -11,6 +11,12 @@ export default class EmptyOperation {
|
|
|
11
11
|
return this.type;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
transformContent(content) {
|
|
15
|
+
const transformedContent = content; ///
|
|
16
|
+
|
|
17
|
+
return transformedContent;
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
transformOperation(operation) {
|
|
15
21
|
return ((tau, rho) => {
|
|
16
22
|
|
|
@@ -19,12 +25,6 @@ export default class EmptyOperation {
|
|
|
19
25
|
})(operation, this);
|
|
20
26
|
}
|
|
21
27
|
|
|
22
|
-
transformContent(content) {
|
|
23
|
-
const transformedContent = content; ///
|
|
24
|
-
|
|
25
|
-
return transformedContent;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
28
|
transformSelection(selection) {
|
|
29
29
|
const transformedSelection = selection.clone();
|
|
30
30
|
|
package/src/operation/insert.js
CHANGED
|
@@ -24,6 +24,24 @@ export default class InsertOperation {
|
|
|
24
24
|
return this.position;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
transformContent(content) {
|
|
28
|
+
let start,
|
|
29
|
+
end;
|
|
30
|
+
|
|
31
|
+
start = 0;
|
|
32
|
+
|
|
33
|
+
end = this.position;
|
|
34
|
+
|
|
35
|
+
const leftContent = content.substring(start, end);
|
|
36
|
+
|
|
37
|
+
start = this.position;
|
|
38
|
+
|
|
39
|
+
const rightContent = content.substring(start),
|
|
40
|
+
transformedContent = leftContent + this.content + rightContent;
|
|
41
|
+
|
|
42
|
+
return transformedContent;
|
|
43
|
+
}
|
|
44
|
+
|
|
27
45
|
transformOperation(operation) {
|
|
28
46
|
const type = operation.getType();
|
|
29
47
|
|
|
@@ -81,24 +99,6 @@ export default class InsertOperation {
|
|
|
81
99
|
}
|
|
82
100
|
}
|
|
83
101
|
|
|
84
|
-
transformContent(content) {
|
|
85
|
-
let start,
|
|
86
|
-
end;
|
|
87
|
-
|
|
88
|
-
start = 0;
|
|
89
|
-
|
|
90
|
-
end = this.position;
|
|
91
|
-
|
|
92
|
-
const leftContent = content.substring(start, end);
|
|
93
|
-
|
|
94
|
-
start = this.position;
|
|
95
|
-
|
|
96
|
-
const rightContent = content.substring(start),
|
|
97
|
-
transformedContent = leftContent + this.content + rightContent;
|
|
98
|
-
|
|
99
|
-
return transformedContent;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
102
|
transformSelection(selection) {
|
|
103
103
|
let transformedSelection;
|
|
104
104
|
|
package/src/richTextarea.js
CHANGED
|
@@ -245,10 +245,14 @@ export default class RichTextarea extends Element {
|
|
|
245
245
|
const operation = this.undoBuffer.undo();
|
|
246
246
|
|
|
247
247
|
if (operation !== null) {
|
|
248
|
-
const undoable = false
|
|
248
|
+
const undoable = false,
|
|
249
|
+
selection = Selection.fromOperation(operation),
|
|
250
|
+
setPreviousSelection = false;
|
|
249
251
|
|
|
250
252
|
this.applyOperation(operation);
|
|
251
253
|
|
|
254
|
+
this.setSelection(selection, setPreviousSelection);
|
|
255
|
+
|
|
252
256
|
this.intermediateHandler(event, element, undoable);
|
|
253
257
|
}
|
|
254
258
|
}
|
|
@@ -257,10 +261,14 @@ export default class RichTextarea extends Element {
|
|
|
257
261
|
const operation = this.undoBuffer.redo();
|
|
258
262
|
|
|
259
263
|
if (operation !== null) {
|
|
260
|
-
const undoable = false
|
|
264
|
+
const undoable = false,
|
|
265
|
+
selection = Selection.fromOperation(operation),
|
|
266
|
+
setPreviousSelection = false;
|
|
261
267
|
|
|
262
268
|
this.applyOperation(operation);
|
|
263
269
|
|
|
270
|
+
this.setSelection(selection, setPreviousSelection);
|
|
271
|
+
|
|
264
272
|
this.intermediateHandler(event, element, undoable);
|
|
265
273
|
}
|
|
266
274
|
}
|
package/src/selection.js
CHANGED
|
@@ -116,6 +116,17 @@ export default class Selection {
|
|
|
116
116
|
return selection;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
static fromOperation(operation) {
|
|
120
|
+
const content = operation.getContent(),
|
|
121
|
+
position = operation.getPosition(),
|
|
122
|
+
contentLength = content.length,
|
|
123
|
+
startPosition = position + contentLength,
|
|
124
|
+
endPosition = startPosition, ///
|
|
125
|
+
selection = new Selection(startPosition, endPosition);
|
|
126
|
+
|
|
127
|
+
return selection;
|
|
128
|
+
}
|
|
129
|
+
|
|
119
130
|
static fromSelection(selection) {
|
|
120
131
|
const startPosition = selection.getStartPosition(),
|
|
121
132
|
endPosition = selection.getEndPosition();
|
|
@@ -135,13 +146,6 @@ export default class Selection {
|
|
|
135
146
|
|
|
136
147
|
}
|
|
137
148
|
|
|
138
|
-
static fromStartPosition(startPosition) {
|
|
139
|
-
const endPosition = startPosition, ///
|
|
140
|
-
selection = new Selection(startPosition, endPosition);
|
|
141
|
-
|
|
142
|
-
return selection;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
149
|
static fromStartPositionAndEndPosition(startPosition, endPosition) {
|
|
146
150
|
const selection = new Selection(startPosition, endPosition);
|
|
147
151
|
|
package/test/operation/delete.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { assert } = require("chai"),
|
|
4
4
|
{ arrayUtilities } = require("necessary"),
|
|
5
|
-
{ EmptyOperation, DeleteOperation, InsertOperation } = require("../../lib/browser"); ///
|
|
5
|
+
{ Selection, EmptyOperation, DeleteOperation, InsertOperation } = require("../../lib/browser"); ///
|
|
6
6
|
|
|
7
7
|
const { first } = arrayUtilities;
|
|
8
8
|
|
|
@@ -270,8 +270,113 @@ describe("DeleteOperation", () => {
|
|
|
270
270
|
});
|
|
271
271
|
});
|
|
272
272
|
|
|
273
|
+
describe("#transformSelection", () => {
|
|
274
|
+
let deleteOperation;
|
|
275
|
+
|
|
276
|
+
beforeEach(() => {
|
|
277
|
+
const content = "jUb",
|
|
278
|
+
position = 4;
|
|
279
|
+
|
|
280
|
+
deleteOperation = DeleteOperation.fromContentAndPosition(content, position);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
describe("the selection is to its left", () => {
|
|
284
|
+
it("leaves the selection intact", () => {
|
|
285
|
+
const startPosition = 1,
|
|
286
|
+
endPosition = 2,
|
|
287
|
+
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
288
|
+
transformedSelection = deleteOperation.transformSelection(selection),
|
|
289
|
+
expectedSelection = selection,
|
|
290
|
+
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
291
|
+
expectedSelectionJSON = expectedSelection.toJSON();
|
|
292
|
+
|
|
293
|
+
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
describe("the selection overlaps its left", () => {
|
|
298
|
+
it("trims the selection's right", () => {
|
|
299
|
+
const startPosition = 1,
|
|
300
|
+
endPosition = 5,
|
|
301
|
+
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
302
|
+
transformedSelection = deleteOperation.transformSelection(selection),
|
|
303
|
+
expectedStartPosition = 1,
|
|
304
|
+
expectedEndPosition = 4,
|
|
305
|
+
expectedSelection = Selection.fromStartPositionAndEndPosition(expectedStartPosition, expectedEndPosition),
|
|
306
|
+
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
307
|
+
expectedSelectionJSON = expectedSelection.toJSON();
|
|
308
|
+
|
|
309
|
+
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
describe("the selection overlaps it completely", () => {
|
|
314
|
+
it("trims the selections's right by its length", () => {
|
|
315
|
+
const startPosition = 1,
|
|
316
|
+
endPosition = 10,
|
|
317
|
+
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
318
|
+
transformedSelection = deleteOperation.transformSelection(selection),
|
|
319
|
+
expectedStartPosition = 1,
|
|
320
|
+
expectedEndPosition = 7,
|
|
321
|
+
expectedSelection = Selection.fromStartPositionAndEndPosition(expectedStartPosition, expectedEndPosition),
|
|
322
|
+
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
323
|
+
expectedSelectionJSON = expectedSelection.toJSON();
|
|
324
|
+
|
|
325
|
+
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
describe("the selection overlaps its right", () => {
|
|
330
|
+
it("trims the selections's left and moves the selection left by its length", () => {
|
|
331
|
+
const startPosition = 5,
|
|
332
|
+
endPosition = 8,
|
|
333
|
+
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
334
|
+
transformedSelection = deleteOperation.transformSelection(selection),
|
|
335
|
+
expectedStartPosition = 4,
|
|
336
|
+
expectedEndPosition = 5,
|
|
337
|
+
expectedSelection = Selection.fromStartPositionAndEndPosition(expectedStartPosition, expectedEndPosition),
|
|
338
|
+
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
339
|
+
expectedSelectionJSON = expectedSelection.toJSON();
|
|
340
|
+
|
|
341
|
+
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
describe("the selection is completely to its right", () => {
|
|
346
|
+
it("moves the selection left by its length", () => {
|
|
347
|
+
const startPosition = 8,
|
|
348
|
+
endPosition = 10,
|
|
349
|
+
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
350
|
+
transformedSelection = deleteOperation.transformSelection(selection),
|
|
351
|
+
expectedStartPosition = 5,
|
|
352
|
+
expectedEndPosition = 7,
|
|
353
|
+
expectedSelection = Selection.fromStartPositionAndEndPosition(expectedStartPosition, expectedEndPosition),
|
|
354
|
+
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
355
|
+
expectedSelectionJSON = expectedSelection.toJSON();
|
|
356
|
+
|
|
357
|
+
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
describe("the selection is completely overlapped", () => {
|
|
362
|
+
it("moves both the selection's start and end points to its left edge", () => {
|
|
363
|
+
const startPosition = 5,
|
|
364
|
+
endPosition = 6,
|
|
365
|
+
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
366
|
+
transformedSelection = deleteOperation.transformSelection(selection),
|
|
367
|
+
expectedStartPosition = 4,
|
|
368
|
+
expectedEndPosition = 4,
|
|
369
|
+
expectedSelection = Selection.fromStartPositionAndEndPosition(expectedStartPosition, expectedEndPosition),
|
|
370
|
+
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
371
|
+
expectedSelectionJSON = expectedSelection.toJSON();
|
|
372
|
+
|
|
373
|
+
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
|
|
273
378
|
describe("fromJSON, toJSON", () => {
|
|
274
|
-
it("transforms from and to JSON, leaving the operation
|
|
379
|
+
it("transforms from and to JSON, leaving the operation intact", () => {
|
|
275
380
|
const expectedJSON = {
|
|
276
381
|
"type": "delete",
|
|
277
382
|
"content": "bcd",
|
package/test/operation/empty.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { assert } = require("chai"),
|
|
4
4
|
{ arrayUtilities } = require("necessary"),
|
|
5
|
-
{ EmptyOperation, DeleteOperation, InsertOperation } = require("../../lib/browser"); ///
|
|
5
|
+
{ Selection, EmptyOperation, DeleteOperation, InsertOperation } = require("../../lib/browser"); ///
|
|
6
6
|
|
|
7
7
|
const { first } = arrayUtilities;
|
|
8
8
|
|
|
@@ -68,8 +68,28 @@ describe("EmptyOperation", () => {
|
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
+
describe("#transformSelection", () => {
|
|
72
|
+
let emptyOperation;
|
|
73
|
+
|
|
74
|
+
beforeEach(() => {
|
|
75
|
+
emptyOperation = EmptyOperation.fromNothing();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("leaves the selection intact", () => {
|
|
79
|
+
const startPosition = 3,
|
|
80
|
+
endPosition = 6,
|
|
81
|
+
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
82
|
+
transformedSelection = emptyOperation.transformSelection(selection),
|
|
83
|
+
expectedSelection = selection, ///
|
|
84
|
+
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
85
|
+
expectedSelectionJSON = expectedSelection.toJSON();
|
|
86
|
+
|
|
87
|
+
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
71
91
|
describe("fromJSON, toJSON", () => {
|
|
72
|
-
it("transforms from and to JSON, leaving the operation
|
|
92
|
+
it("transforms from and to JSON, leaving the operation intact", () => {
|
|
73
93
|
const expectedJSON = {
|
|
74
94
|
"type": "empty"
|
|
75
95
|
},
|
package/test/operation/insert.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { assert } = require("chai"),
|
|
4
4
|
{ arrayUtilities } = require("necessary"),
|
|
5
|
-
{ EmptyOperation, DeleteOperation, InsertOperation } = require("../../lib/browser"); ///
|
|
5
|
+
{ Selection, EmptyOperation, DeleteOperation, InsertOperation } = require("../../lib/browser"); ///
|
|
6
6
|
|
|
7
7
|
const { first, second } = arrayUtilities;
|
|
8
8
|
|
|
@@ -202,8 +202,97 @@ describe("InsertOperation", () => {
|
|
|
202
202
|
});
|
|
203
203
|
});
|
|
204
204
|
|
|
205
|
+
describe("#transformSelection", () => {
|
|
206
|
+
let insertOperation;
|
|
207
|
+
|
|
208
|
+
beforeEach(() => {
|
|
209
|
+
const content = "JHg",
|
|
210
|
+
position = 4;
|
|
211
|
+
|
|
212
|
+
insertOperation = InsertOperation.fromContentAndPosition(content, position);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
describe("the selection is to its left", () => {
|
|
216
|
+
it("leaves the selection intact", () => {
|
|
217
|
+
const startPosition = 1,
|
|
218
|
+
endPosition = 2,
|
|
219
|
+
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
220
|
+
transformedSelection = insertOperation.transformSelection(selection),
|
|
221
|
+
expectedSelection = selection, ///
|
|
222
|
+
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
223
|
+
expectedSelectionJSON = expectedSelection.toJSON();
|
|
224
|
+
|
|
225
|
+
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
describe("the selection overlaps its left", () => {
|
|
230
|
+
it("moves the selections's right by its length", () => {
|
|
231
|
+
const startPosition = 1,
|
|
232
|
+
endPosition = 5,
|
|
233
|
+
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
234
|
+
transformedSelection = insertOperation.transformSelection(selection),
|
|
235
|
+
expectedStartPosition = 1,
|
|
236
|
+
expectedEndPosition = 8,
|
|
237
|
+
expectedSelection = Selection.fromStartPositionAndEndPosition(expectedStartPosition, expectedEndPosition),
|
|
238
|
+
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
239
|
+
expectedSelectionJSON = expectedSelection.toJSON();
|
|
240
|
+
|
|
241
|
+
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
describe("the selection overlaps it completely, moves the selections's right by its length", () => {
|
|
246
|
+
it("the selection overlaps it completely, moves the selections's right by its length", () => {
|
|
247
|
+
const startPosition = 1,
|
|
248
|
+
endPosition = 10,
|
|
249
|
+
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
250
|
+
transformedSelection = insertOperation.transformSelection(selection),
|
|
251
|
+
expectedStartPosition = 1,
|
|
252
|
+
expectedEndPosition = 13,
|
|
253
|
+
expectedSelection = Selection.fromStartPositionAndEndPosition(expectedStartPosition, expectedEndPosition),
|
|
254
|
+
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
255
|
+
expectedSelectionJSON = expectedSelection.toJSON();
|
|
256
|
+
|
|
257
|
+
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe("the selection overlaps its right", () => {
|
|
262
|
+
it("moves the selection right by its length", () => {
|
|
263
|
+
const startPosition = 5,
|
|
264
|
+
endPosition = 8,
|
|
265
|
+
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
266
|
+
transformedSelection = insertOperation.transformSelection(selection),
|
|
267
|
+
expectedStartPosition = 8,
|
|
268
|
+
expectedEndPosition = 11,
|
|
269
|
+
expectedSelection = Selection.fromStartPositionAndEndPosition(expectedStartPosition, expectedEndPosition),
|
|
270
|
+
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
271
|
+
expectedSelectionJSON = expectedSelection.toJSON();
|
|
272
|
+
|
|
273
|
+
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
describe("the selection is completely to its right", () => {
|
|
278
|
+
it("moves the selection right by its length", () => {
|
|
279
|
+
const startPosition = 8,
|
|
280
|
+
endPosition = 10,
|
|
281
|
+
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
282
|
+
transformedSelection = insertOperation.transformSelection(selection),
|
|
283
|
+
expectedStartPosition = 11,
|
|
284
|
+
expectedEndPosition = 13,
|
|
285
|
+
expectedSelection = Selection.fromStartPositionAndEndPosition(expectedStartPosition, expectedEndPosition),
|
|
286
|
+
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
287
|
+
expectedSelectionJSON = expectedSelection.toJSON();
|
|
288
|
+
|
|
289
|
+
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
205
294
|
describe("fromJSON, toJSON", () => {
|
|
206
|
-
it("transforms from and to JSON, leaving the operation
|
|
295
|
+
it("transforms from and to JSON, leaving the operation intact", () => {
|
|
207
296
|
const expectedJSON = {
|
|
208
297
|
"type": "insert",
|
|
209
298
|
"content": "a",
|