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