@theia/editor 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 (112) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/decorations/editor-decoration-style.d.ts +8 -8
  3. package/lib/browser/decorations/editor-decoration-style.js +36 -36
  4. package/lib/browser/decorations/editor-decoration.d.ts +106 -106
  5. package/lib/browser/decorations/editor-decoration.js +37 -37
  6. package/lib/browser/decorations/editor-decorator.d.ts +6 -6
  7. package/lib/browser/decorations/editor-decorator.js +43 -43
  8. package/lib/browser/decorations/index.d.ts +3 -3
  9. package/lib/browser/decorations/index.js +30 -30
  10. package/lib/browser/diff-navigator.d.ts +9 -10
  11. package/lib/browser/diff-navigator.d.ts.map +1 -1
  12. package/lib/browser/diff-navigator.js +19 -19
  13. package/lib/browser/diff-navigator.js.map +1 -1
  14. package/lib/browser/editor-command.d.ts +102 -102
  15. package/lib/browser/editor-command.js +426 -426
  16. package/lib/browser/editor-contribution.d.ts +26 -26
  17. package/lib/browser/editor-contribution.js +198 -198
  18. package/lib/browser/editor-frontend-module.d.ts +5 -5
  19. package/lib/browser/editor-frontend-module.js +74 -74
  20. package/lib/browser/editor-generated-preference-schema.d.ts +282 -249
  21. package/lib/browser/editor-generated-preference-schema.d.ts.map +1 -1
  22. package/lib/browser/editor-generated-preference-schema.js +2451 -2316
  23. package/lib/browser/editor-generated-preference-schema.js.map +1 -1
  24. package/lib/browser/editor-keybinding.d.ts +5 -5
  25. package/lib/browser/editor-keybinding.js +55 -55
  26. package/lib/browser/editor-linenumber-contribution.d.ts +15 -15
  27. package/lib/browser/editor-linenumber-contribution.d.ts.map +1 -1
  28. package/lib/browser/editor-linenumber-contribution.js +95 -96
  29. package/lib/browser/editor-linenumber-contribution.js.map +1 -1
  30. package/lib/browser/editor-manager.d.ts +115 -115
  31. package/lib/browser/editor-manager.js +428 -428
  32. package/lib/browser/editor-menu.d.ts +48 -48
  33. package/lib/browser/editor-menu.js +210 -210
  34. package/lib/browser/editor-navigation-contribution.d.ts +67 -67
  35. package/lib/browser/editor-navigation-contribution.js +343 -343
  36. package/lib/browser/editor-preferences.d.ts +41 -41
  37. package/lib/browser/editor-preferences.js +176 -176
  38. package/lib/browser/editor-variable-contribution.d.ts +8 -8
  39. package/lib/browser/editor-variable-contribution.js +64 -64
  40. package/lib/browser/editor-widget-factory.d.ts +17 -17
  41. package/lib/browser/editor-widget-factory.js +91 -91
  42. package/lib/browser/editor-widget.d.ts +24 -24
  43. package/lib/browser/editor-widget.d.ts.map +1 -1
  44. package/lib/browser/editor-widget.js +122 -114
  45. package/lib/browser/editor-widget.js.map +1 -1
  46. package/lib/browser/editor.d.ts +295 -293
  47. package/lib/browser/editor.d.ts.map +1 -1
  48. package/lib/browser/editor.js +103 -103
  49. package/lib/browser/editor.js.map +1 -1
  50. package/lib/browser/index.d.ts +10 -10
  51. package/lib/browser/index.js +37 -37
  52. package/lib/browser/language-status/editor-language-status-service.d.ts +77 -77
  53. package/lib/browser/language-status/editor-language-status-service.js +251 -251
  54. package/lib/browser/navigation/navigation-location-service.d.ts +103 -103
  55. package/lib/browser/navigation/navigation-location-service.js +281 -281
  56. package/lib/browser/navigation/navigation-location-service.spec.d.ts +1 -1
  57. package/lib/browser/navigation/navigation-location-service.spec.js +184 -184
  58. package/lib/browser/navigation/navigation-location-similarity.d.ts +15 -15
  59. package/lib/browser/navigation/navigation-location-similarity.js +62 -62
  60. package/lib/browser/navigation/navigation-location-similarity.spec.d.ts +1 -1
  61. package/lib/browser/navigation/navigation-location-similarity.spec.js +32 -32
  62. package/lib/browser/navigation/navigation-location-updater.d.ts +35 -35
  63. package/lib/browser/navigation/navigation-location-updater.js +210 -210
  64. package/lib/browser/navigation/navigation-location-updater.spec.d.ts +1 -1
  65. package/lib/browser/navigation/navigation-location-updater.spec.js +177 -177
  66. package/lib/browser/navigation/navigation-location.d.ts +191 -191
  67. package/lib/browser/navigation/navigation-location.js +300 -300
  68. package/lib/browser/navigation/test/mock-navigation-location-updater.d.ts +15 -15
  69. package/lib/browser/navigation/test/mock-navigation-location-updater.js +38 -38
  70. package/lib/browser/quick-editor-service.d.ts +16 -16
  71. package/lib/browser/quick-editor-service.js +109 -109
  72. package/lib/browser/undo-redo-service.d.ts +23 -23
  73. package/lib/browser/undo-redo-service.js +110 -110
  74. package/lib/common/language-selector.d.ts +13 -13
  75. package/lib/common/language-selector.js +90 -90
  76. package/lib/package.spec.js +25 -25
  77. package/package.json +5 -5
  78. package/src/browser/decorations/editor-decoration-style.ts +41 -41
  79. package/src/browser/decorations/editor-decoration.ts +127 -127
  80. package/src/browser/decorations/editor-decorator.ts +36 -36
  81. package/src/browser/decorations/index.ts +19 -19
  82. package/src/browser/diff-navigator.ts +27 -28
  83. package/src/browser/editor-command.ts +414 -414
  84. package/src/browser/editor-contribution.ts +185 -185
  85. package/src/browser/editor-frontend-module.ts +87 -87
  86. package/src/browser/editor-generated-preference-schema.ts +2707 -2539
  87. package/src/browser/editor-keybinding.ts +55 -55
  88. package/src/browser/editor-linenumber-contribution.ts +88 -89
  89. package/src/browser/editor-manager.ts +442 -442
  90. package/src/browser/editor-menu.ts +224 -224
  91. package/src/browser/editor-navigation-contribution.ts +343 -343
  92. package/src/browser/editor-preferences.ts +226 -226
  93. package/src/browser/editor-variable-contribution.ts +54 -54
  94. package/src/browser/editor-widget-factory.ts +82 -82
  95. package/src/browser/editor-widget.ts +137 -130
  96. package/src/browser/editor.ts +360 -358
  97. package/src/browser/index.ts +26 -26
  98. package/src/browser/language-status/editor-language-status-service.ts +271 -271
  99. package/src/browser/language-status/editor-language-status.css +101 -101
  100. package/src/browser/navigation/navigation-location-service.spec.ts +245 -245
  101. package/src/browser/navigation/navigation-location-service.ts +284 -284
  102. package/src/browser/navigation/navigation-location-similarity.spec.ts +46 -46
  103. package/src/browser/navigation/navigation-location-similarity.ts +58 -58
  104. package/src/browser/navigation/navigation-location-updater.spec.ts +197 -197
  105. package/src/browser/navigation/navigation-location-updater.ts +220 -220
  106. package/src/browser/navigation/navigation-location.ts +418 -418
  107. package/src/browser/navigation/test/mock-navigation-location-updater.ts +41 -41
  108. package/src/browser/quick-editor-service.ts +94 -94
  109. package/src/browser/style/index.css +19 -19
  110. package/src/browser/undo-redo-service.ts +120 -120
  111. package/src/common/language-selector.ts +104 -104
  112. package/src/package.spec.ts +28 -28
