@theia/scm 1.45.0 → 1.46.0-next.72

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 (94) hide show
  1. package/README.md +31 -31
  2. package/lib/browser/decorations/scm-decorations-service.d.ts +14 -14
  3. package/lib/browser/decorations/scm-decorations-service.js +101 -101
  4. package/lib/browser/decorations/scm-navigator-decorator.d.ts +25 -25
  5. package/lib/browser/decorations/scm-navigator-decorator.js +132 -132
  6. package/lib/browser/decorations/scm-tab-bar-decorator.d.ts +17 -17
  7. package/lib/browser/decorations/scm-tab-bar-decorator.js +93 -93
  8. package/lib/browser/dirty-diff/content-lines.d.ts +12 -12
  9. package/lib/browser/dirty-diff/content-lines.js +106 -106
  10. package/lib/browser/dirty-diff/content-lines.spec.d.ts +1 -1
  11. package/lib/browser/dirty-diff/content-lines.spec.js +39 -39
  12. package/lib/browser/dirty-diff/diff-computer.d.ts +29 -29
  13. package/lib/browser/dirty-diff/diff-computer.js +102 -102
  14. package/lib/browser/dirty-diff/diff-computer.spec.d.ts +1 -1
  15. package/lib/browser/dirty-diff/diff-computer.spec.js +315 -315
  16. package/lib/browser/dirty-diff/dirty-diff-decorator.d.ts +14 -14
  17. package/lib/browser/dirty-diff/dirty-diff-decorator.js +98 -98
  18. package/lib/browser/dirty-diff/dirty-diff-module.d.ts +3 -3
  19. package/lib/browser/dirty-diff/dirty-diff-module.js +24 -24
  20. package/lib/browser/scm-amend-component.d.ts +123 -123
  21. package/lib/browser/scm-amend-component.js +463 -463
  22. package/lib/browser/scm-amend-widget.d.ts +20 -20
  23. package/lib/browser/scm-amend-widget.js +101 -101
  24. package/lib/browser/scm-avatar-service.d.ts +3 -3
  25. package/lib/browser/scm-avatar-service.js +36 -36
  26. package/lib/browser/scm-commit-widget.d.ts +52 -52
  27. package/lib/browser/scm-commit-widget.js +199 -199
  28. package/lib/browser/scm-context-key-service.d.ts +10 -10
  29. package/lib/browser/scm-context-key-service.js +58 -58
  30. package/lib/browser/scm-contribution.d.ts +83 -83
  31. package/lib/browser/scm-contribution.js +356 -356
  32. package/lib/browser/scm-frontend-module.d.ts +6 -6
  33. package/lib/browser/scm-frontend-module.js +130 -130
  34. package/lib/browser/scm-groups-tree-model.d.ts +14 -14
  35. package/lib/browser/scm-groups-tree-model.js +97 -97
  36. package/lib/browser/scm-input.d.ts +53 -53
  37. package/lib/browser/scm-input.js +127 -127
  38. package/lib/browser/scm-layout-migrations.d.ts +9 -9
  39. package/lib/browser/scm-layout-migrations.js +79 -79
  40. package/lib/browser/scm-no-repository-widget.d.ts +8 -8
  41. package/lib/browser/scm-no-repository-widget.js +49 -49
  42. package/lib/browser/scm-preferences.d.ts +11 -11
  43. package/lib/browser/scm-preferences.js +51 -51
  44. package/lib/browser/scm-provider.d.ts +58 -58
  45. package/lib/browser/scm-provider.js +19 -19
  46. package/lib/browser/scm-quick-open-service.d.ts +11 -11
  47. package/lib/browser/scm-quick-open-service.js +73 -73
  48. package/lib/browser/scm-repository.d.ts +17 -17
  49. package/lib/browser/scm-repository.js +41 -41
  50. package/lib/browser/scm-service.d.ts +26 -26
  51. package/lib/browser/scm-service.js +108 -108
  52. package/lib/browser/scm-tree-label-provider.d.ts +7 -7
  53. package/lib/browser/scm-tree-label-provider.js +57 -57
  54. package/lib/browser/scm-tree-model.d.ts +74 -74
  55. package/lib/browser/scm-tree-model.js +351 -351
  56. package/lib/browser/scm-tree-widget.d.ts +208 -208
  57. package/lib/browser/scm-tree-widget.js +703 -703
  58. package/lib/browser/scm-widget.d.ts +40 -40
  59. package/lib/browser/scm-widget.js +218 -218
  60. package/package.json +6 -6
  61. package/src/browser/decorations/scm-decorations-service.ts +78 -78
  62. package/src/browser/decorations/scm-navigator-decorator.ts +121 -121
  63. package/src/browser/decorations/scm-tab-bar-decorator.ts +83 -83
  64. package/src/browser/dirty-diff/content-lines.spec.ts +42 -42
  65. package/src/browser/dirty-diff/content-lines.ts +112 -112
  66. package/src/browser/dirty-diff/diff-computer.spec.ts +387 -387
  67. package/src/browser/dirty-diff/diff-computer.ts +129 -129
  68. package/src/browser/dirty-diff/dirty-diff-decorator.ts +107 -107
  69. package/src/browser/dirty-diff/dirty-diff-module.ts +24 -24
  70. package/src/browser/scm-amend-component.tsx +600 -600
  71. package/src/browser/scm-amend-widget.tsx +77 -77
  72. package/src/browser/scm-avatar-service.ts +27 -27
  73. package/src/browser/scm-commit-widget.tsx +215 -215
  74. package/src/browser/scm-context-key-service.ts +46 -46
  75. package/src/browser/scm-contribution.ts +361 -361
  76. package/src/browser/scm-frontend-module.ts +149 -149
  77. package/src/browser/scm-groups-tree-model.ts +78 -78
  78. package/src/browser/scm-input.ts +164 -164
  79. package/src/browser/scm-layout-migrations.ts +64 -64
  80. package/src/browser/scm-no-repository-widget.tsx +41 -41
  81. package/src/browser/scm-preferences.ts +63 -63
  82. package/src/browser/scm-provider.ts +91 -91
  83. package/src/browser/scm-quick-open-service.ts +48 -48
  84. package/src/browser/scm-repository.ts +52 -52
  85. package/src/browser/scm-service.ts +108 -108
  86. package/src/browser/scm-tree-label-provider.ts +44 -44
  87. package/src/browser/scm-tree-model.ts +405 -405
  88. package/src/browser/scm-tree-widget.tsx +838 -838
  89. package/src/browser/scm-widget.tsx +204 -204
  90. package/src/browser/style/dirty-diff-decorator.css +52 -52
  91. package/src/browser/style/dirty-diff.css +50 -50
  92. package/src/browser/style/index.css +271 -271
  93. package/src/browser/style/scm-amend-component.css +94 -94
  94. package/src/browser/style/scm.svg +4 -4
