@theia/editor 1.53.0-next.4 → 1.53.0-next.55

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 (48) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/editor-manager.d.ts.map +1 -1
  3. package/lib/browser/editor-manager.js +11 -4
  4. package/lib/browser/editor-manager.js.map +1 -1
  5. package/lib/browser/editor-variable-contribution.d.ts.map +1 -1
  6. package/lib/browser/editor-variable-contribution.js +9 -1
  7. package/lib/browser/editor-variable-contribution.js.map +1 -1
  8. package/lib/browser/editor.d.ts +5 -2
  9. package/lib/browser/editor.d.ts.map +1 -1
  10. package/lib/browser/editor.js.map +1 -1
  11. package/lib/browser/navigation/navigation-location-service.js +3 -3
  12. package/package.json +5 -5
  13. package/src/browser/decorations/editor-decoration-style.ts +41 -41
  14. package/src/browser/decorations/editor-decoration.ts +127 -127
  15. package/src/browser/decorations/editor-decorator.ts +36 -36
  16. package/src/browser/decorations/index.ts +19 -19
  17. package/src/browser/diff-navigator.ts +27 -27
  18. package/src/browser/editor-command.ts +393 -393
  19. package/src/browser/editor-contribution.ts +185 -185
  20. package/src/browser/editor-frontend-module.ts +90 -90
  21. package/src/browser/editor-generated-preference-schema.ts +2956 -2956
  22. package/src/browser/editor-keybinding.ts +55 -55
  23. package/src/browser/editor-language-quick-pick-service.ts +68 -68
  24. package/src/browser/editor-linenumber-contribution.ts +88 -88
  25. package/src/browser/editor-manager.ts +462 -452
  26. package/src/browser/editor-menu.ts +224 -224
  27. package/src/browser/editor-navigation-contribution.ts +343 -343
  28. package/src/browser/editor-preferences.ts +226 -226
  29. package/src/browser/editor-variable-contribution.ts +62 -54
  30. package/src/browser/editor-widget-factory.ts +82 -82
  31. package/src/browser/editor-widget.ts +139 -139
  32. package/src/browser/editor.ts +366 -362
  33. package/src/browser/index.ts +26 -26
  34. package/src/browser/language-status/editor-language-status-service.ts +271 -271
  35. package/src/browser/language-status/editor-language-status.css +101 -101
  36. package/src/browser/navigation/navigation-location-service.spec.ts +245 -245
  37. package/src/browser/navigation/navigation-location-service.ts +284 -284
  38. package/src/browser/navigation/navigation-location-similarity.spec.ts +46 -46
  39. package/src/browser/navigation/navigation-location-similarity.ts +58 -58
  40. package/src/browser/navigation/navigation-location-updater.spec.ts +197 -197
  41. package/src/browser/navigation/navigation-location-updater.ts +220 -220
  42. package/src/browser/navigation/navigation-location.ts +418 -418
  43. package/src/browser/navigation/test/mock-navigation-location-updater.ts +41 -41
  44. package/src/browser/quick-editor-service.ts +94 -94
  45. package/src/browser/style/index.css +19 -19
  46. package/src/browser/undo-redo-service.ts +120 -120
  47. package/src/common/language-selector.ts +104 -104
  48. package/src/package.spec.ts +28 -28
