easy-richtextarea 4.0.1 → 4.0.4
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/README.md +0 -8
- package/example.js +1012 -595
- package/lib/browser.js +9 -9
- package/lib/constants.js +13 -4
- package/lib/contentCompare.js +34 -0
- package/lib/example/richTextarea.js +2 -2
- package/lib/example/view.js +18 -9
- package/lib/keyCodes.js +13 -0
- package/lib/main.js +1 -1
- package/lib/operation/delete.js +101 -52
- package/lib/operation/empty.js +21 -6
- package/lib/operation/insert.js +78 -31
- package/lib/operations/fromJSON.js +4 -4
- package/lib/operations/generate.js +11 -11
- package/lib/operations/transform.js +3 -7
- package/lib/richTextarea.js +244 -156
- package/lib/selection.js +55 -13
- package/lib/types.js +13 -13
- package/lib/undoBuffer.js +105 -0
- package/package.json +3 -2
- package/src/browser.js +3 -3
- package/src/constants.js +1 -0
- package/src/contentCompare.js +34 -0
- package/src/example/richTextarea.js +11 -9
- package/src/example/view.js +28 -10
- package/src/keyCodes.js +3 -0
- package/src/main.js +1 -0
- package/src/operation/delete.js +135 -58
- package/src/operation/empty.js +19 -14
- package/src/operation/insert.js +97 -39
- package/src/operations/fromJSON.js +4 -4
- package/src/operations/generate.js +17 -13
- package/src/operations/transform.js +3 -3
- package/src/richTextarea.js +316 -185
- package/src/selection.js +53 -9
- package/src/types.js +6 -6
- package/src/undoBuffer.js +73 -0
- package/test/content/transform.js +15 -17
- package/test/helpers.js +27 -21
- package/test/operation/delete.js +187 -147
- package/test/operation/empty.js +3 -5
- package/test/operation/insert.js +134 -118
- package/test/operations/generate.js +25 -29
- package/test/operations/transform.js +37 -98
- package/lib/stringCompare.js +0 -33
- package/src/stringCompare.js +0 -33
|
@@ -3,37 +3,41 @@
|
|
|
3
3
|
import InsertOperation from "../operation/insert";
|
|
4
4
|
import DeleteOperation from "../operation/delete";
|
|
5
5
|
|
|
6
|
-
export default function generateOperations(
|
|
6
|
+
export default function generateOperations(contentA, contentB) {
|
|
7
7
|
const operations = [],
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
contentALength = contentA.length,
|
|
9
|
+
contentBLength = contentB.length;
|
|
10
10
|
|
|
11
11
|
let left, right;
|
|
12
12
|
|
|
13
|
-
for (left = 0; (left <
|
|
14
|
-
if (
|
|
13
|
+
for (left = 0; (left < contentALength) && (left < contentBLength); left++) {
|
|
14
|
+
if (contentA[left] !== contentB[left]) {
|
|
15
15
|
break;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
for (right = 0; (right <
|
|
20
|
-
if (
|
|
19
|
+
for (right = 0; (right < contentALength - left) && (right < contentBLength - left); right++) {
|
|
20
|
+
if (contentA[contentALength - right - 1] !== contentB[contentBLength - right - 1]) {
|
|
21
21
|
break;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
if (left + right !==
|
|
26
|
-
const
|
|
25
|
+
if (left + right !== contentALength) {
|
|
26
|
+
const start = left, ///
|
|
27
|
+
end = contentALength - right,
|
|
28
|
+
content = contentA.substring(start, end),
|
|
27
29
|
position = left, ///
|
|
28
|
-
deleteOperation = DeleteOperation.
|
|
30
|
+
deleteOperation = DeleteOperation.fromContentAndPosition(content, position);
|
|
29
31
|
|
|
30
32
|
operations.push(deleteOperation);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
if (left + right !==
|
|
34
|
-
const
|
|
35
|
+
if (left + right !== contentBLength) {
|
|
36
|
+
const start = left, ///
|
|
37
|
+
end = contentBLength - right,
|
|
38
|
+
content = contentB.substring(start, end),
|
|
35
39
|
position = left, ///
|
|
36
|
-
insertOperation = InsertOperation.
|
|
40
|
+
insertOperation = InsertOperation.fromContentAndPosition(content, position);
|
|
37
41
|
|
|
38
42
|
operations.push(insertOperation);
|
|
39
43
|
}
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
import { arrayUtilities } from "necessary";
|
|
4
4
|
|
|
5
|
-
const { first, tail } = arrayUtilities;
|
|
5
|
+
const { first, head, tail } = arrayUtilities;
|
|
6
6
|
|
|
7
7
|
export default function transformOperations(tau, rho) {
|
|
8
8
|
if ((tau.length === 0) || (rho.length === 0)) {
|
|
9
9
|
return tau;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
const tau1 =
|
|
12
|
+
const tau1 = head(tau),
|
|
13
13
|
tau2 = tail(tau),
|
|
14
|
-
rho1 =
|
|
14
|
+
rho1 = head(rho),
|
|
15
15
|
rho2 = tail(rho);
|
|
16
16
|
|
|
17
17
|
if (tau.length > 1 && rho.length > 1) {
|