chrome-devtools-frontend 1.0.945677 → 1.0.947377

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 (191) hide show
  1. package/.eslintrc.js +1 -0
  2. package/config/gni/all_devtools_files.gni +0 -14
  3. package/config/gni/devtools_grd_files.gni +4 -42
  4. package/front_end/.eslintrc.js +5 -1
  5. package/front_end/core/host/InspectorFrontendHost.ts +0 -3
  6. package/front_end/core/host/InspectorFrontendHostAPI.ts +0 -1
  7. package/front_end/core/host/UserMetrics.ts +0 -22
  8. package/front_end/core/i18n/locales/en-US.json +33 -27
  9. package/front_end/core/i18n/locales/en-XL.json +33 -27
  10. package/front_end/core/root/Runtime.ts +0 -5
  11. package/front_end/core/sdk/AccessibilityModel.ts +0 -2
  12. package/front_end/core/sdk/CSSProperty.ts +16 -11
  13. package/front_end/core/sdk/CSSRule.ts +0 -2
  14. package/front_end/core/sdk/Cookie.ts +1 -5
  15. package/front_end/core/sdk/EmulationModel.ts +0 -2
  16. package/front_end/core/sdk/HeapProfilerModel.ts +0 -2
  17. package/front_end/core/sdk/NetworkManager.ts +0 -3
  18. package/front_end/core/sdk/Resource.ts +0 -3
  19. package/front_end/core/sdk/ResourceTreeModel.ts +0 -3
  20. package/front_end/core/sdk/ServiceWorkerManager.ts +0 -2
  21. package/front_end/core/sdk/sdk-meta.ts +20 -8
  22. package/front_end/devtools_compatibility.js +1 -8
  23. package/front_end/entrypoints/devtools_app/devtools_app.js +3 -0
  24. package/front_end/entrypoints/devtools_app/devtools_app.json +1 -3
  25. package/front_end/entrypoints/formatter_worker/CSSFormatter.ts +1 -3
  26. package/front_end/entrypoints/formatter_worker/FormatterActions.ts +0 -2
  27. package/front_end/entrypoints/formatter_worker/FormatterWorker.ts +0 -120
  28. package/front_end/entrypoints/formatter_worker/formatter_worker-entrypoint.ts +1 -11
  29. package/front_end/entrypoints/formatter_worker/formatter_worker.ts +5 -0
  30. package/front_end/entrypoints/inspector/{inspector.js → inspector.ts} +0 -3
  31. package/front_end/entrypoints/js_app/js_app.js +3 -0
  32. package/front_end/entrypoints/js_app/js_app.json +1 -2
  33. package/front_end/entrypoints/main/MainImpl.ts +0 -6
  34. package/front_end/entrypoints/ndb_app/ndb_app.js +3 -0
  35. package/front_end/entrypoints/ndb_app/ndb_app.json +1 -2
  36. package/front_end/entrypoints/{node_main → node_app}/NodeConnectionsPanel.ts +1 -1
  37. package/front_end/entrypoints/{node_main → node_app}/NodeMain.ts +2 -4
  38. package/front_end/entrypoints/{node_main → node_app}/nodeConnectionsPanel.css +0 -0
  39. package/front_end/entrypoints/node_app/node_app.ts +81 -0
  40. package/front_end/entrypoints/shell/shell.js +18 -1
  41. package/front_end/entrypoints/worker_app/{worker_app.js → worker_app.ts} +8 -2
  42. package/front_end/generated/InspectorBackendCommands.js +5 -1
  43. package/front_end/generated/protocol.d.ts +12 -0
  44. package/front_end/legacy_test_runner/sources_test_runner/sources_test_runner.js +0 -1
  45. package/front_end/models/bindings/CompilerScriptMapping.ts +0 -1
  46. package/front_end/models/bindings/DebuggerLanguagePlugins.ts +4 -11
  47. package/front_end/models/bindings/DebuggerWorkspaceBinding.ts +1 -1
  48. package/front_end/models/bindings/ResourceMapping.ts +1 -1
  49. package/front_end/models/bindings/SASSSourceMapping.ts +0 -1
  50. package/front_end/models/emulation/DeviceModeModel.ts +0 -2
  51. package/front_end/models/formatter/FormatterWorkerPool.ts +0 -18
  52. package/front_end/models/issues_manager/CorsIssue.ts +8 -0
  53. package/front_end/models/text_utils/CodeMirrorUtils.ts +6 -51
  54. package/front_end/models/text_utils/TextUtils.ts +1 -2
  55. package/front_end/models/text_utils/text_utils-legacy.ts +0 -5
  56. package/front_end/panels/animation/AnimationTimeline.ts +0 -2
  57. package/front_end/panels/animation/AnimationUI.ts +0 -2
  58. package/front_end/panels/application/ApplicationPanelSidebar.ts +2 -4
  59. package/front_end/panels/application/BackForwardCacheStrings.ts +1 -0
  60. package/front_end/panels/css_overview/CSSOverviewModel.ts +0 -2
  61. package/front_end/panels/css_overview/CSSOverviewPanel.ts +0 -7
  62. package/front_end/panels/css_overview/CSSOverviewProcessingView.ts +0 -2
  63. package/front_end/panels/elements/ColorSwatchPopoverIcon.ts +0 -11
  64. package/front_end/panels/elements/StylesSidebarPane.ts +0 -1
  65. package/front_end/panels/elements/elementsTreeOutline.css +0 -13
  66. package/front_end/panels/emulation/DeviceModeToolbar.ts +0 -16
  67. package/front_end/panels/issues/CorsIssueDetailsView.ts +6 -2
  68. package/front_end/panels/lighthouse/lighthouse-meta.ts +0 -3
  69. package/front_end/panels/network/NetworkConfigView.ts +10 -0
  70. package/front_end/panels/network/NetworkItemView.ts +3 -0
  71. package/front_end/panels/network/networkConfigView.css +5 -0
  72. package/front_end/panels/profiler/profilesPanel.css +1 -1
  73. package/front_end/panels/search/SearchView.ts +24 -4
  74. package/front_end/panels/settings/emulation/components/UserAgentClientHintsForm.ts +6 -4
  75. package/front_end/panels/settings/emulation/components/userAgentClientHintsForm.css +0 -12
  76. package/front_end/panels/sources/CSSPlugin.ts +3 -0
  77. package/front_end/panels/sources/CoveragePlugin.ts +2 -0
  78. package/front_end/panels/sources/DebuggerPlugin.ts +35 -7
  79. package/front_end/panels/sources/JavaScriptCompilerPlugin.ts +3 -0
  80. package/front_end/panels/sources/ProfilePlugin.ts +3 -0
  81. package/front_end/panels/sources/UISourceCodeFrame.ts +11 -2
  82. package/front_end/panels/sources/sourcesView.css +0 -130
  83. package/front_end/panels/timeline/TimelineTreeView.ts +1 -0
  84. package/front_end/third_party/codemirror/codemirror-tsconfig.json +1 -25
  85. package/front_end/third_party/codemirror.next/chunk/codemirror.js +1 -1
  86. package/front_end/third_party/codemirror.next/chunk/cpp.js +1 -2
  87. package/front_end/third_party/codemirror.next/chunk/java.js +1 -2
  88. package/front_end/third_party/codemirror.next/chunk/json.js +1 -2
  89. package/front_end/third_party/codemirror.next/chunk/markdown.js +1 -2
  90. package/front_end/third_party/codemirror.next/chunk/php.js +1 -2
  91. package/front_end/third_party/codemirror.next/chunk/python.js +1 -2
  92. package/front_end/third_party/codemirror.next/chunk/wast.js +1 -2
  93. package/front_end/third_party/codemirror.next/chunk/xml.js +1 -2
  94. package/front_end/third_party/codemirror.next/codemirror.next.d.ts +1486 -1423
  95. package/front_end/third_party/codemirror.next/codemirror.next.js +1 -2
  96. package/front_end/third_party/codemirror.next/package.json +10 -9
  97. package/front_end/third_party/lighthouse/lighthouse-dt-bundle.js +168 -164
  98. package/front_end/third_party/lighthouse/locales/ar-XB.json +0 -3
  99. package/front_end/third_party/lighthouse/locales/ar.json +0 -3
  100. package/front_end/third_party/lighthouse/locales/bg.json +17 -20
  101. package/front_end/third_party/lighthouse/locales/ca.json +0 -3
  102. package/front_end/third_party/lighthouse/locales/cs.json +0 -3
  103. package/front_end/third_party/lighthouse/locales/da.json +16 -19
  104. package/front_end/third_party/lighthouse/locales/de.json +0 -3
  105. package/front_end/third_party/lighthouse/locales/el.json +0 -3
  106. package/front_end/third_party/lighthouse/locales/en-GB.json +19 -22
  107. package/front_end/third_party/lighthouse/locales/en-US.json +33 -3
  108. package/front_end/third_party/lighthouse/locales/en-XA.json +0 -3
  109. package/front_end/third_party/lighthouse/locales/en-XL.json +33 -3
  110. package/front_end/third_party/lighthouse/locales/es-419.json +17 -20
  111. package/front_end/third_party/lighthouse/locales/es.json +0 -3
  112. package/front_end/third_party/lighthouse/locales/fi.json +16 -19
  113. package/front_end/third_party/lighthouse/locales/fil.json +33 -36
  114. package/front_end/third_party/lighthouse/locales/fr.json +16 -19
  115. package/front_end/third_party/lighthouse/locales/he.json +16 -19
  116. package/front_end/third_party/lighthouse/locales/hi.json +0 -3
  117. package/front_end/third_party/lighthouse/locales/hr.json +16 -19
  118. package/front_end/third_party/lighthouse/locales/hu.json +16 -19
  119. package/front_end/third_party/lighthouse/locales/id.json +16 -19
  120. package/front_end/third_party/lighthouse/locales/it.json +37 -40
  121. package/front_end/third_party/lighthouse/locales/ja.json +16 -19
  122. package/front_end/third_party/lighthouse/locales/ko.json +16 -19
  123. package/front_end/third_party/lighthouse/locales/lt.json +17 -20
  124. package/front_end/third_party/lighthouse/locales/lv.json +0 -3
  125. package/front_end/third_party/lighthouse/locales/nl.json +16 -19
  126. package/front_end/third_party/lighthouse/locales/no.json +17 -20
  127. package/front_end/third_party/lighthouse/locales/pl.json +16 -19
  128. package/front_end/third_party/lighthouse/locales/pt-PT.json +37 -40
  129. package/front_end/third_party/lighthouse/locales/pt.json +16 -19
  130. package/front_end/third_party/lighthouse/locales/ro.json +0 -3
  131. package/front_end/third_party/lighthouse/locales/ru.json +16 -19
  132. package/front_end/third_party/lighthouse/locales/sk.json +0 -3
  133. package/front_end/third_party/lighthouse/locales/sl.json +0 -3
  134. package/front_end/third_party/lighthouse/locales/sr-Latn.json +16 -19
  135. package/front_end/third_party/lighthouse/locales/sr.json +16 -19
  136. package/front_end/third_party/lighthouse/locales/sv.json +17 -20
  137. package/front_end/third_party/lighthouse/locales/ta.json +0 -3
  138. package/front_end/third_party/lighthouse/locales/te.json +0 -3
  139. package/front_end/third_party/lighthouse/locales/th.json +0 -3
  140. package/front_end/third_party/lighthouse/locales/tr.json +0 -3
  141. package/front_end/third_party/lighthouse/locales/uk.json +17 -20
  142. package/front_end/third_party/lighthouse/locales/vi.json +0 -3
  143. package/front_end/third_party/lighthouse/locales/zh-HK.json +0 -3
  144. package/front_end/third_party/lighthouse/locales/zh-TW.json +0 -3
  145. package/front_end/third_party/lighthouse/locales/zh.json +0 -3
  146. package/front_end/third_party/lighthouse/report/bundle.d.ts +63 -61
  147. package/front_end/third_party/lighthouse/report/bundle.js +36 -7
  148. package/front_end/third_party/lighthouse/report-assets/report-generator.js +205 -192
  149. package/front_end/ui/components/linear_memory_inspector/LinearMemoryValueInterpreter.ts +0 -8
  150. package/front_end/ui/components/text_editor/config.ts +8 -7
  151. package/front_end/ui/components/text_editor/javascript.ts +28 -10
  152. package/front_end/ui/components/text_editor/theme.ts +1 -0
  153. package/front_end/ui/legacy/InspectorView.ts +10 -0
  154. package/front_end/ui/legacy/components/object_ui/ObjectPropertiesSection.ts +2 -3
  155. package/front_end/ui/legacy/components/object_ui/objectPropertiesSection.css +0 -1
  156. package/front_end/ui/legacy/components/object_ui/object_ui-legacy.ts +0 -8
  157. package/front_end/ui/legacy/components/object_ui/object_ui.ts +0 -4
  158. package/front_end/ui/legacy/components/source_frame/SourceFrame.ts +40 -29
  159. package/front_end/ui/legacy/inspectorSyntaxHighlight.css +0 -211
  160. package/front_end/ui/legacy/legacy-legacy.ts +0 -6
  161. package/front_end/ui/legacy/legacy.ts +0 -2
  162. package/front_end/ui/legacy/tabbedPane.css +1 -1
  163. package/front_end/ui/legacy/themeColors.css +1 -1
  164. package/package.json +1 -1
  165. package/scripts/check_gn.js +1 -1
  166. package/scripts/eslint_rules/lib/l10n_filename_matches.js +4 -4
  167. package/scripts/eslint_rules/tests/l10n_filename_matches_test.js +4 -0
  168. package/scripts/hosted_mode/server.js +17 -2
  169. package/front_end/entrypoints/inspector/inspector.json +0 -4
  170. package/front_end/entrypoints/node_app/node_app-meta.ts +0 -43
  171. package/front_end/entrypoints/node_app/node_app.js +0 -13
  172. package/front_end/entrypoints/node_app/node_app.json +0 -4
  173. package/front_end/entrypoints/node_main/node_main-meta.ts +0 -48
  174. package/front_end/entrypoints/node_main/node_main.ts +0 -11
  175. package/front_end/entrypoints/shell/shell-meta-files.ts +0 -22
  176. package/front_end/entrypoints/shell/shell.json +0 -5
  177. package/front_end/entrypoints/worker_app/worker_app.json +0 -4
  178. package/front_end/panels/lighthouse/module.json +0 -6
  179. package/front_end/third_party/lighthouse/report-assets/report.d.ts +0 -1
  180. package/front_end/third_party/lighthouse/report-assets/report.js +0 -233
  181. package/front_end/third_party/lighthouse/report-assets/standalone-template.html +0 -38
  182. package/front_end/ui/legacy/TextEditor.ts +0 -82
  183. package/front_end/ui/legacy/components/object_ui/JavaScriptAutocomplete.ts +0 -836
  184. package/front_end/ui/legacy/components/text_editor/CodeMirrorTextEditor.ts +0 -1676
  185. package/front_end/ui/legacy/components/text_editor/TextEditorAutocompleteController.ts +0 -586
  186. package/front_end/ui/legacy/components/text_editor/autocompleteTooltip.css +0 -20
  187. package/front_end/ui/legacy/components/text_editor/cm_modes.ts +0 -23
  188. package/front_end/ui/legacy/components/text_editor/cmdevtools.css +0 -995
  189. package/front_end/ui/legacy/components/text_editor/module.json +0 -7
  190. package/front_end/ui/legacy/components/text_editor/text_editor-legacy.ts +0 -33
  191. package/front_end/ui/legacy/components/text_editor/text_editor.ts +0 -13