@@ -1,36 +1,36 @@
1
- import { NavigationLocation, Position, Range } from './navigation-location';
2
- /**
3
- * A navigation location updater that is responsible for adapting editor navigation locations.
4
- *
5
- * 1. Inserting or deleting text before the position shifts the position accordingly.
6
- * 2. Inserting text at the position offset shifts the position accordingly.
7
- * 3. Inserting or deleting text strictly contained by the position shrinks or stretches the position.
8
- * 4. Inserting or deleting text after a position does not affect the position.
9
- * 5. Deleting text which strictly contains the position deletes the position.
10
- * Note that the position is not deleted if its only shrunken to length zero. To delete a position, the modification must delete from
11
- * strictly before to strictly after the position.
12
- * 6. Replacing text contained by the position shrinks or expands the position (but does not shift it), such that the final position
13
- * contains the original position and the replacing text.
14
- * 7. Replacing text overlapping the position in other ways is considered as a sequence of first deleting the replaced text and
15
- * afterwards inserting the new text. Thus, a position is shrunken and can then be shifted (if the replaced text overlaps the offset of the position).
16
- */
17
- export declare class NavigationLocationUpdater {
18
- /**
19
- * Checks whether `candidateLocation` has to be updated when applying `other`.
20
- * - `false` if the `other` does not affect the `candidateLocation`.
21
- * - A `NavigationLocation` object if the `candidateLocation` has to be replaced with the return value.
22
- * - `undefined` if the candidate has to be deleted.
23
- *
24
- * If the `otherLocation` is not a `ContentChangeLocation` or it does not contain any actual content changes, this method returns with `false`
25
- */
26
- affects(candidateLocation: NavigationLocation, otherLocation: NavigationLocation): false | NavigationLocation | undefined;
27
- protected handleInside(candidate: NavigationLocation, endLine: number, endCharacter: number): NavigationLocation.Context;
28
- protected handleBefore(candidate: NavigationLocation, modification: Range, lineDiff: number, startCharacter: number, endCharacter: number): NavigationLocation.Context;
29
- protected shiftLine(position: Position, diff: number): Position;
30
- protected shiftLine(range: Range, diff: number): Range;
31
- /**
32
- * `true` if `subRange` is strictly contained in the `range`. Otherwise, `false`.
33
- */
34
- protected contained(subRange: Range, range: Range): boolean;
35
- }
1
+ import { NavigationLocation, Position, Range } from './navigation-location';
2
+ /**
3
+ * A navigation location updater that is responsible for adapting editor navigation locations.
4
+ *
5
+ * 1. Inserting or deleting text before the position shifts the position accordingly.
6
+ * 2. Inserting text at the position offset shifts the position accordingly.
7
+ * 3. Inserting or deleting text strictly contained by the position shrinks or stretches the position.
8
+ * 4. Inserting or deleting text after a position does not affect the position.
9
+ * 5. Deleting text which strictly contains the position deletes the position.
10
+ * Note that the position is not deleted if its only shrunken to length zero. To delete a position, the modification must delete from
11
+ * strictly before to strictly after the position.
12
+ * 6. Replacing text contained by the position shrinks or expands the position (but does not shift it), such that the final position
13
+ * contains the original position and the replacing text.
14
+ * 7. Replacing text overlapping the position in other ways is considered as a sequence of first deleting the replaced text and
15
+ * afterwards inserting the new text. Thus, a position is shrunken and can then be shifted (if the replaced text overlaps the offset of the position).
16
+ */
17
+ export declare class NavigationLocationUpdater {
18
+ /**
19
+ * Checks whether `candidateLocation` has to be updated when applying `other`.
20
+ * - `false` if the `other` does not affect the `candidateLocation`.
21
+ * - A `NavigationLocation` object if the `candidateLocation` has to be replaced with the return value.
22
+ * - `undefined` if the candidate has to be deleted.
23
+ *
24
+ * If the `otherLocation` is not a `ContentChangeLocation` or it does not contain any actual content changes, this method returns with `false`
25
+ */
26
+ affects(candidateLocation: NavigationLocation, otherLocation: NavigationLocation): false | NavigationLocation | undefined;
27
+ protected handleInside(candidate: NavigationLocation, endLine: number, endCharacter: number): NavigationLocation.Context;
28
+ protected handleBefore(candidate: NavigationLocation, modification: Range, lineDiff: number, startCharacter: number, endCharacter: number): NavigationLocation.Context;
29
+ protected shiftLine(position: Position, diff: number): Position;
30
+ protected shiftLine(range: Range, diff: number): Range;
31
+ /**
32
+ * `true` if `subRange` is strictly contained in the `range`. Otherwise, `false`.
33
+ */
34
+ protected contained(subRange: Range, range: Range): boolean;
35
+ }
36
36
  //# sourceMappingURL=navigation-location-updater.d.ts.map
