easy-richtextarea 4.0.34 → 4.0.36
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 +93 -1563
- package/lib/browser.js +1 -37
- package/lib/main.js +4 -45
- package/lib/mixins/event.js +11 -10
- package/lib/richTextarea.js +31 -156
- package/lib/selection.js +7 -146
- package/package.json +1 -3
- package/src/browser.js +0 -11
- package/src/main.js +0 -12
- package/src/mixins/event.js +3 -4
- package/src/richTextarea.js +22 -239
- package/src/selection.js +4 -154
- package/lib/constants.js +0 -22
- package/lib/contentCompare.js +0 -34
- package/lib/eventTypes.js +0 -49
- package/lib/keyCodes.js +0 -13
- package/lib/operation/delete.js +0 -290
- package/lib/operation/empty.js +0 -116
- package/lib/operation/insert.js +0 -245
- package/lib/operations/fromJSON.js +0 -40
- package/lib/operations/generate.js +0 -42
- package/lib/operations/toJSON.js +0 -17
- package/lib/transform/content.js +0 -19
- package/lib/transform/operations.js +0 -31
- package/lib/transform/selection.js +0 -19
- package/lib/types.js +0 -34
- package/lib/undoBuffer.js +0 -145
- package/src/constants.js +0 -4
- package/src/contentCompare.js +0 -34
- package/src/eventTypes.js +0 -15
- package/src/keyCodes.js +0 -3
- package/src/operation/delete.js +0 -285
- package/src/operation/empty.js +0 -76
- package/src/operation/insert.js +0 -221
- package/src/operations/fromJSON.js +0 -34
- package/src/operations/generate.js +0 -46
- package/src/operations/toJSON.js +0 -5
- package/src/transform/content.js +0 -11
- package/src/transform/operations.js +0 -57
- package/src/transform/selection.js +0 -11
- package/src/types.js +0 -11
- package/src/undoBuffer.js +0 -119
- package/test/content/transform.js +0 -57
- package/test/helpers.js +0 -91
- package/test/operation/delete.js +0 -390
- package/test/operation/empty.js +0 -101
- package/test/operation/insert.js +0 -306
- package/test/operations/generate.js +0 -78
- package/test/operations/transform.js +0 -69
package/test/operation/delete.js
DELETED
|
@@ -1,390 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { assert } = require("chai"),
|
|
4
|
-
{ arrayUtilities } = require("necessary"),
|
|
5
|
-
{ Selection, EmptyOperation, DeleteOperation, InsertOperation } = require("../../lib/browser"); ///
|
|
6
|
-
|
|
7
|
-
const { first } = arrayUtilities;
|
|
8
|
-
|
|
9
|
-
describe("DeleteOperation", () => {
|
|
10
|
-
describe("transform", () => {
|
|
11
|
-
it("leaves an empty operation intact", () => {
|
|
12
|
-
const deleteOperation1 = DeleteOperation.fromContentAndPosition("juiHYGrvc", 6),
|
|
13
|
-
emptyOperation2 = EmptyOperation.fromNothing(),
|
|
14
|
-
transformedOperations = deleteOperation1.transformOperation(emptyOperation2);
|
|
15
|
-
|
|
16
|
-
assert.lengthOf(transformedOperations, 1);
|
|
17
|
-
|
|
18
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
19
|
-
transformedOperation = firstTransformedOperation, ///
|
|
20
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
21
|
-
expectedTransformedOperation = emptyOperation2.clone(),
|
|
22
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
23
|
-
|
|
24
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe("completely to the left of an insert", () => {
|
|
28
|
-
it("move the insert left by its own length", () => {
|
|
29
|
-
const deleteOperation1 = DeleteOperation.fromContentAndPosition("dkjyBH", 1),
|
|
30
|
-
insertOperation2 = InsertOperation.fromContentAndPosition("grFTd", 10),
|
|
31
|
-
transformedOperations = deleteOperation1.transformOperation(insertOperation2);
|
|
32
|
-
|
|
33
|
-
assert.lengthOf(transformedOperations, 1);
|
|
34
|
-
|
|
35
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
36
|
-
transformedOperation = firstTransformedOperation, ///
|
|
37
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
38
|
-
expectedTransformedOperation = InsertOperation.fromContentAndPosition("grFTd", 4),
|
|
39
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
40
|
-
|
|
41
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe("partially overlaps an insert on the left", () => {
|
|
46
|
-
it("moves the insert left by its own position", () => {
|
|
47
|
-
const deleteOperation1 = DeleteOperation.fromContentAndPosition("bgRDTh", 2),
|
|
48
|
-
insertOperation2 = InsertOperation.fromContentAndPosition("zn76g", 4),
|
|
49
|
-
transformedOperations = deleteOperation1.transformOperation(insertOperation2);
|
|
50
|
-
|
|
51
|
-
assert.lengthOf(transformedOperations, 1);
|
|
52
|
-
|
|
53
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
54
|
-
transformedOperation = firstTransformedOperation, ///
|
|
55
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
56
|
-
expectedTransformedOperation = InsertOperation.fromContentAndPosition("zn76g", 2),
|
|
57
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
58
|
-
|
|
59
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe("completely overlaps an insert", () => {
|
|
64
|
-
it("moves the insert left by its own position", () => {
|
|
65
|
-
const deleteOperation1 = DeleteOperation.fromContentAndPosition("bgRjhgtFFGHRTDTh", 2),
|
|
66
|
-
insertOperation2 = InsertOperation.fromContentAndPosition("zn76g", 4),
|
|
67
|
-
transformedOperations = deleteOperation1.transformOperation(insertOperation2);
|
|
68
|
-
|
|
69
|
-
assert.lengthOf(transformedOperations, 1);
|
|
70
|
-
|
|
71
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
72
|
-
transformedOperation = firstTransformedOperation, ///
|
|
73
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
74
|
-
expectedTransformedOperation = InsertOperation.fromContentAndPosition("zn76g", 2),
|
|
75
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
76
|
-
|
|
77
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe("overlaps an insert on the right", () => {
|
|
82
|
-
it("leaves the insert intact", () => {
|
|
83
|
-
const deleteOperation1 = DeleteOperation.fromContentAndPosition("jhuGTRRde2kjU", 6),
|
|
84
|
-
insertOperation2 = InsertOperation.fromContentAndPosition("znds76g", 4),
|
|
85
|
-
transformedOperations = deleteOperation1.transformOperation(insertOperation2);
|
|
86
|
-
|
|
87
|
-
assert.lengthOf(transformedOperations, 1);
|
|
88
|
-
|
|
89
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
90
|
-
transformedOperation = firstTransformedOperation, ///
|
|
91
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
92
|
-
expectedTransformedOperation = InsertOperation.fromContentAndPosition("znds76g", 4),
|
|
93
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
94
|
-
|
|
95
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe("is overlapped by an insert", () => {
|
|
100
|
-
it("leaves the insert intact", () => {
|
|
101
|
-
const deleteOperation1 = DeleteOperation.fromContentAndPosition("juiyd", 6),
|
|
102
|
-
insertOperation2 = InsertOperation.fromContentAndPosition("zndLKo76g", 2),
|
|
103
|
-
transformedOperations = deleteOperation1.transformOperation(insertOperation2);
|
|
104
|
-
|
|
105
|
-
assert.lengthOf(transformedOperations, 1);
|
|
106
|
-
|
|
107
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
108
|
-
transformedOperation = firstTransformedOperation, ///
|
|
109
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
110
|
-
expectedTransformedOperation = InsertOperation.fromContentAndPosition("zndLKo76g", 2),
|
|
111
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
112
|
-
|
|
113
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe("completely to the left of another delete", () => {
|
|
118
|
-
it("moves the other delete to the left by its own length", () => {
|
|
119
|
-
const deleteOperation1 = DeleteOperation.fromContentAndPosition("juhtyb", 2),
|
|
120
|
-
deleteOperation2 = DeleteOperation.fromContentAndPosition("xhTRF43X", 10),
|
|
121
|
-
transformedOperations = deleteOperation1.transformOperation(deleteOperation2);
|
|
122
|
-
|
|
123
|
-
assert.lengthOf(transformedOperations, 1);
|
|
124
|
-
|
|
125
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
126
|
-
transformedOperation = firstTransformedOperation, ///
|
|
127
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
128
|
-
expectedTransformedOperation = DeleteOperation.fromContentAndPosition("xhTRF43X", 4),
|
|
129
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
130
|
-
|
|
131
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe("partially overlaps another delete on the left", () => {
|
|
136
|
-
it("moves the other delete to the left to its own position and truncates it on the left", () => {
|
|
137
|
-
const deleteOperation1 = DeleteOperation.fromContentAndPosition("jkimmijhdX", 2),
|
|
138
|
-
deleteOperation2 = DeleteOperation.fromContentAndPosition("mijhdXkAVB", 6),
|
|
139
|
-
transformedOperations = deleteOperation1.transformOperation(deleteOperation2);
|
|
140
|
-
|
|
141
|
-
assert.lengthOf(transformedOperations, 1);
|
|
142
|
-
|
|
143
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
144
|
-
transformedOperation = firstTransformedOperation, ///
|
|
145
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
146
|
-
expectedTransformedOperation = DeleteOperation.fromContentAndPosition("kAVB", 2),
|
|
147
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
148
|
-
|
|
149
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe("completely overlaps another delete on the left", () => {
|
|
154
|
-
it("transforms it to an empty operation", () => {
|
|
155
|
-
const deleteOperation1 = DeleteOperation.fromContentAndPosition("jkimmijhdX", 2),
|
|
156
|
-
deleteOperation2 = DeleteOperation.fromContentAndPosition("immi", 4),
|
|
157
|
-
transformedOperations = deleteOperation1.transformOperation(deleteOperation2);
|
|
158
|
-
|
|
159
|
-
assert.lengthOf(transformedOperations, 1);
|
|
160
|
-
|
|
161
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
162
|
-
transformedOperation = firstTransformedOperation, ///
|
|
163
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
164
|
-
expectedTransformedOperation = EmptyOperation.fromNothing(),
|
|
165
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
166
|
-
|
|
167
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
describe("is completely overlapped by another delete", () => {
|
|
172
|
-
it("splites the ohter delete", () => {
|
|
173
|
-
const deleteOperation1 = DeleteOperation.fromContentAndPosition("immi", 4),
|
|
174
|
-
deleteOperation2 = DeleteOperation.fromContentAndPosition("jkimmijhdX", 2),
|
|
175
|
-
transformedOperations = deleteOperation1.transformOperation(deleteOperation2);
|
|
176
|
-
|
|
177
|
-
assert.lengthOf(transformedOperations, 1);
|
|
178
|
-
|
|
179
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
180
|
-
transformedOperation = firstTransformedOperation, ///
|
|
181
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
182
|
-
expectedTransformedOperation = DeleteOperation.fromContentAndPosition("jkjhdX", 2),
|
|
183
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
184
|
-
|
|
185
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
describe("overlaps another delete on the right", () => {
|
|
190
|
-
it("truncates the other delete on the right", () => {
|
|
191
|
-
const deleteOperation1 = DeleteOperation.fromContentAndPosition("GtfrdIKJU", 6),
|
|
192
|
-
deleteOperation2 = DeleteOperation.fromContentAndPosition("juHYGtfrd", 2),
|
|
193
|
-
transformedOperations = deleteOperation1.transformOperation(deleteOperation2);
|
|
194
|
-
|
|
195
|
-
assert.lengthOf(transformedOperations, 1);
|
|
196
|
-
|
|
197
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
198
|
-
transformedOperation = firstTransformedOperation, ///
|
|
199
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
200
|
-
expectedTransformedOperation = DeleteOperation.fromContentAndPosition("juHY", 2),
|
|
201
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
202
|
-
|
|
203
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
describe("completely to the right another delete", () => {
|
|
208
|
-
it("leaves the other delete intact", () => {
|
|
209
|
-
const deleteOperation1 = DeleteOperation.fromContentAndPosition("jikd", 12),
|
|
210
|
-
deleteOperation2 = DeleteOperation.fromContentAndPosition("ZDrert5", 2),
|
|
211
|
-
transformedOperations = deleteOperation1.transformOperation(deleteOperation2);
|
|
212
|
-
|
|
213
|
-
assert.lengthOf(transformedOperations, 1);
|
|
214
|
-
|
|
215
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
216
|
-
transformedOperation = firstTransformedOperation, ///
|
|
217
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
218
|
-
expectedTransformedOperation = DeleteOperation.fromContentAndPosition("ZDrert5", 2),
|
|
219
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
220
|
-
|
|
221
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
describe("has the same position as the other delete and is strictly overlapped by it", () => {
|
|
226
|
-
it("truncates the other delete on the left", () => {
|
|
227
|
-
const deleteOperation1 = DeleteOperation.fromContentAndPosition("juhy", 2),
|
|
228
|
-
deleteOperation2 = DeleteOperation.fromContentAndPosition("juhyKIOU", 2),
|
|
229
|
-
transformedOperations = deleteOperation1.transformOperation(deleteOperation2);
|
|
230
|
-
|
|
231
|
-
assert.lengthOf(transformedOperations, 1);
|
|
232
|
-
|
|
233
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
234
|
-
transformedOperation = firstTransformedOperation, ///
|
|
235
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
236
|
-
expectedTransformedOperation = DeleteOperation.fromContentAndPosition("KIOU", 2),
|
|
237
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
238
|
-
|
|
239
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
describe("has the same position as the other delete and overlaps it", () => {
|
|
244
|
-
it("transforms the other delete to an empty operation", () => {
|
|
245
|
-
const deleteOperation1 = DeleteOperation.fromContentAndPosition("juhYGTfv", 2),
|
|
246
|
-
deleteOperation2 = DeleteOperation.fromContentAndPosition("juhYG", 2),
|
|
247
|
-
transformedOperations = deleteOperation1.transformOperation(deleteOperation2);
|
|
248
|
-
|
|
249
|
-
assert.lengthOf(transformedOperations, 1);
|
|
250
|
-
|
|
251
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
252
|
-
transformedOperation = firstTransformedOperation, ///
|
|
253
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
254
|
-
expectedTransformedOperation = EmptyOperation.fromNothing(),
|
|
255
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
256
|
-
|
|
257
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
describe("transformContent", () => {
|
|
263
|
-
it("deletes the requisite characters from the content", () => {
|
|
264
|
-
const content = "3c9OQTyTmb",
|
|
265
|
-
deleteOperation = DeleteOperation.fromContentAndPosition("QTyTmb", 4),
|
|
266
|
-
transformedContent = deleteOperation.transformContent(content),
|
|
267
|
-
expectedContent = "3c9O";
|
|
268
|
-
|
|
269
|
-
assert.equal(transformedContent, expectedContent);
|
|
270
|
-
});
|
|
271
|
-
});
|
|
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
|
-
|
|
378
|
-
describe("fromJSON, toJSON", () => {
|
|
379
|
-
it("transforms from and to JSON, leaving the operation intact", () => {
|
|
380
|
-
const expectedJSON = {
|
|
381
|
-
"type": "delete",
|
|
382
|
-
"content": "bcd",
|
|
383
|
-
"position": 1
|
|
384
|
-
},
|
|
385
|
-
json = DeleteOperation.fromJSON(expectedJSON).toJSON();
|
|
386
|
-
|
|
387
|
-
assert.deepEqual(json, expectedJSON);
|
|
388
|
-
});
|
|
389
|
-
});
|
|
390
|
-
});
|
package/test/operation/empty.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { assert } = require("chai"),
|
|
4
|
-
{ arrayUtilities } = require("necessary"),
|
|
5
|
-
{ Selection, EmptyOperation, DeleteOperation, InsertOperation } = require("../../lib/browser"); ///
|
|
6
|
-
|
|
7
|
-
const { first } = arrayUtilities;
|
|
8
|
-
|
|
9
|
-
describe("EmptyOperation", () => {
|
|
10
|
-
describe("transform", () => {
|
|
11
|
-
it("transforms an insert operation, leaving it the same", () => {
|
|
12
|
-
const emptyOperation1 = EmptyOperation.fromNothing(),
|
|
13
|
-
insertOperation2 = InsertOperation.fromContentAndPosition("jinHgt", 8),
|
|
14
|
-
transformedOperations = emptyOperation1.transformOperation(insertOperation2);
|
|
15
|
-
|
|
16
|
-
assert.lengthOf(transformedOperations, 1);
|
|
17
|
-
|
|
18
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
19
|
-
transformedOperation = firstTransformedOperation, ///
|
|
20
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
21
|
-
expectedTransformedOperation = insertOperation2.clone(),
|
|
22
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
23
|
-
|
|
24
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("transforms a second empty operation, leaving it the same", () => {
|
|
28
|
-
const emptyOperation1 = EmptyOperation.fromNothing(),
|
|
29
|
-
emptyOperation2 = EmptyOperation.fromNothing(),
|
|
30
|
-
transformedOperations = emptyOperation1.transformOperation(emptyOperation2);
|
|
31
|
-
|
|
32
|
-
assert.lengthOf(transformedOperations, 1);
|
|
33
|
-
|
|
34
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
35
|
-
transformedOperation = firstTransformedOperation, ///
|
|
36
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
37
|
-
expectedTransformedOperation = emptyOperation2.clone(),
|
|
38
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
39
|
-
|
|
40
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("transforms a delete operation, leaving it the same", () => {
|
|
44
|
-
const emptyOperation1 = EmptyOperation.fromNothing(),
|
|
45
|
-
deleteOperation2 = DeleteOperation.fromContentAndPosition("bKinld", 4),
|
|
46
|
-
transformedOperations = emptyOperation1.transformOperation(deleteOperation2);
|
|
47
|
-
|
|
48
|
-
assert.lengthOf(transformedOperations, 1);
|
|
49
|
-
|
|
50
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
51
|
-
transformedOperation = firstTransformedOperation, ///
|
|
52
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
53
|
-
expectedTransformedOperation = deleteOperation2.clone(),
|
|
54
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
55
|
-
|
|
56
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe("transformContent", () => {
|
|
61
|
-
it("leaves the content unchanged", () => {
|
|
62
|
-
const content = "asXdvvyi",
|
|
63
|
-
emptyOperation = EmptyOperation.fromNothing(),
|
|
64
|
-
transformedContent = emptyOperation.transformContent(content),
|
|
65
|
-
expectedContent = content; ///
|
|
66
|
-
|
|
67
|
-
assert.equal(transformedContent, expectedContent);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
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
|
-
|
|
91
|
-
describe("fromJSON, toJSON", () => {
|
|
92
|
-
it("transforms from and to JSON, leaving the operation intact", () => {
|
|
93
|
-
const expectedJSON = {
|
|
94
|
-
"type": "empty"
|
|
95
|
-
},
|
|
96
|
-
json = EmptyOperation.fromJSON(expectedJSON).toJSON();
|
|
97
|
-
|
|
98
|
-
assert.deepEqual(json, expectedJSON);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
});
|