@@ -1,220 +1,220 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { injectable } from '@theia/core/shared/inversify';
18
- import { NavigationLocation, ContentChangeLocation, CursorLocation, SelectionLocation, Position, Range } from './navigation-location';
19
-
20
- /**
21
- * A navigation location updater that is responsible for adapting editor navigation locations.
22
- *
23
- * 1. Inserting or deleting text before the position shifts the position accordingly.
24
- * 2. Inserting text at the position offset shifts the position accordingly.
25
- * 3. Inserting or deleting text strictly contained by the position shrinks or stretches the position.
26
- * 4. Inserting or deleting text after a position does not affect the position.
27
- * 5. Deleting text which strictly contains the position deletes the position.
28
- * Note that the position is not deleted if its only shrunken to length zero. To delete a position, the modification must delete from
29
- * strictly before to strictly after the position.
30
- * 6. Replacing text contained by the position shrinks or expands the position (but does not shift it), such that the final position
31
- * contains the original position and the replacing text.
32
- * 7. Replacing text overlapping the position in other ways is considered as a sequence of first deleting the replaced text and
33
- * 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).
34
- */
35
- @injectable()
36
- export class NavigationLocationUpdater {
37
-
38
- /**
39
- * Checks whether `candidateLocation` has to be updated when applying `other`.
40
- * - `false` if the `other` does not affect the `candidateLocation`.
41
- * - A `NavigationLocation` object if the `candidateLocation` has to be replaced with the return value.
42
- * - `undefined` if the candidate has to be deleted.
43
- *
44
- * If the `otherLocation` is not a `ContentChangeLocation` or it does not contain any actual content changes, this method returns with `false`
45
- */
46
- affects(candidateLocation: NavigationLocation, otherLocation: NavigationLocation): false | NavigationLocation | undefined {
47
- if (!ContentChangeLocation.is(otherLocation)) {
48
- return false;
49
- }
50
- if (candidateLocation.uri.toString() !== otherLocation.uri.toString()) {
51
- return false;
52
- }
53
-
54
- const candidate = NavigationLocation.range(candidateLocation);
55
- const other = NavigationLocation.range(otherLocation);
56
- if (candidate === undefined || other === undefined) {
57
- return false;
58
- }
59
-
60
- const { uri, type } = candidateLocation;
61
- const modification = otherLocation.context.text;
62
- const newLineCount = modification.split(/[\n\r]/g).length - 1;
63
-
64
- // Spec (1. and 2.)
65
- if (other.end.line < candidate.start.line
66
- || (other.end.line === candidate.start.line && other.end.character <= candidate.start.character)) {
67
-
68
- // Shortcut for the general case. The user is typing above the candidate range. Nothing to do.
69
- if (other.start.line === other.end.line && newLineCount === 0) {
70
- return false;
71
- }
72
-
73
- const lineDiff = other.start.line - other.end.line + newLineCount;
74
- let startCharacter = candidate.start.character;
75
- let endCharacter = candidate.end.character;
76
-
77
- if (other.start.line !== other.end.line) {
78
- startCharacter = other.start.character + (candidate.start.character - other.end.character) + (modification.length - (modification.lastIndexOf('\n') + 1));
79
- endCharacter = candidate.start.line === candidate.end.line
80
- ? candidate.end.character + startCharacter - candidate.start.character
81
- : candidate.end.character;
82
- }
83
-
84
- const context = this.handleBefore(candidateLocation, other, lineDiff, startCharacter, endCharacter);
85
- return {
86
- uri,
87
- type,
88
- context
89
- };
90
- }
91
-
92
- // Spec (3., 5., and 6.)
93
- if (this.contained(other, candidate)) {
94
- const endLine = candidate.end.line - other.end.line + candidate.start.line + newLineCount;
95
- let endCharacter = candidate.end.character - (other.end.character - other.start.character) + modification.length;
96
-
97
- if (newLineCount > 0) {
98
- if (candidate.end.line === other.end.line) {
99
- endCharacter = modification.length - (modification.lastIndexOf('\n') + 1) + (candidate.end.character - other.end.character);
100
- } else {
101
- endCharacter = endCharacter - 1;
102
- }
103
- }
104
-
105
- const context = this.handleInside(candidateLocation, endLine, endCharacter);
106
- return {
107
- uri,
108
- type,
109
- context
110
- };
111
- }
112
-
113
- // Spec (5.)
114
- if (other.start.line === candidate.start.line && other.start.character === candidate.start.character
115
- && (other.end.line > candidate.end.line || (other.end.line === candidate.end.line && other.end.character > candidate.end.character))) {
116
- return undefined;
117
- }
118
-
119
- // Spec (4.)
120
- if (candidate.end.line < other.start.line
121
- || (candidate.end.line === other.start.line && candidate.end.character < other.end.character)) {
122
- return false;
123
- }
124
-
125
- return false;
126
- }
127
-
128
- protected handleInside(candidate: NavigationLocation, endLine: number, endCharacter: number): NavigationLocation.Context {
129
- if (CursorLocation.is(candidate)) {
130
- throw new Error('Modifications are not allowed inside a cursor location.');
131
- }
132
- const { start } = NavigationLocation.range(candidate);
133
- const range = {
134
- start,
135
- end: {
136
- line: endLine,
137
- character: endCharacter
138
- }
139
- };
140
- if (SelectionLocation.is(candidate)) {
141
- return range;
142
- }
143
- if (ContentChangeLocation.is(candidate)) {
144
- const { rangeLength, text } = candidate.context;
145
- return {
146
- range,
147
- rangeLength,
148
- text
149
- };
150
- }
151
- throw new Error(`Unexpected navigation location: ${NavigationLocation.toString(candidate)}.`);
152
- }
153
-
154
- protected handleBefore(candidate: NavigationLocation, modification: Range, lineDiff: number, startCharacter: number, endCharacter: number): NavigationLocation.Context {
155
- let range = NavigationLocation.range(candidate);
156
- range = this.shiftLine(range, lineDiff);
157
- range = {
158
- start: {
159
- line: range.start.line,
160
- character: startCharacter
161
- },
162
- end: {
163
- line: range.end.line,
164
- character: endCharacter
165
- }
166
- };
167
- if (CursorLocation.is(candidate)) {
168
- return range.start;
169
- }
170
- if (SelectionLocation.is(candidate)) {
171
- return range;
172
- }
173
- if (ContentChangeLocation.is(candidate)) {
174
- const { rangeLength, text } = candidate.context;
175
- return {
176
- range,
177
- rangeLength,
178
- text
179
- };
180
- }
181
- throw new Error(`Unexpected navigation location: ${NavigationLocation.toString(candidate)}.`);
182
- }
183
-
184
- protected shiftLine(position: Position, diff: number): Position;
185
- protected shiftLine(range: Range, diff: number): Range;
186
- protected shiftLine(input: Position | Range, diff: number): Position | Range {
187
- if (Position.is(input)) {
188
- const { line, character } = input;
189
- return {
190
- line: line + diff,
191
- character
192
- };
193
- }
194
- const { start, end } = input;
195
- return {
196
- start: this.shiftLine(start, diff),
197
- end: this.shiftLine(end, diff)
198
- };
199
- }
200
-
201
- /**
202
- * `true` if `subRange` is strictly contained in the `range`. Otherwise, `false`.
203
- */
204
- protected contained(subRange: Range, range: Range): boolean {
205
- if (subRange.start.line > range.start.line && subRange.end.line < range.end.line) {
206
- return true;
207
- }
208
- if (subRange.start.line < range.start.line || subRange.end.line > range.end.line) {
209
- return false;
210
- }
211
- if (subRange.start.line === range.start.line && subRange.start.character < range.start.character) {
212
- return false;
213
- }
214
- if (subRange.end.line === range.end.line && subRange.end.character > range.end.character) {
215
- return false;
216
- }
217
- return true;
218
- }
219
-
220
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { injectable } from '@theia/core/shared/inversify';
18
+ import { NavigationLocation, ContentChangeLocation, CursorLocation, SelectionLocation, Position, Range } from './navigation-location';
19
+
20
+ /**
21
+ * A navigation location updater that is responsible for adapting editor navigation locations.
22
+ *
23
+ * 1. Inserting or deleting text before the position shifts the position accordingly.
24
+ * 2. Inserting text at the position offset shifts the position accordingly.
25
+ * 3. Inserting or deleting text strictly contained by the position shrinks or stretches the position.
26
+ * 4. Inserting or deleting text after a position does not affect the position.
27
+ * 5. Deleting text which strictly contains the position deletes the position.
28
+ * Note that the position is not deleted if its only shrunken to length zero. To delete a position, the modification must delete from
29
+ * strictly before to strictly after the position.
30
+ * 6. Replacing text contained by the position shrinks or expands the position (but does not shift it), such that the final position
31
+ * contains the original position and the replacing text.
32
+ * 7. Replacing text overlapping the position in other ways is considered as a sequence of first deleting the replaced text and
33
+ * 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).
34
+ */
35
+ @injectable()
36
+ export class NavigationLocationUpdater {
37
+
38
+ /**
39
+ * Checks whether `candidateLocation` has to be updated when applying `other`.
40
+ * - `false` if the `other` does not affect the `candidateLocation`.
41
+ * - A `NavigationLocation` object if the `candidateLocation` has to be replaced with the return value.
42
+ * - `undefined` if the candidate has to be deleted.
43
+ *
44
+ * If the `otherLocation` is not a `ContentChangeLocation` or it does not contain any actual content changes, this method returns with `false`
45
+ */
46
+ affects(candidateLocation: NavigationLocation, otherLocation: NavigationLocation): false | NavigationLocation | undefined {
47
+ if (!ContentChangeLocation.is(otherLocation)) {
48
+ return false;
49
+ }
50
+ if (candidateLocation.uri.toString() !== otherLocation.uri.toString()) {
51
+ return false;
52
+ }
53
+
54
+ const candidate = NavigationLocation.range(candidateLocation);
55
+ const other = NavigationLocation.range(otherLocation);
56
+ if (candidate === undefined || other === undefined) {
57
+ return false;
58
+ }
59
+
60
+ const { uri, type } = candidateLocation;
61
+ const modification = otherLocation.context.text;
62
+ const newLineCount = modification.split(/[\n\r]/g).length - 1;
63
+
64
+ // Spec (1. and 2.)
65
+ if (other.end.line < candidate.start.line
66
+ || (other.end.line === candidate.start.line && other.end.character <= candidate.start.character)) {
67
+
68
+ // Shortcut for the general case. The user is typing above the candidate range. Nothing to do.
69
+ if (other.start.line === other.end.line && newLineCount === 0) {
70
+ return false;
71
+ }
72
+
73
+ const lineDiff = other.start.line - other.end.line + newLineCount;
74
+ let startCharacter = candidate.start.character;
75
+ let endCharacter = candidate.end.character;
76
+
77
+ if (other.start.line !== other.end.line) {
78
+ startCharacter = other.start.character + (candidate.start.character - other.end.character) + (modification.length - (modification.lastIndexOf('\n') + 1));
79
+ endCharacter = candidate.start.line === candidate.end.line
80
+ ? candidate.end.character + startCharacter - candidate.start.character
81
+ : candidate.end.character;
82
+ }
83
+
84
+ const context = this.handleBefore(candidateLocation, other, lineDiff, startCharacter, endCharacter);
85
+ return {
86
+ uri,
87
+ type,
88
+ context
89
+ };
90
+ }
91
+
92
+ // Spec (3., 5., and 6.)
93
+ if (this.contained(other, candidate)) {
94
+ const endLine = candidate.end.line - other.end.line + candidate.start.line + newLineCount;
95
+ let endCharacter = candidate.end.character - (other.end.character - other.start.character) + modification.length;
96
+
97
+ if (newLineCount > 0) {
98
+ if (candidate.end.line === other.end.line) {
99
+ endCharacter = modification.length - (modification.lastIndexOf('\n') + 1) + (candidate.end.character - other.end.character);
100
+ } else {
101
+ endCharacter = endCharacter - 1;
102
+ }
103
+ }
104
+
105
+ const context = this.handleInside(candidateLocation, endLine, endCharacter);
106
+ return {
107
+ uri,
108
+ type,
109
+ context
110
+ };
111
+ }
112
+
113
+ // Spec (5.)
114
+ if (other.start.line === candidate.start.line && other.start.character === candidate.start.character
115
+ && (other.end.line > candidate.end.line || (other.end.line === candidate.end.line && other.end.character > candidate.end.character))) {
116
+ return undefined;
117
+ }
118
+
119
+ // Spec (4.)
120
+ if (candidate.end.line < other.start.line
121
+ || (candidate.end.line === other.start.line && candidate.end.character < other.end.character)) {
122
+ return false;
123
+ }
124
+
125
+ return false;
126
+ }
127
+
128
+ protected handleInside(candidate: NavigationLocation, endLine: number, endCharacter: number): NavigationLocation.Context {
129
+ if (CursorLocation.is(candidate)) {
130
+ throw new Error('Modifications are not allowed inside a cursor location.');
131
+ }
132
+ const { start } = NavigationLocation.range(candidate);
133
+ const range = {
134
+ start,
135
+ end: {
136
+ line: endLine,
137
+ character: endCharacter
138
+ }
139
+ };
140
+ if (SelectionLocation.is(candidate)) {
141
+ return range;
142
+ }
143
+ if (ContentChangeLocation.is(candidate)) {
144
+ const { rangeLength, text } = candidate.context;
145
+ return {
146
+ range,
147
+ rangeLength,
148
+ text
149
+ };
150
+ }
151
+ throw new Error(`Unexpected navigation location: ${NavigationLocation.toString(candidate)}.`);
152
+ }
153
+
154
+ protected handleBefore(candidate: NavigationLocation, modification: Range, lineDiff: number, startCharacter: number, endCharacter: number): NavigationLocation.Context {
155
+ let range = NavigationLocation.range(candidate);
156
+ range = this.shiftLine(range, lineDiff);
157
+ range = {
158
+ start: {
159
+ line: range.start.line,
160
+ character: startCharacter
161
+ },
162
+ end: {
163
+ line: range.end.line,
164
+ character: endCharacter
165
+ }
166
+ };
167
+ if (CursorLocation.is(candidate)) {
168
+ return range.start;
169
+ }
170
+ if (SelectionLocation.is(candidate)) {
171
+ return range;
172
+ }
173
+ if (ContentChangeLocation.is(candidate)) {
174
+ const { rangeLength, text } = candidate.context;
175
+ return {
176
+ range,
177
+ rangeLength,
178
+ text
179
+ };
180
+ }
181
+ throw new Error(`Unexpected navigation location: ${NavigationLocation.toString(candidate)}.`);
182
+ }
183
+
184
+ protected shiftLine(position: Position, diff: number): Position;
185
+ protected shiftLine(range: Range, diff: number): Range;
186
+ protected shiftLine(input: Position | Range, diff: number): Position | Range {
187
+ if (Position.is(input)) {
188
+ const { line, character } = input;
189
+ return {
190
+ line: line + diff,
191
+ character
192
+ };
193
+ }
194
+ const { start, end } = input;
195
+ return {
196
+ start: this.shiftLine(start, diff),
197
+ end: this.shiftLine(end, diff)
198
+ };
199
+ }
200
+
201
+ /**
202
+ * `true` if `subRange` is strictly contained in the `range`. Otherwise, `false`.
203
+ */
204
+ protected contained(subRange: Range, range: Range): boolean {
205
+ if (subRange.start.line > range.start.line && subRange.end.line < range.end.line) {
206
+ return true;
207
+ }
208
+ if (subRange.start.line < range.start.line || subRange.end.line > range.end.line) {
209
+ return false;
210
+ }
211
+ if (subRange.start.line === range.start.line && subRange.start.character < range.start.character) {
212
+ return false;
213
+ }
214
+ if (subRange.end.line === range.end.line && subRange.end.character > range.end.character) {
215
+ return false;
216
+ }
217
+ return true;
218
+ }
219
+
220
+ }