@@ -1,211 +1,211 @@
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
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
- return c > 3 && r && Object.defineProperty(target, key, r), r;
22
- };
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.NavigationLocationUpdater = void 0;
25
- const inversify_1 = require("@theia/core/shared/inversify");
26
- const navigation_location_1 = require("./navigation-location");
27
- /**
28
- * A navigation location updater that is responsible for adapting editor navigation locations.
29
- *
30
- * 1. Inserting or deleting text before the position shifts the position accordingly.
31
- * 2. Inserting text at the position offset shifts the position accordingly.
32
- * 3. Inserting or deleting text strictly contained by the position shrinks or stretches the position.
33
- * 4. Inserting or deleting text after a position does not affect the position.
34
- * 5. Deleting text which strictly contains the position deletes the position.
35
- * Note that the position is not deleted if its only shrunken to length zero. To delete a position, the modification must delete from
36
- * strictly before to strictly after the position.
37
- * 6. Replacing text contained by the position shrinks or expands the position (but does not shift it), such that the final position
38
- * contains the original position and the replacing text.
39
- * 7. Replacing text overlapping the position in other ways is considered as a sequence of first deleting the replaced text and
40
- * afterwards inserting the new text. Thus, a position is shrunken and can then be shifted (if the replaced text overlaps the offset of the position).
41
- */
42
- let NavigationLocationUpdater = class NavigationLocationUpdater {
43
- /**
44
- * Checks whether `candidateLocation` has to be updated when applying `other`.
45
- * - `false` if the `other` does not affect the `candidateLocation`.
46
- * - A `NavigationLocation` object if the `candidateLocation` has to be replaced with the return value.
47
- * - `undefined` if the candidate has to be deleted.
48
- *
49
- * If the `otherLocation` is not a `ContentChangeLocation` or it does not contain any actual content changes, this method returns with `false`
50
- */
51
- affects(candidateLocation, otherLocation) {
52
- if (!navigation_location_1.ContentChangeLocation.is(otherLocation)) {
53
- return false;
54
- }
55
- if (candidateLocation.uri.toString() !== otherLocation.uri.toString()) {
56
- return false;
57
- }
58
- const candidate = navigation_location_1.NavigationLocation.range(candidateLocation);
59
- const other = navigation_location_1.NavigationLocation.range(otherLocation);
60
- if (candidate === undefined || other === undefined) {
61
- return false;
62
- }
63
- const { uri, type } = candidateLocation;
64
- const modification = otherLocation.context.text;
65
- const newLineCount = modification.split(/[\n\r]/g).length - 1;
66
- // Spec (1. and 2.)
67
- if (other.end.line < candidate.start.line
68
- || (other.end.line === candidate.start.line && other.end.character <= candidate.start.character)) {
69
- // Shortcut for the general case. The user is typing above the candidate range. Nothing to do.
70
- if (other.start.line === other.end.line && newLineCount === 0) {
71
- return false;
72
- }
73
- const lineDiff = other.start.line - other.end.line + newLineCount;
74
- let startCharacter = candidate.start.character;
75
- let endCharacter = candidate.end.character;
76
- if (other.start.line !== other.end.line) {
77
- startCharacter = other.start.character + (candidate.start.character - other.end.character) + (modification.length - (modification.lastIndexOf('\n') + 1));
78
- endCharacter = candidate.start.line === candidate.end.line
79
- ? candidate.end.character + startCharacter - candidate.start.character
80
- : candidate.end.character;
81
- }
82
- const context = this.handleBefore(candidateLocation, other, lineDiff, startCharacter, endCharacter);
83
- return {
84
- uri,
85
- type,
86
- context
87
- };
88
- }
89
- // Spec (3., 5., and 6.)
90
- if (this.contained(other, candidate)) {
91
- const endLine = candidate.end.line - other.end.line + candidate.start.line + newLineCount;
92
- let endCharacter = candidate.end.character - (other.end.character - other.start.character) + modification.length;
93
- if (newLineCount > 0) {
94
- if (candidate.end.line === other.end.line) {
95
- endCharacter = modification.length - (modification.lastIndexOf('\n') + 1) + (candidate.end.character - other.end.character);
96
- }
97
- else {
98
- endCharacter = endCharacter - 1;
99
- }
100
- }
101
- const context = this.handleInside(candidateLocation, endLine, endCharacter);
102
- return {
103
- uri,
104
- type,
105
- context
106
- };
107
- }
108
- // Spec (5.)
109
- if (other.start.line === candidate.start.line && other.start.character === candidate.start.character
110
- && (other.end.line > candidate.end.line || (other.end.line === candidate.end.line && other.end.character > candidate.end.character))) {
111
- return undefined;
112
- }
113
- // Spec (4.)
114
- if (candidate.end.line < other.start.line
115
- || (candidate.end.line === other.start.line && candidate.end.character < other.end.character)) {
116
- return false;
117
- }
118
- return false;
119
- }
120
- handleInside(candidate, endLine, endCharacter) {
121
- if (navigation_location_1.CursorLocation.is(candidate)) {
122
- throw new Error('Modifications are not allowed inside a cursor location.');
123
- }
124
- const { start } = navigation_location_1.NavigationLocation.range(candidate);
125
- const range = {
126
- start,
127
- end: {
128
- line: endLine,
129
- character: endCharacter
130
- }
131
- };
132
- if (navigation_location_1.SelectionLocation.is(candidate)) {
133
- return range;
134
- }
135
- if (navigation_location_1.ContentChangeLocation.is(candidate)) {
136
- const { rangeLength, text } = candidate.context;
137
- return {
138
- range,
139
- rangeLength,
140
- text
141
- };
142
- }
143
- throw new Error(`Unexpected navigation location: ${navigation_location_1.NavigationLocation.toString(candidate)}.`);
144
- }
145
- handleBefore(candidate, modification, lineDiff, startCharacter, endCharacter) {
146
- let range = navigation_location_1.NavigationLocation.range(candidate);
147
- range = this.shiftLine(range, lineDiff);
148
- range = {
149
- start: {
150
- line: range.start.line,
151
- character: startCharacter
152
- },
153
- end: {
154
- line: range.end.line,
155
- character: endCharacter
156
- }
157
- };
158
- if (navigation_location_1.CursorLocation.is(candidate)) {
159
- return range.start;
160
- }
161
- if (navigation_location_1.SelectionLocation.is(candidate)) {
162
- return range;
163
- }
164
- if (navigation_location_1.ContentChangeLocation.is(candidate)) {
165
- const { rangeLength, text } = candidate.context;
166
- return {
167
- range,
168
- rangeLength,
169
- text
170
- };
171
- }
172
- throw new Error(`Unexpected navigation location: ${navigation_location_1.NavigationLocation.toString(candidate)}.`);
173
- }
174
- shiftLine(input, diff) {
175
- if (navigation_location_1.Position.is(input)) {
176
- const { line, character } = input;
177
- return {
178
- line: line + diff,
179
- character
180
- };
181
- }
182
- const { start, end } = input;
183
- return {
184
- start: this.shiftLine(start, diff),
185
- end: this.shiftLine(end, diff)
186
- };
187
- }
188
- /**
189
- * `true` if `subRange` is strictly contained in the `range`. Otherwise, `false`.
190
- */
191
- contained(subRange, range) {
192
- if (subRange.start.line > range.start.line && subRange.end.line < range.end.line) {
193
- return true;
194
- }
195
- if (subRange.start.line < range.start.line || subRange.end.line > range.end.line) {
196
- return false;
197
- }
198
- if (subRange.start.line === range.start.line && subRange.start.character < range.start.character) {
199
- return false;
200
- }
201
- if (subRange.end.line === range.end.line && subRange.end.character > range.end.character) {
202
- return false;
203
- }
204
- return true;
205
- }
206
- };
207
- NavigationLocationUpdater = __decorate([
208
- (0, inversify_1.injectable)()
209
- ], NavigationLocationUpdater);
210
- exports.NavigationLocationUpdater = NavigationLocationUpdater;
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
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.NavigationLocationUpdater = void 0;
25
+ const inversify_1 = require("@theia/core/shared/inversify");
26
+ const navigation_location_1 = require("./navigation-location");
27
+ /**
28
+ * A navigation location updater that is responsible for adapting editor navigation locations.
29
+ *
30
+ * 1. Inserting or deleting text before the position shifts the position accordingly.
31
+ * 2. Inserting text at the position offset shifts the position accordingly.
32
+ * 3. Inserting or deleting text strictly contained by the position shrinks or stretches the position.
33
+ * 4. Inserting or deleting text after a position does not affect the position.
34
+ * 5. Deleting text which strictly contains the position deletes the position.
35
+ * Note that the position is not deleted if its only shrunken to length zero. To delete a position, the modification must delete from
36
+ * strictly before to strictly after the position.
37
+ * 6. Replacing text contained by the position shrinks or expands the position (but does not shift it), such that the final position
38
+ * contains the original position and the replacing text.
39
+ * 7. Replacing text overlapping the position in other ways is considered as a sequence of first deleting the replaced text and
40
+ * afterwards inserting the new text. Thus, a position is shrunken and can then be shifted (if the replaced text overlaps the offset of the position).
41
+ */
42
+ let NavigationLocationUpdater = class NavigationLocationUpdater {
43
+ /**
44
+ * Checks whether `candidateLocation` has to be updated when applying `other`.
45
+ * - `false` if the `other` does not affect the `candidateLocation`.
46
+ * - A `NavigationLocation` object if the `candidateLocation` has to be replaced with the return value.
47
+ * - `undefined` if the candidate has to be deleted.
48
+ *
49
+ * If the `otherLocation` is not a `ContentChangeLocation` or it does not contain any actual content changes, this method returns with `false`
50
+ */
51
+ affects(candidateLocation, otherLocation) {
52
+ if (!navigation_location_1.ContentChangeLocation.is(otherLocation)) {
53
+ return false;
54
+ }
55
+ if (candidateLocation.uri.toString() !== otherLocation.uri.toString()) {
56
+ return false;
57
+ }
58
+ const candidate = navigation_location_1.NavigationLocation.range(candidateLocation);
59
+ const other = navigation_location_1.NavigationLocation.range(otherLocation);
60
+ if (candidate === undefined || other === undefined) {
61
+ return false;
62
+ }
63
+ const { uri, type } = candidateLocation;
64
+ const modification = otherLocation.context.text;
65
+ const newLineCount = modification.split(/[\n\r]/g).length - 1;
66
+ // Spec (1. and 2.)
67
+ if (other.end.line < candidate.start.line
68
+ || (other.end.line === candidate.start.line && other.end.character <= candidate.start.character)) {
69
+ // Shortcut for the general case. The user is typing above the candidate range. Nothing to do.
70
+ if (other.start.line === other.end.line && newLineCount === 0) {
71
+ return false;
72
+ }
73
+ const lineDiff = other.start.line - other.end.line + newLineCount;
74
+ let startCharacter = candidate.start.character;
75
+ let endCharacter = candidate.end.character;
76
+ if (other.start.line !== other.end.line) {
77
+ startCharacter = other.start.character + (candidate.start.character - other.end.character) + (modification.length - (modification.lastIndexOf('\n') + 1));
78
+ endCharacter = candidate.start.line === candidate.end.line
79
+ ? candidate.end.character + startCharacter - candidate.start.character
80
+ : candidate.end.character;
81
+ }
82
+ const context = this.handleBefore(candidateLocation, other, lineDiff, startCharacter, endCharacter);
83
+ return {
84
+ uri,
85
+ type,
86
+ context
87
+ };
88
+ }
89
+ // Spec (3., 5., and 6.)
90
+ if (this.contained(other, candidate)) {
91
+ const endLine = candidate.end.line - other.end.line + candidate.start.line + newLineCount;
92
+ let endCharacter = candidate.end.character - (other.end.character - other.start.character) + modification.length;
93
+ if (newLineCount > 0) {
94
+ if (candidate.end.line === other.end.line) {
95
+ endCharacter = modification.length - (modification.lastIndexOf('\n') + 1) + (candidate.end.character - other.end.character);
96
+ }
97
+ else {
98
+ endCharacter = endCharacter - 1;
99
+ }
100
+ }
101
+ const context = this.handleInside(candidateLocation, endLine, endCharacter);
102
+ return {
103
+ uri,
104
+ type,
105
+ context
106
+ };
107
+ }
108
+ // Spec (5.)
109
+ if (other.start.line === candidate.start.line && other.start.character === candidate.start.character
110
+ && (other.end.line > candidate.end.line || (other.end.line === candidate.end.line && other.end.character > candidate.end.character))) {
111
+ return undefined;
112
+ }
113
+ // Spec (4.)
114
+ if (candidate.end.line < other.start.line
115
+ || (candidate.end.line === other.start.line && candidate.end.character < other.end.character)) {
116
+ return false;
117
+ }
118
+ return false;
119
+ }
120
+ handleInside(candidate, endLine, endCharacter) {
121
+ if (navigation_location_1.CursorLocation.is(candidate)) {
122
+ throw new Error('Modifications are not allowed inside a cursor location.');
123
+ }
124
+ const { start } = navigation_location_1.NavigationLocation.range(candidate);
125
+ const range = {
126
+ start,
127
+ end: {
128
+ line: endLine,
129
+ character: endCharacter
130
+ }
131
+ };
132
+ if (navigation_location_1.SelectionLocation.is(candidate)) {
133
+ return range;
134
+ }
135
+ if (navigation_location_1.ContentChangeLocation.is(candidate)) {
136
+ const { rangeLength, text } = candidate.context;
137
+ return {
138
+ range,
139
+ rangeLength,
140
+ text
141
+ };
142
+ }
143
+ throw new Error(`Unexpected navigation location: ${navigation_location_1.NavigationLocation.toString(candidate)}.`);
144
+ }
145
+ handleBefore(candidate, modification, lineDiff, startCharacter, endCharacter) {
146
+ let range = navigation_location_1.NavigationLocation.range(candidate);
147
+ range = this.shiftLine(range, lineDiff);
148
+ range = {
149
+ start: {
150
+ line: range.start.line,
151
+ character: startCharacter
152
+ },
153
+ end: {
154
+ line: range.end.line,
155
+ character: endCharacter
156
+ }
157
+ };
158
+ if (navigation_location_1.CursorLocation.is(candidate)) {
159
+ return range.start;
160
+ }
161
+ if (navigation_location_1.SelectionLocation.is(candidate)) {
162
+ return range;
163
+ }
164
+ if (navigation_location_1.ContentChangeLocation.is(candidate)) {
165
+ const { rangeLength, text } = candidate.context;
166
+ return {
167
+ range,
168
+ rangeLength,
169
+ text
170
+ };
171
+ }
172
+ throw new Error(`Unexpected navigation location: ${navigation_location_1.NavigationLocation.toString(candidate)}.`);
173
+ }
174
+ shiftLine(input, diff) {
175
+ if (navigation_location_1.Position.is(input)) {
176
+ const { line, character } = input;
177
+ return {
178
+ line: line + diff,
179
+ character
180
+ };
181
+ }
182
+ const { start, end } = input;
183
+ return {
184
+ start: this.shiftLine(start, diff),
185
+ end: this.shiftLine(end, diff)
186
+ };
187
+ }
188
+ /**
189
+ * `true` if `subRange` is strictly contained in the `range`. Otherwise, `false`.
190
+ */
191
+ contained(subRange, range) {
192
+ if (subRange.start.line > range.start.line && subRange.end.line < range.end.line) {
193
+ return true;
194
+ }
195
+ if (subRange.start.line < range.start.line || subRange.end.line > range.end.line) {
196
+ return false;
197
+ }
198
+ if (subRange.start.line === range.start.line && subRange.start.character < range.start.character) {
199
+ return false;
200
+ }
201
+ if (subRange.end.line === range.end.line && subRange.end.character > range.end.character) {
202
+ return false;
203
+ }
204
+ return true;
205
+ }
206
+ };
207
+ NavigationLocationUpdater = __decorate([
208
+ (0, inversify_1.injectable)()
209
+ ], NavigationLocationUpdater);
210
+ exports.NavigationLocationUpdater = NavigationLocationUpdater;
211
211
  //# sourceMappingURL=navigation-location-updater.js.map
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=navigation-location-updater.spec.d.ts.map