@@ -1,316 +1,316 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2018 TypeFox and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const chai = require("chai");
19
- const chai_1 = require("chai");
20
- chai.use(require('chai-string'));
21
- const diff_computer_1 = require("./diff-computer");
22
- const content_lines_1 = require("./content-lines");
23
- let diffComputer;
24
- before(() => {
25
- diffComputer = new diff_computer_1.DiffComputer();
26
- });
27
- describe('dirty-diff-computer', () => {
28
- it('remove single line', () => {
29
- const dirtyDiff = computeDirtyDiff([
30
- 'FIRST',
31
- 'SECOND TO-BE-REMOVED',
32
- 'THIRD'
33
- ], [
34
- 'FIRST',
35
- 'THIRD'
36
- ]);
37
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
38
- added: [],
39
- modified: [],
40
- removed: [0],
41
- });
42
- });
43
- [1, 2, 3, 20].forEach(lines => {
44
- it(`remove ${formatLines(lines)} at the end`, () => {
45
- const dirtyDiff = computeDirtyDiff(sequenceOfN(2)
46
- .concat(sequenceOfN(lines, () => 'TO-BE-REMOVED')), sequenceOfN(2));
47
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
48
- modified: [],
49
- removed: [1],
50
- added: [],
51
- });
52
- });
53
- });
54
- it('remove all lines', () => {
55
- const dirtyDiff = computeDirtyDiff(sequenceOfN(10, () => 'TO-BE-REMOVED'), ['']);
56
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
57
- added: [],
58
- modified: [],
59
- removed: [0],
60
- });
61
- });
62
- [1, 2, 3, 20].forEach(lines => {
63
- it(`remove ${formatLines(lines)} at the beginning`, () => {
64
- const dirtyDiff = computeDirtyDiff(sequenceOfN(lines, () => 'TO-BE-REMOVED')
65
- .concat(sequenceOfN(2)), sequenceOfN(2));
66
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
67
- modified: [],
68
- removed: [0],
69
- added: [],
70
- });
71
- });
72
- });
73
- [1, 2, 3, 20].forEach(lines => {
74
- it(`add ${formatLines(lines)}`, () => {
75
- const previous = sequenceOfN(3);
76
- const modified = insertIntoArray(previous, 2, ...sequenceOfN(lines, () => 'ADDED LINE'));
77
- const dirtyDiff = computeDirtyDiff(previous, modified);
78
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
79
- modified: [],
80
- removed: [],
81
- added: [{ start: 2, end: 2 + lines - 1 }],
82
- });
83
- });
84
- });
85
- [1, 2, 3, 20].forEach(lines => {
86
- it(`add ${formatLines(lines)} at the beginning`, () => {
87
- const dirtyDiff = computeDirtyDiff(sequenceOfN(2), sequenceOfN(lines, () => 'ADDED LINE')
88
- .concat(sequenceOfN(2)));
89
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
90
- modified: [],
91
- removed: [],
92
- added: [{ start: 0, end: lines - 1 }],
93
- });
94
- });
95
- });
96
- it('add lines to empty file', () => {
97
- const numberOfLines = 3;
98
- const dirtyDiff = computeDirtyDiff([''], sequenceOfN(numberOfLines, () => 'ADDED LINE'));
99
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
100
- modified: [],
101
- removed: [],
102
- added: [{ start: 0, end: numberOfLines - 1 }],
103
- });
104
- });
105
- it('add empty lines', () => {
106
- const dirtyDiff = computeDirtyDiff([
107
- '1',
108
- '2'
109
- ], [
110
- '1',
111
- '',
112
- '',
113
- '2'
114
- ]);
115
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
116
- modified: [],
117
- removed: [],
118
- added: [{ start: 1, end: 2 }],
119
- });
120
- });
121
- it('add empty line after single line', () => {
122
- const dirtyDiff = computeDirtyDiff([
123
- '1'
124
- ], [
125
- '1',
126
- ''
127
- ]);
128
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
129
- modified: [],
130
- removed: [],
131
- added: [{ start: 1, end: 1 }],
132
- });
133
- });
134
- [1, 2, 3, 20].forEach(lines => {
135
- it(`add ${formatLines(lines)} (empty) at the end`, () => {
136
- const dirtyDiff = computeDirtyDiff(sequenceOfN(2), sequenceOfN(2)
137
- .concat(new Array(lines).map(() => '')));
138
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
139
- modified: [],
140
- removed: [],
141
- added: [{ start: 2, end: 1 + lines }],
142
- });
143
- });
144
- });
145
- it('add empty and non-empty lines', () => {
146
- const dirtyDiff = computeDirtyDiff([
147
- 'FIRST',
148
- 'LAST'
149
- ], [
150
- 'FIRST',
151
- '1. ADDED',
152
- '2. ADDED',
153
- '3. ADDED',
154
- '4. ADDED',
155
- '5. ADDED',
156
- 'LAST'
157
- ]);
158
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
159
- modified: [],
160
- removed: [],
161
- added: [{ start: 1, end: 5 }],
162
- });
163
- });
164
- [1, 2, 3, 4, 5].forEach(lines => {
165
- it(`add ${formatLines(lines)} after single line`, () => {
166
- const dirtyDiff = computeDirtyDiff(['0'], ['0'].concat(sequenceOfN(lines, () => 'ADDED LINE')));
167
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
168
- modified: [],
169
- removed: [],
170
- added: [{ start: 1, end: lines }],
171
- });
172
- });
173
- });
174
- it('modify single line', () => {
175
- const dirtyDiff = computeDirtyDiff([
176
- 'FIRST',
177
- 'TO-BE-MODIFIED',
178
- 'LAST'
179
- ], [
180
- 'FIRST',
181
- 'MODIFIED',
182
- 'LAST'
183
- ]);
184
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
185
- removed: [],
186
- added: [],
187
- modified: [{ start: 1, end: 1 }],
188
- });
189
- });
190
- it('modify all lines', () => {
191
- const numberOfLines = 10;
192
- const dirtyDiff = computeDirtyDiff(sequenceOfN(numberOfLines, () => 'TO-BE-MODIFIED'), sequenceOfN(numberOfLines, () => 'MODIFIED'));
193
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
194
- removed: [],
195
- added: [],
196
- modified: [{ start: 0, end: numberOfLines - 1 }],
197
- });
198
- });
199
- it('modify lines at the end', () => {
200
- const dirtyDiff = computeDirtyDiff([
201
- '1',
202
- '2',
203
- '3',
204
- '4'
205
- ], [
206
- '1',
207
- '2-changed',
208
- '3-changed'
209
- ]);
210
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
211
- removed: [],
212
- added: [],
213
- modified: [{ start: 1, end: 2 }],
214
- });
215
- });
216
- it('multiple diffs', () => {
217
- const dirtyDiff = computeDirtyDiff([
218
- 'TO-BE-CHANGED',
219
- '1',
220
- '2',
221
- '3',
222
- 'TO-BE-REMOVED',
223
- '4',
224
- '5',
225
- '6',
226
- '7',
227
- '8',
228
- '9'
229
- ], [
230
- 'CHANGED',
231
- '1',
232
- '2',
233
- '3',
234
- '4',
235
- '5',
236
- '6',
237
- '7',
238
- '8',
239
- '9',
240
- 'ADDED',
241
- ''
242
- ]);
243
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
244
- removed: [3],
245
- added: [{ start: 10, end: 11 }],
246
- modified: [{ start: 0, end: 0 }],
247
- });
248
- });
249
- it('multiple additions', () => {
250
- const dirtyDiff = computeDirtyDiff([
251
- 'first line',
252
- '',
253
- 'foo changed on master',
254
- 'bar changed on master',
255
- '',
256
- '',
257
- '',
258
- '',
259
- '',
260
- 'last line'
261
- ], [
262
- 'first line',
263
- '',
264
- 'foo changed on master',
265
- 'bar changed on master',
266
- '',
267
- 'NEW TEXT',
268
- '',
269
- '',
270
- '',
271
- 'last line',
272
- '',
273
- ''
274
- ]);
275
- (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
276
- removed: [11],
277
- added: [{ start: 5, end: 5 }, { start: 9, end: 9 }],
278
- modified: [],
279
- });
280
- });
281
- });
282
- function computeDirtyDiff(previous, modified) {
283
- const a = content_lines_1.ContentLines.arrayLike({
284
- length: previous.length,
285
- getLineContent: line => {
286
- const value = previous[line];
287
- if (value === undefined) {
288
- console.log(undefined);
289
- }
290
- return value;
291
- },
292
- });
293
- const b = content_lines_1.ContentLines.arrayLike({
294
- length: modified.length,
295
- getLineContent: line => {
296
- const value = modified[line];
297
- if (value === undefined) {
298
- console.log(undefined);
299
- }
300
- return value;
301
- },
302
- });
303
- return diffComputer.computeDirtyDiff(a, b);
304
- }
305
- function sequenceOfN(n, mapFn = i => i.toString()) {
306
- return Array.from(new Array(n).keys()).map((value, index) => mapFn(index));
307
- }
308
- function formatLines(n) {
309
- return n + ' line' + (n > 1 ? 's' : '');
310
- }
311
- function insertIntoArray(target, start, ...items) {
312
- const copy = target.slice(0);
313
- copy.splice(start, 0, ...items);
314
- return copy;
315
- }
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2018 TypeFox and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const chai = require("chai");
19
+ const chai_1 = require("chai");
20
+ chai.use(require('chai-string'));
21
+ const diff_computer_1 = require("./diff-computer");
22
+ const content_lines_1 = require("./content-lines");
23
+ let diffComputer;
24
+ before(() => {
25
+ diffComputer = new diff_computer_1.DiffComputer();
26
+ });
27
+ describe('dirty-diff-computer', () => {
28
+ it('remove single line', () => {
29
+ const dirtyDiff = computeDirtyDiff([
30
+ 'FIRST',
31
+ 'SECOND TO-BE-REMOVED',
32
+ 'THIRD'
33
+ ], [
34
+ 'FIRST',
35
+ 'THIRD'
36
+ ]);
37
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
38
+ added: [],
39
+ modified: [],
40
+ removed: [0],
41
+ });
42
+ });
43
+ [1, 2, 3, 20].forEach(lines => {
44
+ it(`remove ${formatLines(lines)} at the end`, () => {
45
+ const dirtyDiff = computeDirtyDiff(sequenceOfN(2)
46
+ .concat(sequenceOfN(lines, () => 'TO-BE-REMOVED')), sequenceOfN(2));
47
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
48
+ modified: [],
49
+ removed: [1],
50
+ added: [],
51
+ });
52
+ });
53
+ });
54
+ it('remove all lines', () => {
55
+ const dirtyDiff = computeDirtyDiff(sequenceOfN(10, () => 'TO-BE-REMOVED'), ['']);
56
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
57
+ added: [],
58
+ modified: [],
59
+ removed: [0],
60
+ });
61
+ });
62
+ [1, 2, 3, 20].forEach(lines => {
63
+ it(`remove ${formatLines(lines)} at the beginning`, () => {
64
+ const dirtyDiff = computeDirtyDiff(sequenceOfN(lines, () => 'TO-BE-REMOVED')
65
+ .concat(sequenceOfN(2)), sequenceOfN(2));
66
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
67
+ modified: [],
68
+ removed: [0],
69
+ added: [],
70
+ });
71
+ });
72
+ });
73
+ [1, 2, 3, 20].forEach(lines => {
74
+ it(`add ${formatLines(lines)}`, () => {
75
+ const previous = sequenceOfN(3);
76
+ const modified = insertIntoArray(previous, 2, ...sequenceOfN(lines, () => 'ADDED LINE'));
77
+ const dirtyDiff = computeDirtyDiff(previous, modified);
78
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
79
+ modified: [],
80
+ removed: [],
81
+ added: [{ start: 2, end: 2 + lines - 1 }],
82
+ });
83
+ });
84
+ });
85
+ [1, 2, 3, 20].forEach(lines => {
86
+ it(`add ${formatLines(lines)} at the beginning`, () => {
87
+ const dirtyDiff = computeDirtyDiff(sequenceOfN(2), sequenceOfN(lines, () => 'ADDED LINE')
88
+ .concat(sequenceOfN(2)));
89
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
90
+ modified: [],
91
+ removed: [],
92
+ added: [{ start: 0, end: lines - 1 }],
93
+ });
94
+ });
95
+ });
96
+ it('add lines to empty file', () => {
97
+ const numberOfLines = 3;
98
+ const dirtyDiff = computeDirtyDiff([''], sequenceOfN(numberOfLines, () => 'ADDED LINE'));
99
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
100
+ modified: [],
101
+ removed: [],
102
+ added: [{ start: 0, end: numberOfLines - 1 }],
103
+ });
104
+ });
105
+ it('add empty lines', () => {
106
+ const dirtyDiff = computeDirtyDiff([
107
+ '1',
108
+ '2'
109
+ ], [
110
+ '1',
111
+ '',
112
+ '',
113
+ '2'
114
+ ]);
115
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
116
+ modified: [],
117
+ removed: [],
118
+ added: [{ start: 1, end: 2 }],
119
+ });
120
+ });
121
+ it('add empty line after single line', () => {
122
+ const dirtyDiff = computeDirtyDiff([
123
+ '1'
124
+ ], [
125
+ '1',
126
+ ''
127
+ ]);
128
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
129
+ modified: [],
130
+ removed: [],
131
+ added: [{ start: 1, end: 1 }],
132
+ });
133
+ });
134
+ [1, 2, 3, 20].forEach(lines => {
135
+ it(`add ${formatLines(lines)} (empty) at the end`, () => {
136
+ const dirtyDiff = computeDirtyDiff(sequenceOfN(2), sequenceOfN(2)
137
+ .concat(new Array(lines).map(() => '')));
138
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
139
+ modified: [],
140
+ removed: [],
141
+ added: [{ start: 2, end: 1 + lines }],
142
+ });
143
+ });
144
+ });
145
+ it('add empty and non-empty lines', () => {
146
+ const dirtyDiff = computeDirtyDiff([
147
+ 'FIRST',
148
+ 'LAST'
149
+ ], [
150
+ 'FIRST',
151
+ '1. ADDED',
152
+ '2. ADDED',
153
+ '3. ADDED',
154
+ '4. ADDED',
155
+ '5. ADDED',
156
+ 'LAST'
157
+ ]);
158
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
159
+ modified: [],
160
+ removed: [],
161
+ added: [{ start: 1, end: 5 }],
162
+ });
163
+ });
164
+ [1, 2, 3, 4, 5].forEach(lines => {
165
+ it(`add ${formatLines(lines)} after single line`, () => {
166
+ const dirtyDiff = computeDirtyDiff(['0'], ['0'].concat(sequenceOfN(lines, () => 'ADDED LINE')));
167
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
168
+ modified: [],
169
+ removed: [],
170
+ added: [{ start: 1, end: lines }],
171
+ });
172
+ });
173
+ });
174
+ it('modify single line', () => {
175
+ const dirtyDiff = computeDirtyDiff([
176
+ 'FIRST',
177
+ 'TO-BE-MODIFIED',
178
+ 'LAST'
179
+ ], [
180
+ 'FIRST',
181
+ 'MODIFIED',
182
+ 'LAST'
183
+ ]);
184
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
185
+ removed: [],
186
+ added: [],
187
+ modified: [{ start: 1, end: 1 }],
188
+ });
189
+ });
190
+ it('modify all lines', () => {
191
+ const numberOfLines = 10;
192
+ const dirtyDiff = computeDirtyDiff(sequenceOfN(numberOfLines, () => 'TO-BE-MODIFIED'), sequenceOfN(numberOfLines, () => 'MODIFIED'));
193
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
194
+ removed: [],
195
+ added: [],
196
+ modified: [{ start: 0, end: numberOfLines - 1 }],
197
+ });
198
+ });
199
+ it('modify lines at the end', () => {
200
+ const dirtyDiff = computeDirtyDiff([
201
+ '1',
202
+ '2',
203
+ '3',
204
+ '4'
205
+ ], [
206
+ '1',
207
+ '2-changed',
208
+ '3-changed'
209
+ ]);
210
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
211
+ removed: [],
212
+ added: [],
213
+ modified: [{ start: 1, end: 2 }],
214
+ });
215
+ });
216
+ it('multiple diffs', () => {
217
+ const dirtyDiff = computeDirtyDiff([
218
+ 'TO-BE-CHANGED',
219
+ '1',
220
+ '2',
221
+ '3',
222
+ 'TO-BE-REMOVED',
223
+ '4',
224
+ '5',
225
+ '6',
226
+ '7',
227
+ '8',
228
+ '9'
229
+ ], [
230
+ 'CHANGED',
231
+ '1',
232
+ '2',
233
+ '3',
234
+ '4',
235
+ '5',
236
+ '6',
237
+ '7',
238
+ '8',
239
+ '9',
240
+ 'ADDED',
241
+ ''
242
+ ]);
243
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
244
+ removed: [3],
245
+ added: [{ start: 10, end: 11 }],
246
+ modified: [{ start: 0, end: 0 }],
247
+ });
248
+ });
249
+ it('multiple additions', () => {
250
+ const dirtyDiff = computeDirtyDiff([
251
+ 'first line',
252
+ '',
253
+ 'foo changed on master',
254
+ 'bar changed on master',
255
+ '',
256
+ '',
257
+ '',
258
+ '',
259
+ '',
260
+ 'last line'
261
+ ], [
262
+ 'first line',
263
+ '',
264
+ 'foo changed on master',
265
+ 'bar changed on master',
266
+ '',
267
+ 'NEW TEXT',
268
+ '',
269
+ '',
270
+ '',
271
+ 'last line',
272
+ '',
273
+ ''
274
+ ]);
275
+ (0, chai_1.expect)(dirtyDiff).to.be.deep.equal({
276
+ removed: [11],
277
+ added: [{ start: 5, end: 5 }, { start: 9, end: 9 }],
278
+ modified: [],
279
+ });
280
+ });
281
+ });
282
+ function computeDirtyDiff(previous, modified) {
283
+ const a = content_lines_1.ContentLines.arrayLike({
284
+ length: previous.length,
285
+ getLineContent: line => {
286
+ const value = previous[line];
287
+ if (value === undefined) {
288
+ console.log(undefined);
289
+ }
290
+ return value;
291
+ },
292
+ });
293
+ const b = content_lines_1.ContentLines.arrayLike({
294
+ length: modified.length,
295
+ getLineContent: line => {
296
+ const value = modified[line];
297
+ if (value === undefined) {
298
+ console.log(undefined);
299
+ }
300
+ return value;
301
+ },
302
+ });
303
+ return diffComputer.computeDirtyDiff(a, b);
304
+ }
305
+ function sequenceOfN(n, mapFn = i => i.toString()) {
306
+ return Array.from(new Array(n).keys()).map((value, index) => mapFn(index));
307
+ }
308
+ function formatLines(n) {
309
+ return n + ' line' + (n > 1 ? 's' : '');
310
+ }
311
+ function insertIntoArray(target, start, ...items) {
312
+ const copy = target.slice(0);
313
+ copy.splice(start, 0, ...items);
314
+ return copy;
315
+ }
316
316
  //# sourceMappingURL=diff-computer.spec.js.map
