chrome-devtools-frontend 1.0.925655 → 1.0.927419
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.
- package/.stylelintignore +1 -0
- package/AUTHORS +1 -0
- package/config/gni/devtools_grd_files.gni +10 -3
- package/front_end/core/common/Color.ts +6 -0
- package/front_end/core/common/SettingRegistration.ts +8 -0
- package/front_end/core/host/InspectorFrontendHost.ts +3 -0
- package/front_end/core/host/InspectorFrontendHostAPI.ts +3 -0
- package/front_end/core/host/UserMetrics.ts +7 -3
- package/front_end/core/i18n/locales/en-US.json +71 -14
- package/front_end/core/i18n/locales/en-XL.json +71 -14
- package/front_end/core/platform/keyboard-utilities.ts +1 -0
- package/front_end/core/root/Runtime.ts +1 -0
- package/front_end/core/sdk/ConsoleModel.ts +3 -0
- package/front_end/core/sdk/DebuggerModel.ts +2 -0
- package/front_end/core/sdk/NetworkManager.ts +12 -2
- package/front_end/core/sdk/NetworkRequest.ts +20 -5
- package/front_end/core/sdk/OverlayModel.ts +21 -0
- package/front_end/core/sdk/OverlayPersistentHighlighter.ts +55 -3
- package/front_end/devtools_compatibility.js +11 -1
- package/front_end/entrypoints/main/MainImpl.ts +4 -2
- package/front_end/entrypoints/main/main-meta.ts +16 -0
- package/front_end/generated/InspectorBackendCommands.js +8 -7
- package/front_end/generated/SupportedCSSProperties.js +7 -1
- package/front_end/generated/protocol-mapping.d.ts +5 -24
- package/front_end/generated/protocol-proxy-api.d.ts +6 -29
- package/front_end/generated/protocol.d.ts +51 -46
- package/front_end/models/bindings/DebuggerWorkspaceBinding.ts +0 -6
- package/front_end/models/issues_manager/CorsIssue.ts +4 -0
- package/front_end/models/logs/LogManager.ts +1 -0
- package/front_end/models/persistence/WorkspaceSettingsTab.ts +6 -4
- package/front_end/models/persistence/workspaceSettingsTab.css +18 -18
- package/front_end/models/timeline_model/TimelineFrameModel.ts +107 -28
- package/front_end/panels/application/ReportingApiReportsView.ts +89 -0
- package/front_end/panels/application/ReportingApiTreeElement.ts +3 -3
- package/front_end/panels/application/ReportingApiView.ts +27 -0
- package/front_end/panels/application/application.ts +2 -0
- package/front_end/panels/application/components/EndpointsGrid.ts +55 -0
- package/front_end/panels/application/components/ReportsGrid.ts +144 -0
- package/front_end/panels/application/components/components.ts +4 -2
- package/front_end/panels/application/components/reportingApiGrid.css +35 -0
- package/front_end/panels/application/reportingApiReportsView.css +13 -0
- package/front_end/panels/console/ConsoleView.ts +17 -0
- package/front_end/panels/console/console-meta.ts +26 -0
- package/front_end/panels/elements/ElementsTreeElement.ts +19 -0
- package/front_end/panels/elements/PropertiesWidget.ts +1 -2
- package/front_end/panels/elements/StylePropertyTreeElement.ts +28 -0
- package/front_end/panels/elements/StylePropertyUtils.ts +13 -0
- package/front_end/panels/elements/components/nodeText.css +4 -4
- package/front_end/panels/elements/elements.ts +2 -0
- package/front_end/panels/elements/layoutPane.css +1 -1
- package/front_end/panels/issues/CorsIssueDetailsView.ts +4 -2
- package/front_end/panels/network/RequestCookiesView.ts +13 -4
- package/front_end/panels/screencast/screencastView.css +2 -6
- package/front_end/panels/search/SearchResultsPane.ts +1 -1
- package/front_end/panels/settings/SettingsScreen.ts +3 -0
- package/front_end/panels/snippets/SnippetsQuickOpen.ts +8 -3
- package/front_end/panels/sources/CallStackSidebarPane.ts +1 -10
- package/front_end/panels/sources/GoToLineQuickOpen.ts +50 -10
- package/front_end/panels/sources/UISourceCodeFrame.ts +0 -13
- package/front_end/panels/sources/sources-legacy.ts +0 -11
- package/front_end/panels/sources/sources-meta.ts +22 -20
- package/front_end/panels/sources/sources.ts +0 -2
- package/front_end/third_party/codemirror.next/LICENSE +21 -0
- package/front_end/third_party/codemirror.next/README.chromium +18 -0
- package/front_end/third_party/codemirror.next/bundle-tsconfig.json +21 -0
- package/front_end/third_party/codemirror.next/bundle.ts +87 -0
- package/front_end/third_party/codemirror.next/chunk/codemirror.js +1 -0
- package/front_end/third_party/codemirror.next/chunk/cpp.js +2 -0
- package/front_end/third_party/codemirror.next/chunk/css.js +2 -0
- package/front_end/third_party/codemirror.next/chunk/html.js +4 -0
- package/front_end/third_party/codemirror.next/chunk/java.js +2 -0
- package/front_end/third_party/codemirror.next/chunk/javascript.js +2 -0
- package/front_end/third_party/codemirror.next/chunk/json.js +2 -0
- package/front_end/third_party/codemirror.next/chunk/legacy.js +1 -0
- package/front_end/third_party/codemirror.next/chunk/markdown.js +6 -0
- package/front_end/third_party/codemirror.next/chunk/php.js +6 -0
- package/front_end/third_party/codemirror.next/chunk/python.js +2 -0
- package/front_end/third_party/codemirror.next/chunk/wast.js +2 -0
- package/front_end/third_party/codemirror.next/chunk/xml.js +2 -0
- package/front_end/third_party/codemirror.next/codemirror.next.d.ts +5467 -0
- package/front_end/third_party/codemirror.next/codemirror.next.js +2 -0
- package/front_end/third_party/codemirror.next/package.json +39 -0
- package/front_end/third_party/codemirror.next/rebuild.sh +6 -0
- package/front_end/third_party/codemirror.next/rollup.config.js +45 -0
- package/front_end/ui/components/buttons/Button.ts +33 -5
- package/front_end/ui/components/buttons/button.css +32 -2
- package/front_end/ui/components/code_highlighter/CodeHighlighter.ts +137 -0
- package/front_end/ui/components/code_highlighter/codeHighlighter.css +51 -0
- package/front_end/ui/components/code_highlighter/code_highlighter.ts +11 -0
- package/front_end/ui/components/docs/button/basic.html +1 -0
- package/front_end/ui/components/docs/button/basic.ts +47 -4
- package/front_end/ui/components/docs/text_editor/basic.html +28 -0
- package/front_end/ui/components/docs/text_editor/basic.ts +14 -0
- package/front_end/ui/components/docs/text_prompt/basic.html +35 -0
- package/front_end/ui/components/docs/text_prompt/basic.ts +19 -0
- package/front_end/ui/components/render_coordinator/RenderCoordinator.ts +17 -0
- package/front_end/ui/components/text_editor/TextEditor.ts +161 -0
- package/front_end/ui/components/text_editor/config.ts +264 -0
- package/front_end/ui/components/text_editor/text_editor.ts +6 -0
- package/front_end/ui/components/text_editor/theme.ts +113 -0
- package/front_end/ui/components/text_prompt/TextPrompt.ts +144 -0
- package/front_end/ui/components/text_prompt/textPrompt.css +33 -0
- package/front_end/ui/components/text_prompt/text_prompt.ts +9 -0
- package/front_end/ui/legacy/UIUtils.ts +9 -1
- package/front_end/ui/legacy/components/quick_open/CommandMenu.ts +8 -3
- package/front_end/ui/legacy/components/quick_open/FilteredListWidget.ts +39 -39
- package/front_end/ui/legacy/components/quick_open/HelpQuickOpen.ts +10 -4
- package/front_end/ui/legacy/components/quick_open/QuickOpen.ts +31 -14
- package/front_end/ui/legacy/components/quick_open/filteredListWidget.css +7 -8
- package/front_end/ui/legacy/components/source_frame/source_frame-legacy.ts +0 -6
- package/front_end/ui/legacy/components/source_frame/source_frame.ts +0 -2
- package/front_end/ui/legacy/components/utils/JSPresentationUtils.ts +11 -9
- package/front_end/ui/legacy/filter.css +1 -0
- package/front_end/ui/legacy/inspectorSyntaxHighlight.css +3 -8
- package/front_end/ui/legacy/inspectorSyntaxHighlightDark.css +11 -16
- package/front_end/ui/legacy/themeColors.css +60 -0
- package/inspector_overlay/debug/tool_persistent_isolated_element.html +75 -0
- package/inspector_overlay/drag_resize_handler.ts +142 -0
- package/inspector_overlay/highlight_isolated_element.ts +62 -0
- package/inspector_overlay/main.ts +4 -1
- package/inspector_overlay/tool_highlight.ts +6 -0
- package/inspector_overlay/tool_paused.ts +2 -0
- package/inspector_overlay/tool_persistent.ts +110 -0
- package/inspector_overlay/tool_screenshot.ts +8 -1
- package/package.json +1 -1
- package/front_end/panels/application/components/ReportingApiView.ts +0 -24
- package/front_end/panels/sources/GutterDiffPlugin.ts +0 -282
- package/front_end/ui/legacy/components/source_frame/SourceCodeDiff.ts +0 -140
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
// Copyright 2018 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 * as Common from '../../core/common/common.js';
|
|
6
|
-
import * as i18n from '../../core/i18n/i18n.js';
|
|
7
|
-
import * as Persistence from '../../models/persistence/persistence.js';
|
|
8
|
-
import * as Workspace from '../../models/workspace/workspace.js';
|
|
9
|
-
import * as WorkspaceDiff from '../../models/workspace_diff/workspace_diff.js';
|
|
10
|
-
import type * as Diff from '../../third_party/diff/diff.js';
|
|
11
|
-
import * as SourceFrame from '../../ui/legacy/components/source_frame/source_frame.js';
|
|
12
|
-
import type * as TextEditor from '../../ui/legacy/components/text_editor/text_editor.js';
|
|
13
|
-
import type * as UI from '../../ui/legacy/legacy.js';
|
|
14
|
-
|
|
15
|
-
import {Plugin} from './Plugin.js';
|
|
16
|
-
|
|
17
|
-
const UIStrings = {
|
|
18
|
-
/**
|
|
19
|
-
*@description A context menu item in the Gutter Diff Plugin of the Sources panel
|
|
20
|
-
*/
|
|
21
|
-
localModifications: 'Local Modifications...',
|
|
22
|
-
};
|
|
23
|
-
const str_ = i18n.i18n.registerUIStrings('panels/sources/GutterDiffPlugin.ts', UIStrings);
|
|
24
|
-
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
|
|
25
|
-
export class GutterDiffPlugin extends Plugin {
|
|
26
|
-
private readonly textEditor: SourceFrame.SourcesTextEditor.SourcesTextEditor;
|
|
27
|
-
private readonly uiSourceCode: Workspace.UISourceCode.UISourceCode;
|
|
28
|
-
private decorations: GutterDecoration[];
|
|
29
|
-
private readonly workspaceDiff: WorkspaceDiff.WorkspaceDiff.WorkspaceDiffImpl;
|
|
30
|
-
|
|
31
|
-
constructor(
|
|
32
|
-
textEditor: SourceFrame.SourcesTextEditor.SourcesTextEditor, uiSourceCode: Workspace.UISourceCode.UISourceCode) {
|
|
33
|
-
super();
|
|
34
|
-
this.textEditor = textEditor;
|
|
35
|
-
this.uiSourceCode = uiSourceCode;
|
|
36
|
-
|
|
37
|
-
this.decorations = [];
|
|
38
|
-
this.textEditor.installGutter(DiffGutterType, true);
|
|
39
|
-
this.workspaceDiff = WorkspaceDiff.WorkspaceDiff.workspaceDiff();
|
|
40
|
-
this.workspaceDiff.subscribeToDiffChange(this.uiSourceCode, this.update, this);
|
|
41
|
-
this.update();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
static accepts(uiSourceCode: Workspace.UISourceCode.UISourceCode): boolean {
|
|
45
|
-
return uiSourceCode.project().type() === Workspace.Workspace.projectTypes.Network;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private updateDecorations(removed: GutterDecoration[], added: GutterDecoration[]): void {
|
|
49
|
-
this.textEditor.operation(operation);
|
|
50
|
-
|
|
51
|
-
function operation(): void {
|
|
52
|
-
for (const decoration of removed) {
|
|
53
|
-
decoration.remove();
|
|
54
|
-
}
|
|
55
|
-
for (const decoration of added) {
|
|
56
|
-
decoration.install();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private update(): void {
|
|
62
|
-
if (this.uiSourceCode) {
|
|
63
|
-
this.workspaceDiff.requestDiff(this.uiSourceCode).then(this.innerUpdate.bind(this));
|
|
64
|
-
} else {
|
|
65
|
-
this.innerUpdate(null);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private innerUpdate(lineDiff: Diff.Diff.DiffArray|null): void {
|
|
70
|
-
if (!lineDiff) {
|
|
71
|
-
this.updateDecorations(this.decorations, []);
|
|
72
|
-
this.decorations = [];
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const diff = SourceFrame.SourceCodeDiff.SourceCodeDiff.computeDiff(lineDiff);
|
|
77
|
-
|
|
78
|
-
const newDecorations = new Map<number, {
|
|
79
|
-
lineNumber: number,
|
|
80
|
-
type: SourceFrame.SourceCodeDiff.EditType,
|
|
81
|
-
}>();
|
|
82
|
-
for (let i = 0; i < diff.length; ++i) {
|
|
83
|
-
const diffEntry = diff[i];
|
|
84
|
-
for (let lineNumber = diffEntry.from; lineNumber < diffEntry.to; ++lineNumber) {
|
|
85
|
-
newDecorations.set(lineNumber, {lineNumber: lineNumber, type: diffEntry.type});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const decorationDiff = this.calculateDecorationsDiff(newDecorations);
|
|
90
|
-
const addedDecorations =
|
|
91
|
-
decorationDiff.added.map(entry => new GutterDecoration(this.textEditor, entry.lineNumber, entry.type));
|
|
92
|
-
|
|
93
|
-
this.decorations = decorationDiff.equal.concat(addedDecorations);
|
|
94
|
-
this.updateDecorations(decorationDiff.removed, addedDecorations);
|
|
95
|
-
this.decorationsSetForTest(newDecorations);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
private decorationsByLine(): Map<number, GutterDecoration> {
|
|
99
|
-
const decorations = new Map<number, GutterDecoration>();
|
|
100
|
-
for (const decoration of this.decorations) {
|
|
101
|
-
const lineNumber = decoration.lineNumber();
|
|
102
|
-
if (lineNumber !== -1) {
|
|
103
|
-
decorations.set(lineNumber, decoration);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return decorations;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
private calculateDecorationsDiff(decorations: Map<number, {
|
|
110
|
-
lineNumber: number,
|
|
111
|
-
type: SourceFrame.SourceCodeDiff.EditType,
|
|
112
|
-
}>): {
|
|
113
|
-
added: {
|
|
114
|
-
lineNumber: number,
|
|
115
|
-
type: SourceFrame.SourceCodeDiff.EditType,
|
|
116
|
-
}[],
|
|
117
|
-
removed: GutterDecoration[],
|
|
118
|
-
equal: GutterDecoration[],
|
|
119
|
-
} {
|
|
120
|
-
const oldDecorations = this.decorationsByLine();
|
|
121
|
-
const leftKeys = [...oldDecorations.keys()];
|
|
122
|
-
const rightKeys = [...decorations.keys()];
|
|
123
|
-
leftKeys.sort((a, b) => a - b);
|
|
124
|
-
rightKeys.sort((a, b) => a - b);
|
|
125
|
-
|
|
126
|
-
const removed = [];
|
|
127
|
-
const added = [];
|
|
128
|
-
const equal = [];
|
|
129
|
-
let leftIndex = 0;
|
|
130
|
-
let rightIndex = 0;
|
|
131
|
-
while (leftIndex < leftKeys.length && rightIndex < rightKeys.length) {
|
|
132
|
-
const leftKey = leftKeys[leftIndex];
|
|
133
|
-
const rightKey = rightKeys[rightIndex];
|
|
134
|
-
const left = oldDecorations.get(leftKey);
|
|
135
|
-
const right = decorations.get(rightKey);
|
|
136
|
-
if (!left) {
|
|
137
|
-
throw new Error(`No decoration with key ${leftKey}`);
|
|
138
|
-
}
|
|
139
|
-
if (!right) {
|
|
140
|
-
throw new Error(`No decoration with key ${rightKey}`);
|
|
141
|
-
}
|
|
142
|
-
if (leftKey === rightKey && left.type === right.type) {
|
|
143
|
-
equal.push(left);
|
|
144
|
-
++leftIndex;
|
|
145
|
-
++rightIndex;
|
|
146
|
-
} else if (leftKey <= rightKey) {
|
|
147
|
-
removed.push(left);
|
|
148
|
-
++leftIndex;
|
|
149
|
-
} else {
|
|
150
|
-
added.push(right);
|
|
151
|
-
++rightIndex;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
while (leftIndex < leftKeys.length) {
|
|
155
|
-
const leftKey = leftKeys[leftIndex++];
|
|
156
|
-
const left = oldDecorations.get(leftKey);
|
|
157
|
-
if (!left) {
|
|
158
|
-
throw new Error(`No decoration with key ${leftKey}`);
|
|
159
|
-
}
|
|
160
|
-
removed.push(left);
|
|
161
|
-
}
|
|
162
|
-
while (rightIndex < rightKeys.length) {
|
|
163
|
-
const rightKey = rightKeys[rightIndex++];
|
|
164
|
-
const right = decorations.get(rightKey);
|
|
165
|
-
if (!right) {
|
|
166
|
-
throw new Error(`No decoration with key ${rightKey}`);
|
|
167
|
-
}
|
|
168
|
-
added.push(right);
|
|
169
|
-
}
|
|
170
|
-
return {added: added, removed: removed, equal: equal};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
private decorationsSetForTest(_decorations: Map<number, {
|
|
174
|
-
lineNumber: number,
|
|
175
|
-
type: SourceFrame.SourceCodeDiff.EditType,
|
|
176
|
-
}>): void {
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
async populateLineGutterContextMenu(contextMenu: UI.ContextMenu.ContextMenu, _lineNumber: number): Promise<void> {
|
|
180
|
-
GutterDiffPlugin.appendRevealDiffContextMenu(contextMenu, this.uiSourceCode);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
async populateTextAreaContextMenu(
|
|
184
|
-
contextMenu: UI.ContextMenu.ContextMenu, _lineNumber: number, _columnNumber: number): Promise<void> {
|
|
185
|
-
GutterDiffPlugin.appendRevealDiffContextMenu(contextMenu, this.uiSourceCode);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
static appendRevealDiffContextMenu(
|
|
189
|
-
contextMenu: UI.ContextMenu.ContextMenu, uiSourceCode: Workspace.UISourceCode.UISourceCode): void {
|
|
190
|
-
if (!WorkspaceDiff.WorkspaceDiff.workspaceDiff().isUISourceCodeModified(uiSourceCode)) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
contextMenu.revealSection().appendItem(i18nString(UIStrings.localModifications), () => {
|
|
194
|
-
Common.Revealer.reveal(new WorkspaceDiff.WorkspaceDiff.DiffUILocation(uiSourceCode));
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
dispose(): void {
|
|
199
|
-
for (const decoration of this.decorations) {
|
|
200
|
-
decoration.remove();
|
|
201
|
-
}
|
|
202
|
-
WorkspaceDiff.WorkspaceDiff.workspaceDiff().unsubscribeFromDiffChange(this.uiSourceCode, this.update, this);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export class GutterDecoration {
|
|
207
|
-
private readonly textEditor: SourceFrame.SourcesTextEditor.SourcesTextEditor;
|
|
208
|
-
private readonly position: TextEditor.CodeMirrorTextEditor.TextEditorPositionHandle;
|
|
209
|
-
private readonly className: string;
|
|
210
|
-
type: SourceFrame.SourceCodeDiff.EditType;
|
|
211
|
-
|
|
212
|
-
constructor(
|
|
213
|
-
textEditor: SourceFrame.SourcesTextEditor.SourcesTextEditor, lineNumber: number,
|
|
214
|
-
type: SourceFrame.SourceCodeDiff.EditType) {
|
|
215
|
-
this.textEditor = textEditor;
|
|
216
|
-
this.position = this.textEditor.textEditorPositionHandle(lineNumber, 0);
|
|
217
|
-
this.className = '';
|
|
218
|
-
if (type === SourceFrame.SourceCodeDiff.EditType.Insert) {
|
|
219
|
-
this.className = 'diff-entry-insert';
|
|
220
|
-
} else if (type === SourceFrame.SourceCodeDiff.EditType.Delete) {
|
|
221
|
-
this.className = 'diff-entry-delete';
|
|
222
|
-
} else if (type === SourceFrame.SourceCodeDiff.EditType.Modify) {
|
|
223
|
-
this.className = 'diff-entry-modify';
|
|
224
|
-
}
|
|
225
|
-
this.type = type;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
lineNumber(): number {
|
|
229
|
-
const location = this.position.resolve();
|
|
230
|
-
if (!location) {
|
|
231
|
-
return -1;
|
|
232
|
-
}
|
|
233
|
-
return location.lineNumber;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
install(): void {
|
|
237
|
-
const location = this.position.resolve();
|
|
238
|
-
if (!location) {
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
const element = document.createElement('div');
|
|
242
|
-
element.classList.add('diff-marker');
|
|
243
|
-
element.textContent = '\xA0';
|
|
244
|
-
this.textEditor.setGutterDecoration(location.lineNumber, DiffGutterType, element);
|
|
245
|
-
this.textEditor.toggleLineClass(location.lineNumber, this.className, true);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
remove(): void {
|
|
249
|
-
const location = this.position.resolve();
|
|
250
|
-
if (!location) {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
this.textEditor.setGutterDecoration(location.lineNumber, DiffGutterType, null);
|
|
254
|
-
this.textEditor.toggleLineClass(location.lineNumber, this.className, false);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export const DiffGutterType: string = 'CodeMirror-gutter-diff';
|
|
259
|
-
|
|
260
|
-
let contextMenuProviderInstance: ContextMenuProvider;
|
|
261
|
-
|
|
262
|
-
export class ContextMenuProvider implements UI.ContextMenu.Provider {
|
|
263
|
-
static instance(opts: {
|
|
264
|
-
forceNew: boolean|null,
|
|
265
|
-
} = {forceNew: null}): ContextMenuProvider {
|
|
266
|
-
const {forceNew} = opts;
|
|
267
|
-
if (!contextMenuProviderInstance || forceNew) {
|
|
268
|
-
contextMenuProviderInstance = new ContextMenuProvider();
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return contextMenuProviderInstance;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
appendApplicableItems(_event: Event, contextMenu: UI.ContextMenu.ContextMenu, target: Object): void {
|
|
275
|
-
let uiSourceCode: Workspace.UISourceCode.UISourceCode = (target as Workspace.UISourceCode.UISourceCode);
|
|
276
|
-
const binding = Persistence.Persistence.PersistenceImpl.instance().binding(uiSourceCode);
|
|
277
|
-
if (binding) {
|
|
278
|
-
uiSourceCode = binding.network;
|
|
279
|
-
}
|
|
280
|
-
GutterDiffPlugin.appendRevealDiffContextMenu(contextMenu, uiSourceCode);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
// Copyright 2016 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 * as Diff from '../../../../third_party/diff/diff.js';
|
|
6
|
-
import type * as TextEditor from '../text_editor/text_editor.js';
|
|
7
|
-
import type {SourcesTextEditor} from './SourcesTextEditor.js';
|
|
8
|
-
|
|
9
|
-
export class SourceCodeDiff {
|
|
10
|
-
private readonly textEditor: SourcesTextEditor;
|
|
11
|
-
private animatedLines: TextEditor.CodeMirrorTextEditor.TextEditorPositionHandle[];
|
|
12
|
-
private animationTimeout: number|null;
|
|
13
|
-
constructor(textEditor: SourcesTextEditor) {
|
|
14
|
-
this.textEditor = textEditor;
|
|
15
|
-
this.animatedLines = [];
|
|
16
|
-
this.animationTimeout = null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
highlightModifiedLines(oldContent: string|null, newContent: string|null): void {
|
|
20
|
-
if (typeof oldContent !== 'string' || typeof newContent !== 'string') {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const diff =
|
|
25
|
-
SourceCodeDiff.computeDiff(Diff.Diff.DiffWrapper.lineDiff(oldContent.split('\n'), newContent.split('\n')));
|
|
26
|
-
const changedLines = [];
|
|
27
|
-
for (let i = 0; i < diff.length; ++i) {
|
|
28
|
-
const diffEntry = diff[i];
|
|
29
|
-
if (diffEntry.type === EditType.Delete) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
for (let lineNumber = diffEntry.from; lineNumber < diffEntry.to; ++lineNumber) {
|
|
33
|
-
const position = this.textEditor.textEditorPositionHandle(lineNumber, 0);
|
|
34
|
-
if (position) {
|
|
35
|
-
changedLines.push(position);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
this.updateHighlightedLines(changedLines);
|
|
40
|
-
this.animationTimeout = window.setTimeout(
|
|
41
|
-
this.updateHighlightedLines.bind(this, []), 400); // // Keep this timeout in sync with sourcesView.css.
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private updateHighlightedLines(newLines: TextEditor.CodeMirrorTextEditor.TextEditorPositionHandle[]): void {
|
|
45
|
-
if (this.animationTimeout) {
|
|
46
|
-
clearTimeout(this.animationTimeout);
|
|
47
|
-
}
|
|
48
|
-
this.animationTimeout = null;
|
|
49
|
-
this.textEditor.operation(operation.bind(this));
|
|
50
|
-
|
|
51
|
-
function operation(this: SourceCodeDiff): void {
|
|
52
|
-
toggleLines.call(this, false);
|
|
53
|
-
this.animatedLines = newLines;
|
|
54
|
-
toggleLines.call(this, true);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function toggleLines(this: SourceCodeDiff, value: boolean): void {
|
|
58
|
-
for (let i = 0; i < this.animatedLines.length; ++i) {
|
|
59
|
-
const location = this.animatedLines[i].resolve();
|
|
60
|
-
if (location) {
|
|
61
|
-
this.textEditor.toggleLineClass(location.lineNumber, 'highlight-line-modification', value);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
static computeDiff(diff: Diff.Diff.DiffArray): {
|
|
68
|
-
type: EditType,
|
|
69
|
-
from: number,
|
|
70
|
-
to: number,
|
|
71
|
-
}[] {
|
|
72
|
-
const result: {
|
|
73
|
-
type: EditType,
|
|
74
|
-
from: number,
|
|
75
|
-
to: number,
|
|
76
|
-
}[] = [];
|
|
77
|
-
let hasAdded = false;
|
|
78
|
-
let hasRemoved = false;
|
|
79
|
-
let blockStartLineNumber = 0;
|
|
80
|
-
let currentLineNumber = 0;
|
|
81
|
-
let isInsideBlock = false;
|
|
82
|
-
for (let i = 0; i < diff.length; ++i) {
|
|
83
|
-
const token = diff[i];
|
|
84
|
-
if (token[0] === Diff.Diff.Operation.Equal) {
|
|
85
|
-
if (isInsideBlock) {
|
|
86
|
-
flush();
|
|
87
|
-
}
|
|
88
|
-
currentLineNumber += token[1].length;
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (!isInsideBlock) {
|
|
93
|
-
isInsideBlock = true;
|
|
94
|
-
blockStartLineNumber = currentLineNumber;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (token[0] === Diff.Diff.Operation.Delete) {
|
|
98
|
-
hasRemoved = true;
|
|
99
|
-
} else {
|
|
100
|
-
currentLineNumber += token[1].length;
|
|
101
|
-
hasAdded = true;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (isInsideBlock) {
|
|
105
|
-
flush();
|
|
106
|
-
}
|
|
107
|
-
if (result.length > 1 && result[0].from === 0 && result[1].from === 0) {
|
|
108
|
-
const merged = {type: EditType.Modify, from: 0, to: result[1].to};
|
|
109
|
-
result.splice(0, 2, merged);
|
|
110
|
-
}
|
|
111
|
-
return result;
|
|
112
|
-
|
|
113
|
-
function flush(): void {
|
|
114
|
-
let type = EditType.Insert;
|
|
115
|
-
let from = blockStartLineNumber;
|
|
116
|
-
let to: 1|number = currentLineNumber;
|
|
117
|
-
if (hasAdded && hasRemoved) {
|
|
118
|
-
type = EditType.Modify;
|
|
119
|
-
} else if (!hasAdded && hasRemoved && from === 0 && to === 0) {
|
|
120
|
-
type = EditType.Modify;
|
|
121
|
-
to = 1;
|
|
122
|
-
} else if (!hasAdded && hasRemoved) {
|
|
123
|
-
type = EditType.Delete;
|
|
124
|
-
from -= 1;
|
|
125
|
-
}
|
|
126
|
-
result.push({type: type, from: from, to: to});
|
|
127
|
-
isInsideBlock = false;
|
|
128
|
-
hasAdded = false;
|
|
129
|
-
hasRemoved = false;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// TODO(crbug.com/1167717): Make this a const enum again
|
|
135
|
-
// eslint-disable-next-line rulesdir/const_enum
|
|
136
|
-
export enum EditType {
|
|
137
|
-
Insert = 'Insert',
|
|
138
|
-
Delete = 'Delete',
|
|
139
|
-
Modify = 'Modify',
|
|
140
|
-
}
|