@@ -1,586 +0,0 @@
1
- // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2
- // Use of this source code is governed by a BSD-style license that can be
3
- // found in the LICENSE file.
4
-
5
- /* eslint-disable @typescript-eslint/no-explicit-any */
6
-
7
- import * as Common from '../../../../core/common/common.js';
8
- import * as Platform from '../../../../core/platform/platform.js';
9
- import * as TextUtils from '../../../../models/text_utils/text_utils.js';
10
- import * as UI from '../../legacy.js';
11
-
12
- import type {CodeMirrorTextEditor} from './CodeMirrorTextEditor.js';
13
-
14
- export class TextEditorAutocompleteController implements UI.SuggestBox.SuggestBoxDelegate {
15
- private textEditor: CodeMirrorTextEditor;
16
- private codeMirror: any;
17
- private config: UI.TextEditor.AutocompleteConfig;
18
- private initialized: boolean;
19
- private readonly mouseDown: () => void;
20
- private lastHintText: string;
21
- private suggestBox: UI.SuggestBox.SuggestBox|null;
22
- private currentSuggestion: UI.SuggestBox.Suggestion|null;
23
- private hintElement: HTMLSpanElement;
24
- private readonly tooltipGlassPane: UI.GlassPane.GlassPane;
25
- private readonly tooltipElement: HTMLDivElement;
26
- private queryRange: TextUtils.TextRange.TextRange|null;
27
- private dictionary?: Common.TextDictionary.TextDictionary;
28
- private updatedLines?: any;
29
- private hintMarker?: any|null;
30
- private anchorBox?: AnchorBox|null;
31
-
32
- // https://crbug.com/1151919 * = CodeMirror.Editor
33
- constructor(textEditor: CodeMirrorTextEditor, codeMirror: any, config: UI.TextEditor.AutocompleteConfig) {
34
- this.textEditor = textEditor;
35
- this.codeMirror = codeMirror;
36
- this.config = config;
37
- this.initialized = false;
38
-
39
- this.onScroll = this.onScroll.bind(this);
40
- this.onCursorActivity = this.onCursorActivity.bind(this);
41
- this.changes = this.changes.bind(this);
42
- this.blur = this.blur.bind(this);
43
- this.beforeChange = this.beforeChange.bind(this);
44
- this.mouseDown = (): void => {
45
- this.clearAutocomplete();
46
- this.tooltipGlassPane.hide();
47
- };
48
- // @ts-ignore CodeMirror types are wrong.
49
- this.codeMirror.on('changes', this.changes);
50
- this.lastHintText = '';
51
- this.suggestBox = null;
52
- this.currentSuggestion = null;
53
- this.hintElement = document.createElement('span');
54
- this.hintElement.classList.add('auto-complete-text');
55
-
56
- this.tooltipGlassPane = new UI.GlassPane.GlassPane();
57
- this.tooltipGlassPane.setSizeBehavior(UI.GlassPane.SizeBehavior.MeasureContent);
58
- this.tooltipGlassPane.setOutsideClickCallback(this.tooltipGlassPane.hide.bind(this.tooltipGlassPane));
59
- this.tooltipElement = document.createElement('div');
60
- this.tooltipElement.classList.add('autocomplete-tooltip');
61
- const shadowRoot = UI.Utils.createShadowRootWithCoreStyles(this.tooltipGlassPane.contentElement, {
62
- cssFile: 'ui/legacy/components/text_editor/autocompleteTooltip.css',
63
- delegatesFocus: undefined,
64
- });
65
- shadowRoot.appendChild(this.tooltipElement);
66
-
67
- this.queryRange = null;
68
- }
69
-
70
- private initializeIfNeeded(): void {
71
- if (this.initialized) {
72
- return;
73
- }
74
- this.initialized = true;
75
- // @ts-ignore CodeMirror types are wrong.
76
- this.codeMirror.on('scroll', this.onScroll);
77
- // @ts-ignore CodeMirror types are wrong.
78
- this.codeMirror.on('cursorActivity', this.onCursorActivity);
79
- // @ts-ignore CodeMirror types are wrong.
80
- this.codeMirror.on('mousedown', this.mouseDown);
81
- // @ts-ignore CodeMirror types are wrong.
82
- this.codeMirror.on('blur', this.blur);
83
- if (this.config.isWordChar) {
84
- // @ts-ignore CodeMirror types are wrong.
85
- this.codeMirror.on('beforeChange', this.beforeChange);
86
- this.dictionary = new Common.TextDictionary.TextDictionary();
87
- // @ts-ignore CodeMirror types are wrong.
88
- this.addWordsFromText(this.codeMirror.getValue());
89
- }
90
- UI.ARIAUtils.setAutocomplete(this.textEditor.element, UI.ARIAUtils.AutocompleteInteractionModel.both);
91
- UI.ARIAUtils.setHasPopup(this.textEditor.element, UI.ARIAUtils.PopupRole.ListBox);
92
- }
93
-
94
- dispose(): void {
95
- // @ts-ignore CodeMirror types are wrong.
96
- this.codeMirror.off('changes', this.changes);
97
- if (this.initialized) {
98
- // @ts-ignore CodeMirror types are wrong.
99
- this.codeMirror.off('scroll', this.onScroll);
100
- // @ts-ignore CodeMirror types are wrong.
101
- this.codeMirror.off('cursorActivity', this.onCursorActivity);
102
- // @ts-ignore CodeMirror types are wrong.
103
- this.codeMirror.off('mousedown', this.mouseDown);
104
- // @ts-ignore CodeMirror types are wrong.
105
- this.codeMirror.off('blur', this.blur);
106
- }
107
- if (this.dictionary) {
108
- // @ts-ignore CodeMirror types are wrong.
109
- this.codeMirror.off('beforeChange', this.beforeChange);
110
- this.dictionary.reset();
111
- }
112
- UI.ARIAUtils.clearAutocomplete(this.textEditor.element);
113
- UI.ARIAUtils.setHasPopup(this.textEditor.element, UI.ARIAUtils.PopupRole.False);
114
- }
115
-
116
- private beforeChange(codeMirror: typeof CodeMirror, changeObject: any): void {
117
- this.updatedLines = this.updatedLines || {};
118
- for (let i = changeObject.from.line; i <= changeObject.to.line; ++i) {
119
- if (this.updatedLines[i] === undefined) {
120
- // @ts-ignore CodeMirror types are wrong.
121
- this.updatedLines[i] = this.codeMirror.getLine(i);
122
- }
123
- }
124
- }
125
-
126
- private addWordsFromText(text: string): void {
127
- TextUtils.TextUtils.Utils.textToWords(
128
- text, this.config.isWordChar as (arg0: string) => boolean, addWord.bind(this));
129
-
130
- function addWord(this: TextEditorAutocompleteController, word: string): void {
131
- if (this.dictionary && word.length && (word[0] < '0' || word[0] > '9')) {
132
- this.dictionary.addWord(word);
133
- }
134
- }
135
- }
136
-
137
- private removeWordsFromText(text: string): void {
138
- TextUtils.TextUtils.Utils.textToWords(
139
- text, this.config.isWordChar as (arg0: string) => boolean,
140
- word => this.dictionary && this.dictionary.removeWord(word));
141
- }
142
-
143
- private substituteRange(lineNumber: number, columnNumber: number): TextUtils.TextRange.TextRange|null {
144
- let range: TextUtils.TextRange.TextRange|(TextUtils.TextRange.TextRange | null) =
145
- this.config.substituteRangeCallback ? this.config.substituteRangeCallback(lineNumber, columnNumber) : null;
146
- if (!range && this.config.isWordChar) {
147
- range = this.textEditor.wordRangeForCursorPosition(lineNumber, columnNumber, this.config.isWordChar);
148
- }
149
- return range;
150
- }
151
-
152
- private wordsWithQuery(
153
- queryRange: TextUtils.TextRange.TextRange, substituteRange: TextUtils.TextRange.TextRange,
154
- force?: boolean): Promise<UI.SuggestBox.Suggestions> {
155
- const external =
156
- this.config.suggestionsCallback ? this.config.suggestionsCallback(queryRange, substituteRange, force) : null;
157
- if (external) {
158
- return external;
159
- }
160
-
161
- if (!this.dictionary || (!force && queryRange.isEmpty())) {
162
- return Promise.resolve([]);
163
- }
164
-
165
- let completions = this.dictionary.wordsWithPrefix(this.textEditor.text(queryRange));
166
- const substituteWord = this.textEditor.text(substituteRange);
167
- if (this.dictionary.wordCount(substituteWord) === 1) {
168
- completions = completions.filter(word => word !== substituteWord);
169
- }
170
- const dictionary = this.dictionary;
171
- completions.sort((a, b) => dictionary.wordCount(b) - dictionary.wordCount(a) || a.length - b.length);
172
- return Promise.resolve(completions.map(item => ({
173
- text: item,
174
- title: undefined,
175
- subtitle: undefined,
176
- iconType: undefined,
177
- priority: undefined,
178
- isSecondary: undefined,
179
- subtitleRenderer: undefined,
180
- selectionRange: undefined,
181
- hideGhostText: undefined,
182
- iconElement: undefined,
183
- })));
184
- }
185
-
186
- private changes(codeMirror: typeof CodeMirror, changes: any[]): void {
187
- if (!changes.length) {
188
- return;
189
- }
190
-
191
- if (this.dictionary && this.updatedLines) {
192
- for (const lineNumber in this.updatedLines) {
193
- this.removeWordsFromText(this.updatedLines[lineNumber]);
194
- }
195
- delete this.updatedLines;
196
-
197
- const linesToUpdate: {
198
- [x: string]: string,
199
- } = {};
200
- for (let changeIndex = 0; changeIndex < changes.length; ++changeIndex) {
201
- const changeObject = changes[changeIndex];
202
- const editInfo = TextUtils.CodeMirrorUtils.changeObjectToEditOperation(changeObject);
203
- for (let i = editInfo.newRange.startLine; i <= editInfo.newRange.endLine; ++i) {
204
- // @ts-ignore CodeMirror types are wrong.
205
- linesToUpdate[String(i)] = this.codeMirror.getLine(i);
206
- }
207
- }
208
- for (const lineNumber in linesToUpdate) {
209
- this.addWordsFromText(linesToUpdate[lineNumber]);
210
- }
211
- }
212
-
213
- let singleCharInput = false;
214
- let singleCharDelete = false;
215
- // @ts-ignore CodeMirror types are wrong.
216
- const cursor = this.codeMirror.getCursor('head');
217
- for (let changeIndex = 0; changeIndex < changes.length; ++changeIndex) {
218
- const changeObject = changes[changeIndex];
219
- if (changeObject.origin === '+input' && changeObject.text.length === 1 && changeObject.text[0].length === 1 &&
220
- changeObject.to.line === cursor.line && changeObject.to.ch + 1 === cursor.ch) {
221
- singleCharInput = true;
222
- break;
223
- }
224
- if (changeObject.origin === '+delete' && changeObject.removed.length === 1 &&
225
- changeObject.removed[0].length === 1 && changeObject.to.line === cursor.line &&
226
- changeObject.to.ch - 1 === cursor.ch) {
227
- singleCharDelete = true;
228
- break;
229
- }
230
- }
231
- if (this.queryRange) {
232
- if (singleCharInput) {
233
- this.queryRange.endColumn++;
234
- } else if (singleCharDelete) {
235
- this.queryRange.endColumn--;
236
- }
237
- if (singleCharDelete || singleCharInput) {
238
- this.setHint(this.lastHintText);
239
- }
240
- }
241
-
242
- if (singleCharInput || singleCharDelete) {
243
- queueMicrotask(() => {
244
- this.autocomplete();
245
- });
246
- } else {
247
- this.clearAutocomplete();
248
- }
249
- }
250
-
251
- private blur(): void {
252
- this.clearAutocomplete();
253
- }
254
-
255
- private validateSelectionsContexts(mainSelection: TextUtils.TextRange.TextRange): boolean {
256
- // @ts-ignore CodeMirror types are wrong.
257
- const selections = this.codeMirror.listSelections();
258
- if (selections.length <= 1) {
259
- return true;
260
- }
261
- const mainSelectionContext = this.textEditor.text(mainSelection);
262
- for (let i = 0; i < selections.length; ++i) {
263
- const wordRange = this.substituteRange(selections[i].head.line, selections[i].head.ch);
264
- if (!wordRange) {
265
- return false;
266
- }
267
- const context = this.textEditor.text(wordRange);
268
- if (context !== mainSelectionContext) {
269
- return false;
270
- }
271
- }
272
- return true;
273
- }
274
-
275
- autocomplete(force?: boolean): void {
276
- this.initializeIfNeeded();
277
- // @ts-ignore CodeMirror types are wrong.
278
- if (this.codeMirror.somethingSelected()) {
279
- this.hideSuggestBox();
280
- return;
281
- }
282
-
283
- // @ts-ignore CodeMirror types are wrong.
284
- const cursor = this.codeMirror.getCursor('head');
285
- const substituteRange = this.substituteRange(cursor.line, cursor.ch);
286
- if (!substituteRange || !this.validateSelectionsContexts(substituteRange)) {
287
- this.hideSuggestBox();
288
- return;
289
- }
290
-
291
- const queryRange = substituteRange.clone();
292
- queryRange.endColumn = cursor.ch;
293
- const query = this.textEditor.text(queryRange);
294
- let hadSuggestBox = false;
295
- if (this.suggestBox) {
296
- hadSuggestBox = true;
297
- }
298
- this.wordsWithQuery(queryRange, substituteRange, force).then(wordsWithQuery => {
299
- return wordsAcquired(wordsWithQuery);
300
- });
301
-
302
- const wordsAcquired = (wordsWithQuery: UI.SuggestBox.Suggestions): void => {
303
- if (!wordsWithQuery.length || (wordsWithQuery.length === 1 && query === wordsWithQuery[0].text) ||
304
- (!this.suggestBox && hadSuggestBox)) {
305
- this.hideSuggestBox();
306
- this.onSuggestionsShownForTest([]);
307
- return;
308
- }
309
- if (!this.suggestBox) {
310
- this.suggestBox = new UI.SuggestBox.SuggestBox(this, 20);
311
- if (this.config.anchorBehavior) {
312
- this.suggestBox.setAnchorBehavior(this.config.anchorBehavior);
313
- }
314
- }
315
-
316
- const oldQueryRange = this.queryRange;
317
- this.queryRange = queryRange;
318
- if (!oldQueryRange || queryRange.startLine !== oldQueryRange.startLine ||
319
- queryRange.startColumn !== oldQueryRange.startColumn) {
320
- this.updateAnchorBox();
321
- }
322
- this.anchorBox &&
323
- this.suggestBox.updateSuggestions(this.anchorBox, wordsWithQuery, true, !this.isCursorAtEndOfLine(), query);
324
- if (this.suggestBox.visible()) {
325
- this.tooltipGlassPane.hide();
326
- }
327
- this.onSuggestionsShownForTest(wordsWithQuery);
328
- };
329
- }
330
-
331
- private setHint(hint: string): void {
332
- if (this.queryRange === null) {
333
- return;
334
- }
335
- const query = this.textEditor.text(this.queryRange);
336
- if (!hint || !this.isCursorAtEndOfLine() || !hint.startsWith(query)) {
337
- this.clearHint();
338
- return;
339
- }
340
- const suffix = hint.substring(query.length).split('\n')[0];
341
- this.hintElement.textContent = Platform.StringUtilities.trimEndWithMaxLength(suffix, 10000);
342
- // @ts-ignore CodeMirror types are wrong.
343
- const cursor = this.codeMirror.getCursor('to');
344
- if (this.hintMarker) {
345
- const position = this.hintMarker.position();
346
- if (!position || !position.equal(TextUtils.TextRange.TextRange.createFromLocation(cursor.line, cursor.ch))) {
347
- this.hintMarker.clear();
348
- this.hintMarker = null;
349
- }
350
- }
351
-
352
- if (!this.hintMarker) {
353
- this.hintMarker = this.textEditor.addBookmark(
354
- cursor.line, cursor.ch, this.hintElement as HTMLElement, TextEditorAutocompleteController.HintBookmark, true);
355
- } else if (this.lastHintText !== hint) {
356
- this.hintMarker.refresh();
357
- }
358
- this.lastHintText = hint;
359
- }
360
-
361
- private clearHint(): void {
362
- if (!this.hintElement.textContent) {
363
- return;
364
- }
365
- this.lastHintText = '';
366
- this.hintElement.textContent = '';
367
- if (this.hintMarker) {
368
- this.hintMarker.refresh();
369
- }
370
- }
371
-
372
- private onSuggestionsShownForTest(_suggestions: UI.SuggestBox.Suggestions): void {
373
- }
374
-
375
- private onSuggestionsHiddenForTest(): void {
376
- }
377
-
378
- clearAutocomplete(): void {
379
- this.tooltipGlassPane.hide();
380
- this.hideSuggestBox();
381
- }
382
-
383
- private hideSuggestBox(): void {
384
- if (!this.suggestBox) {
385
- return;
386
- }
387
- this.suggestBox.hide();
388
- this.suggestBox = null;
389
- this.queryRange = null;
390
- this.anchorBox = null;
391
- this.currentSuggestion = null;
392
- this.textEditor.dispatchEventToListeners(UI.TextEditor.Events.SuggestionChanged);
393
- this.clearHint();
394
- this.onSuggestionsHiddenForTest();
395
- }
396
-
397
- keyDown(event: KeyboardEvent): boolean {
398
- if (this.tooltipGlassPane.isShowing() && event.keyCode === UI.KeyboardShortcut.Keys.Esc.code) {
399
- this.tooltipGlassPane.hide();
400
- return true;
401
- }
402
- if (!this.suggestBox) {
403
- return false;
404
- }
405
- switch (event.keyCode) {
406
- case UI.KeyboardShortcut.Keys.Tab.code:
407
- this.suggestBox.acceptSuggestion();
408
- this.clearAutocomplete();
409
- return true;
410
- case UI.KeyboardShortcut.Keys.End.code:
411
- case UI.KeyboardShortcut.Keys.Right.code:
412
- if (this.isCursorAtEndOfLine()) {
413
- this.suggestBox.acceptSuggestion();
414
- this.clearAutocomplete();
415
- return true;
416
- }
417
- this.clearAutocomplete();
418
- return false;
419
- case UI.KeyboardShortcut.Keys.Left.code:
420
- case UI.KeyboardShortcut.Keys.Home.code:
421
- this.clearAutocomplete();
422
- return false;
423
- case UI.KeyboardShortcut.Keys.Esc.code:
424
- this.clearAutocomplete();
425
- return true;
426
- }
427
- return this.suggestBox.keyPressed(event);
428
- }
429
-
430
- private isCursorAtEndOfLine(): boolean {
431
- // @ts-ignore CodeMirror types are wrong.
432
- const cursor = this.codeMirror.getCursor('to');
433
- // @ts-ignore CodeMirror types are wrong.
434
- return cursor.ch === this.codeMirror.getLine(cursor.line).length;
435
- }
436
-
437
- applySuggestion(suggestion: UI.SuggestBox.Suggestion|null, _isIntermediateSuggestion?: boolean): void {
438
- const oldSuggestion = this.currentSuggestion;
439
- this.currentSuggestion = suggestion;
440
- this.setHint(suggestion ? suggestion.text : '');
441
- if ((oldSuggestion ? oldSuggestion.text : '') !== (suggestion ? suggestion.text : '')) {
442
- this.textEditor.dispatchEventToListeners(UI.TextEditor.Events.SuggestionChanged);
443
- }
444
- }
445
-
446
- acceptSuggestion(): void {
447
- if (this.currentSuggestion === null || this.queryRange === null) {
448
- return;
449
- }
450
- // @ts-ignore CodeMirror types are wrong.
451
- const selections = this.codeMirror.listSelections().slice();
452
- const queryLength = this.queryRange.endColumn - this.queryRange.startColumn;
453
- const suggestion = this.currentSuggestion.text;
454
- // @ts-ignore CodeMirror types are wrong.
455
- this.codeMirror.operation(() => {
456
- for (let i = selections.length - 1; i >= 0; --i) {
457
- const start = selections[i].head;
458
- const end = new CodeMirror.Pos(start.line, start.ch - queryLength);
459
- // @ts-ignore CodeMirror types are wrong.
460
- this.codeMirror.replaceRange(suggestion, start, end, '+autocomplete');
461
- }
462
- });
463
- }
464
-
465
- ariaControlledBy(): Element {
466
- return this.textEditor.element;
467
- }
468
-
469
- textWithCurrentSuggestion(): string {
470
- if (!this.queryRange || this.currentSuggestion === null) {
471
- // @ts-ignore CodeMirror types are wrong.
472
- return this.codeMirror.getValue();
473
- }
474
-
475
- // @ts-ignore CodeMirror types are wrong.
476
- const selections = this.codeMirror.listSelections().slice();
477
- let last: {
478
- line: any,
479
- column: any,
480
- }|{
481
- line: number,
482
- column: number,
483
- } = {line: 0, column: 0};
484
- let text = '';
485
- const queryLength = this.queryRange.endColumn - this.queryRange.startColumn;
486
- for (const selection of selections) {
487
- const range = new TextUtils.TextRange.TextRange(
488
- last.line, last.column, selection.head.line, selection.head.ch - queryLength);
489
- text += this.textEditor.text(range);
490
- text += this.currentSuggestion.text;
491
- last = {line: selection.head.line, column: selection.head.ch};
492
- }
493
- const range = new TextUtils.TextRange.TextRange(last.line, last.column, Infinity, Infinity);
494
- text += this.textEditor.text(range);
495
- return text;
496
- }
497
-
498
- private onScroll(): void {
499
- this.tooltipGlassPane.hide();
500
- if (!this.suggestBox) {
501
- return;
502
- }
503
- // @ts-ignore CodeMirror types are wrong.
504
- const cursor = this.codeMirror.getCursor();
505
- // @ts-ignore CodeMirror types are wrong.
506
- const scrollInfo = this.codeMirror.getScrollInfo();
507
- // @ts-ignore CodeMirror types are wrong.
508
- const topmostLineNumber = this.codeMirror.lineAtHeight(scrollInfo.top, 'local');
509
- // @ts-ignore CodeMirror types are wrong.
510
- const bottomLine = this.codeMirror.lineAtHeight(scrollInfo.top + scrollInfo.clientHeight, 'local');
511
- if (cursor.line < topmostLineNumber || cursor.line > bottomLine) {
512
- this.clearAutocomplete();
513
- } else {
514
- this.updateAnchorBox();
515
- this.anchorBox && this.suggestBox.setPosition(this.anchorBox);
516
- }
517
- }
518
-
519
- private async updateTooltip(): Promise<void> {
520
- // @ts-ignore CodeMirror types are wrong.
521
- const cursor = this.codeMirror.getCursor();
522
- const tooltip = this.config.tooltipCallback ? await this.config.tooltipCallback(cursor.line, cursor.ch) : null;
523
- // @ts-ignore CodeMirror types are wrong.
524
- const newCursor = this.codeMirror.getCursor();
525
-
526
- if (newCursor.line !== cursor.line && newCursor.ch !== cursor.ch) {
527
- return;
528
- }
529
- if (this.suggestBox && this.suggestBox.visible) {
530
- return;
531
- }
532
-
533
- if (!tooltip) {
534
- this.tooltipGlassPane.hide();
535
- return;
536
- }
537
- const metrics = this.textEditor.cursorPositionToCoordinates(cursor.line, cursor.ch);
538
- if (!metrics) {
539
- this.tooltipGlassPane.hide();
540
- return;
541
- }
542
-
543
- this.tooltipGlassPane.setContentAnchorBox(new AnchorBox(metrics.x, metrics.y, 0, metrics.height));
544
- this.tooltipElement.removeChildren();
545
- this.tooltipElement.appendChild(tooltip);
546
- this.tooltipGlassPane.show(this.textEditor.element.ownerDocument as Document);
547
- }
548
-
549
- private onCursorActivity(): void {
550
- this.updateTooltip();
551
- if (!this.suggestBox || this.queryRange === null) {
552
- return;
553
- }
554
- // @ts-ignore CodeMirror types are wrong.
555
- const cursor = this.codeMirror.getCursor();
556
- let shouldCloseAutocomplete: boolean =
557
- !(cursor.line === this.queryRange.startLine && this.queryRange.startColumn <= cursor.ch &&
558
- cursor.ch <= this.queryRange.endColumn);
559
- // Try not to hide autocomplete when user types in.
560
- if (cursor.line === this.queryRange.startLine && cursor.ch === this.queryRange.endColumn + 1) {
561
- // @ts-ignore CodeMirror types are wrong.
562
- const line = this.codeMirror.getLine(cursor.line);
563
- shouldCloseAutocomplete = this.config.isWordChar ? !this.config.isWordChar(line.charAt(cursor.ch - 1)) : false;
564
- }
565
- if (shouldCloseAutocomplete) {
566
- this.clearAutocomplete();
567
- }
568
- this.onCursorActivityHandledForTest();
569
- }
570
-
571
- private onCursorActivityHandledForTest(): void {
572
- }
573
-
574
- private updateAnchorBox(): void {
575
- if (this.queryRange === null) {
576
- return;
577
- }
578
- const line = this.queryRange.startLine;
579
- const column = this.queryRange.startColumn;
580
- const metrics = this.textEditor.cursorPositionToCoordinates(line, column);
581
- this.anchorBox = metrics ? new AnchorBox(metrics.x, metrics.y, 0, metrics.height) : null;
582
- }
583
-
584
- // eslint-disable-next-line @typescript-eslint/naming-convention
585
- static readonly HintBookmark = Symbol('hint');
586
- }
@@ -1,20 +0,0 @@
1
- /*
2
- * Copyright (c) 2018 The Chromium Authors. All rights reserved.
3
- * Use of this source code is governed by a BSD-style license that can be
4
- * found in the LICENSE file.
5
- */
6
-
7
- .autocomplete-tooltip {
8
- pointer-events: none;
9
- margin-left: -3px;
10
- }
11
-
12
- .autocomplete-tooltip > div > * {
13
- padding: 0 4px;
14
- white-space: nowrap;
15
- vertical-align: middle;
16
- line-height: 20px;
17
- box-shadow: var(--drop-shadow);
18
- background-color: var(--color-background);
19
- width: fit-content;
20
- }
@@ -1,23 +0,0 @@
1
- // Copyright 2019 The Chromium Authors. All rights reserved.
2
- // Use of this source code is governed by a BSD-style license that can be
3
- // found in the LICENSE file.
4
-
5
- import '../../../../third_party/codemirror/codemirror.js';
6
-
7
- // TODO(crbug.com/1029037): lazily load these files again after the
8
- // race-condition with CodeMirror is fixed
9
- import '../../../../third_party/codemirror/package/mode/clike/clike.js';
10
- import '../../../../third_party/codemirror/package/mode/coffeescript/coffeescript.js';
11
- import '../../../../third_party/codemirror/package/mode/php/php.js';
12
- import '../../../../third_party/codemirror/package/mode/python/python.js';
13
- import '../../../../third_party/codemirror/package/mode/shell/shell.js';
14
- import '../../../../third_party/codemirror/package/mode/livescript/livescript.js';
15
- import '../../../../third_party/codemirror/package/mode/markdown/markdown.js';
16
- import '../../../../third_party/codemirror/package/mode/clojure/clojure.js';
17
- import '../../../../third_party/codemirror/package/mode/jsx/jsx.js';
18
- import '../../../../third_party/codemirror/package/mode/css/css.js';
19
- import '../../../../third_party/codemirror/package/mode/javascript/javascript.js';
20
- import '../../../../third_party/codemirror/package/mode/xml/xml.js';
21
- import '../../../../third_party/codemirror/package/mode/htmlmixed/htmlmixed.js';
22
- import '../../../../third_party/codemirror/package/mode/htmlembedded/htmlembedded.js';
23
- import '../../../../third_party/codemirror/package/mode/wast/wast.js';