@@ -1,15 +1,15 @@
1
- import { EditorDecoration, EditorDecorationOptions, EditorDecorator, TextEditor } from '@theia/editor/lib/browser';
2
- import { DirtyDiff, LineRange } from './diff-computer';
3
- export declare enum DirtyDiffDecorationType {
4
- AddedLine = "dirty-diff-added-line",
5
- RemovedLine = "dirty-diff-removed-line",
6
- ModifiedLine = "dirty-diff-modified-line"
7
- }
8
- export interface DirtyDiffUpdate extends DirtyDiff {
9
- readonly editor: TextEditor;
10
- }
11
- export declare class DirtyDiffDecorator extends EditorDecorator {
12
- applyDecorations(update: DirtyDiffUpdate): void;
13
- protected toDeltaDecoration(from: LineRange | number, options: EditorDecorationOptions): EditorDecoration;
14
- }
1
+ import { EditorDecoration, EditorDecorationOptions, EditorDecorator, TextEditor } from '@theia/editor/lib/browser';
2
+ import { DirtyDiff, LineRange } from './diff-computer';
3
+ export declare enum DirtyDiffDecorationType {
4
+ AddedLine = "dirty-diff-added-line",
5
+ RemovedLine = "dirty-diff-removed-line",
6
+ ModifiedLine = "dirty-diff-modified-line"
7
+ }
8
+ export interface DirtyDiffUpdate extends DirtyDiff {
9
+ readonly editor: TextEditor;
10
+ }
11
+ export declare class DirtyDiffDecorator extends EditorDecorator {
12
+ applyDecorations(update: DirtyDiffUpdate): void;
13
+ protected toDeltaDecoration(from: LineRange | number, options: EditorDecorationOptions): EditorDecoration;
14
+ }
15
15
  //# sourceMappingURL=dirty-diff-decorator.d.ts.map