chrome-devtools-frontend 1.0.941208 → 1.0.942095
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/config/gni/all_devtools_files.gni +0 -6
- package/config/gni/devtools_grd_files.gni +6 -12
- package/config/gni/devtools_image_files.gni +0 -2
- package/front_end/Tests.js +1 -0
- package/front_end/core/common/Color.ts +5 -0
- package/front_end/core/i18n/locales/en-US.json +16 -28
- package/front_end/core/i18n/locales/en-XL.json +16 -28
- package/front_end/core/sdk/sdk-meta.ts +17 -3
- package/front_end/entrypoints/devtools_app/devtools_app.json +1 -7
- package/front_end/entrypoints/main/MainImpl.ts +26 -0
- package/front_end/entrypoints/shell/shell.js +0 -11
- package/front_end/entrypoints/worker_app/worker_app.json +0 -4
- package/front_end/generated/InspectorBackendCommands.js +1 -0
- package/front_end/generated/protocol.d.ts +2 -0
- package/front_end/legacy_test_runner/legacy_test_runner.ts +10 -1
- package/front_end/models/formatter/SourceFormatter.ts +0 -10
- package/front_end/models/workspace/UISourceCode.ts +9 -42
- package/front_end/panels/animation/AnimationTimeline.ts +3 -3
- package/front_end/panels/application/ApplicationPanelSidebar.ts +3 -3
- package/front_end/panels/application/application-meta.ts +0 -3
- package/front_end/panels/console/ConsolePinPane.ts +21 -26
- package/front_end/panels/coverage/CoverageDecorationManager.ts +4 -5
- package/front_end/panels/coverage/CoverageView.ts +2 -105
- package/front_end/panels/css_overview/components/CSSOverviewStartView.ts +11 -56
- package/front_end/panels/css_overview/components/cssOverviewStartView.css +1 -8
- package/front_end/panels/elements/ElementsTreeElement.ts +4 -9
- package/front_end/panels/elements/components/adornerSettingsPane.css +0 -4
- package/front_end/panels/emulation/emulation-meta.ts +2 -2
- package/front_end/panels/issues/issues-meta.ts +0 -2
- package/front_end/panels/layers/module.json +0 -1
- package/front_end/panels/lighthouse/lighthouseStartView.css +4 -0
- package/front_end/panels/media/media-meta.ts +0 -3
- package/front_end/panels/network/ResourceWebSocketFrameView.ts +2 -1
- package/front_end/panels/network/network-meta.ts +0 -3
- package/front_end/panels/security/security-meta.ts +0 -3
- package/front_end/panels/sources/BreakpointEditDialog.ts +16 -30
- package/front_end/panels/sources/CSSPlugin.ts +310 -331
- package/front_end/panels/sources/CallStackSidebarPane.ts +28 -34
- package/front_end/panels/sources/CoveragePlugin.ts +121 -6
- package/front_end/panels/sources/DebuggerPlugin.ts +1166 -1243
- package/front_end/panels/sources/EditingLocationHistoryManager.ts +71 -101
- package/front_end/panels/sources/GoToLineQuickOpen.ts +4 -3
- package/front_end/panels/sources/InplaceFormatterEditorAction.ts +3 -3
- package/front_end/panels/sources/JavaScriptCompilerPlugin.ts +26 -23
- package/front_end/panels/sources/Plugin.ts +20 -4
- package/front_end/panels/sources/ProfilePlugin.ts +185 -0
- package/front_end/panels/sources/ScriptFormatterEditorAction.ts +3 -3
- package/front_end/panels/sources/ScriptOriginPlugin.ts +0 -10
- package/front_end/panels/sources/SnippetsPlugin.ts +1 -10
- package/front_end/panels/sources/SourcesPanel.ts +6 -5
- package/front_end/panels/sources/SourcesView.ts +10 -8
- package/front_end/panels/sources/TabbedEditorContainer.ts +31 -27
- package/front_end/panels/sources/UISourceCodeFrame.ts +335 -470
- package/front_end/panels/sources/WatchExpressionsSidebarPane.ts +3 -2
- package/front_end/panels/sources/sources-legacy.ts +0 -6
- package/front_end/panels/sources/sources.ts +0 -2
- package/front_end/panels/timeline/module.json +0 -1
- package/front_end/third_party/codemirror.next/bundle.ts +9 -13
- package/front_end/third_party/codemirror.next/chunk/codemirror.js +1 -1
- package/front_end/third_party/codemirror.next/chunk/javascript.js +2 -2
- package/front_end/third_party/codemirror.next/chunk/markdown.js +2 -6
- package/front_end/third_party/codemirror.next/chunk/php.js +2 -6
- package/front_end/third_party/codemirror.next/chunk/python.js +1 -1
- package/front_end/third_party/codemirror.next/chunk/wast.js +1 -1
- package/front_end/third_party/codemirror.next/chunk/xml.js +2 -2
- package/front_end/third_party/codemirror.next/codemirror.next.d.ts +279 -198
- package/front_end/third_party/codemirror.next/codemirror.next.js +1 -1
- package/front_end/third_party/codemirror.next/package.json +13 -11
- package/front_end/ui/components/code_highlighter/CodeHighlighter.ts +60 -68
- package/front_end/ui/components/data_grid/dataGrid.css +12 -10
- package/front_end/ui/components/docs/css_overview/start_view.html +25 -0
- package/front_end/ui/components/docs/css_overview/start_view.ts +14 -0
- package/front_end/ui/components/text_editor/TextEditor.ts +79 -36
- package/front_end/ui/components/text_editor/config.ts +42 -26
- package/front_end/ui/components/text_editor/javascript.ts +2 -3
- package/front_end/ui/components/text_editor/position.ts +17 -0
- package/front_end/ui/components/text_editor/text_editor.ts +1 -0
- package/front_end/ui/components/text_editor/theme.ts +5 -1
- package/front_end/ui/legacy/Infobar.ts +2 -6
- package/front_end/ui/legacy/ShortcutRegistry.ts +11 -7
- package/front_end/ui/legacy/components/perf_ui/LineLevelProfile.ts +35 -131
- package/front_end/ui/legacy/components/source_frame/BinaryResourceViewFactory.ts +3 -6
- package/front_end/ui/legacy/components/source_frame/ResourceSourceFrame.ts +18 -14
- package/front_end/ui/legacy/components/source_frame/SourceFrame.ts +502 -252
- package/front_end/ui/legacy/components/source_frame/source_frame-legacy.ts +0 -11
- package/front_end/ui/legacy/components/source_frame/source_frame.ts +0 -2
- package/front_end/ui/legacy/components/text_editor/cmdevtools.css +3 -1
- package/front_end/ui/legacy/radioButton.css +1 -13
- package/front_end/ui/legacy/themeColors.css +36 -0
- package/package.json +1 -1
- package/front_end/Images/radioDot-dark-theme.png +0 -0
- package/front_end/Images/radioDot.png +0 -0
- package/front_end/panels/application/module.json +0 -6
- package/front_end/panels/issues/module.json +0 -6
- package/front_end/panels/layer_viewer/module.json +0 -5
- package/front_end/panels/media/module.json +0 -5
- package/front_end/panels/network/module.json +0 -5
- package/front_end/panels/security/module.json +0 -5
- package/front_end/ui/legacy/components/source_frame/SourcesTextEditor.ts +0 -1030
|
@@ -3,21 +3,21 @@
|
|
|
3
3
|
"version": "0.0.1",
|
|
4
4
|
"private": true,
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@codemirror/autocomplete": "0.19.
|
|
6
|
+
"@codemirror/autocomplete": "0.19.5",
|
|
7
7
|
"@codemirror/closebrackets": "0.19.0",
|
|
8
|
-
"@codemirror/commands": "0.19.
|
|
8
|
+
"@codemirror/commands": "0.19.5",
|
|
9
9
|
"@codemirror/comment": "0.19.0",
|
|
10
|
-
"@codemirror/fold": "0.19.
|
|
11
|
-
"@codemirror/gutter": "0.19.
|
|
10
|
+
"@codemirror/fold": "0.19.1",
|
|
11
|
+
"@codemirror/gutter": "0.19.3",
|
|
12
12
|
"@codemirror/highlight": "0.19.6",
|
|
13
13
|
"@codemirror/history": "0.19.0",
|
|
14
14
|
"@codemirror/lang-cpp": "0.19.1",
|
|
15
15
|
"@codemirror/lang-css": "0.19.3",
|
|
16
16
|
"@codemirror/lang-html": "0.19.3",
|
|
17
17
|
"@codemirror/lang-java": "0.19.1",
|
|
18
|
-
"@codemirror/lang-javascript": "0.19.
|
|
18
|
+
"@codemirror/lang-javascript": "0.19.3",
|
|
19
19
|
"@codemirror/lang-json": "0.19.1",
|
|
20
|
-
"@codemirror/lang-markdown": "0.19.
|
|
20
|
+
"@codemirror/lang-markdown": "0.19.2",
|
|
21
21
|
"@codemirror/lang-php": "0.19.1",
|
|
22
22
|
"@codemirror/lang-python": "0.19.2",
|
|
23
23
|
"@codemirror/lang-wast": "0.19.0",
|
|
@@ -25,13 +25,15 @@
|
|
|
25
25
|
"@codemirror/language": "0.19.3",
|
|
26
26
|
"@codemirror/legacy-modes": "0.19.0",
|
|
27
27
|
"@codemirror/matchbrackets": "0.19.3",
|
|
28
|
+
"@codemirror/panel": "0.19.0",
|
|
29
|
+
"@codemirror/rangeset": "0.19.2",
|
|
28
30
|
"@codemirror/search": "0.19.2",
|
|
29
|
-
"@codemirror/state": "0.19.
|
|
31
|
+
"@codemirror/state": "0.19.5",
|
|
30
32
|
"@codemirror/stream-parser": "0.19.2",
|
|
31
|
-
"@codemirror/text": "0.19.
|
|
32
|
-
"@codemirror/tooltip": "0.19.
|
|
33
|
-
"@codemirror/view": "0.19.
|
|
34
|
-
"@lezer/common": "0.15.
|
|
33
|
+
"@codemirror/text": "0.19.5",
|
|
34
|
+
"@codemirror/tooltip": "0.19.6",
|
|
35
|
+
"@codemirror/view": "0.19.16",
|
|
36
|
+
"@lezer/common": "0.15.8",
|
|
35
37
|
"@rollup/plugin-node-resolve": "^13.0.4",
|
|
36
38
|
"rollup-plugin-dts": "^4.0.0",
|
|
37
39
|
"rollup-plugin-terser": "^7.0.2",
|
|
@@ -2,56 +2,50 @@
|
|
|
2
2
|
// Use of this source code is governed by a BSD-style license that can be
|
|
3
3
|
// found in the LICENSE file.
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
{tag: t.deleted, class: 'token-deleted'},
|
|
40
|
-
{tag: t.heading, class: 'token-heading'},
|
|
41
|
-
{tag: t.link, class: 'token-link'},
|
|
42
|
-
{tag: t.strikethrough, class: 'token-strikethrough'},
|
|
43
|
-
{tag: t.strong, class: 'token-strong'},
|
|
44
|
-
{tag: t.emphasis, class: 'token-emphasis'},
|
|
45
|
-
]);
|
|
46
|
-
}
|
|
47
|
-
return highlightStyle;
|
|
48
|
-
}
|
|
5
|
+
import * as CodeMirror from '../../../third_party/codemirror.next/codemirror.next.js';
|
|
6
|
+
|
|
7
|
+
const t = CodeMirror.tags;
|
|
8
|
+
|
|
9
|
+
export const highlightStyle: CodeMirror.HighlightStyle = CodeMirror.HighlightStyle.define([
|
|
10
|
+
{tag: t.variableName, class: 'token-variable'},
|
|
11
|
+
{tag: t.propertyName, class: 'token-property'},
|
|
12
|
+
{tag: [t.typeName, t.className, t.namespace, t.macroName], class: 'token-type'},
|
|
13
|
+
{tag: [t.special(t.name), t.constant(t.className)], class: 'token-variable-special'},
|
|
14
|
+
{tag: t.definition(t.name), class: 'token-definition'},
|
|
15
|
+
{tag: t.standard(t.variableName), class: 'token-builtin'},
|
|
16
|
+
|
|
17
|
+
{tag: [t.number, t.literal, t.unit], class: 'token-number'},
|
|
18
|
+
{tag: t.string, class: 'token-string'},
|
|
19
|
+
{tag: [t.special(t.string), t.regexp, t.escape], class: 'token-string-special'},
|
|
20
|
+
{tag: [t.atom, t.labelName, t.bool], class: 'token-atom'},
|
|
21
|
+
|
|
22
|
+
{tag: t.keyword, class: 'token-keyword'},
|
|
23
|
+
{tag: [t.comment, t.quote], class: 'token-comment'},
|
|
24
|
+
{tag: t.meta, class: 'token-meta'},
|
|
25
|
+
{tag: t.invalid, class: 'token-invalid'},
|
|
26
|
+
|
|
27
|
+
{tag: t.tagName, class: 'token-tag'},
|
|
28
|
+
{tag: t.attributeName, class: 'token-attribute'},
|
|
29
|
+
{tag: t.attributeValue, class: 'token-attribute-value'},
|
|
30
|
+
|
|
31
|
+
{tag: t.inserted, class: 'token-inserted'},
|
|
32
|
+
{tag: t.deleted, class: 'token-deleted'},
|
|
33
|
+
{tag: t.heading, class: 'token-heading'},
|
|
34
|
+
{tag: t.link, class: 'token-link'},
|
|
35
|
+
{tag: t.strikethrough, class: 'token-strikethrough'},
|
|
36
|
+
{tag: t.strong, class: 'token-strong'},
|
|
37
|
+
{tag: t.emphasis, class: 'token-emphasis'},
|
|
38
|
+
]);
|
|
49
39
|
|
|
50
40
|
export async function create(code: string, mimeType: string): Promise<CodeHighlighter> {
|
|
51
|
-
const CM = await importCM();
|
|
52
41
|
const language = await languageFromMIME(mimeType);
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
let tree: CodeMirror.Tree;
|
|
43
|
+
if (language) {
|
|
44
|
+
tree = language.language.parser.parse(code);
|
|
45
|
+
} else {
|
|
46
|
+
tree = new CodeMirror.Tree(CodeMirror.NodeType.none, [], [], code.length);
|
|
47
|
+
}
|
|
48
|
+
return new CodeHighlighter(code, tree);
|
|
55
49
|
}
|
|
56
50
|
|
|
57
51
|
export async function highlightNode(node: Element, mimeType: string): Promise<void> {
|
|
@@ -71,57 +65,55 @@ export async function highlightNode(node: Element, mimeType: string): Promise<vo
|
|
|
71
65
|
}
|
|
72
66
|
|
|
73
67
|
export async function languageFromMIME(mimeType: string): Promise<CodeMirror.LanguageSupport|null> {
|
|
74
|
-
const CM = await importCM();
|
|
75
|
-
|
|
76
68
|
switch (mimeType) {
|
|
77
69
|
case 'text/javascript':
|
|
78
|
-
return
|
|
70
|
+
return CodeMirror.javascript.javascript();
|
|
79
71
|
case 'text/jsx':
|
|
80
|
-
return
|
|
72
|
+
return CodeMirror.javascript.javascript({jsx: true});
|
|
81
73
|
case 'text/typescript':
|
|
82
|
-
return
|
|
74
|
+
return CodeMirror.javascript.javascript({typescript: true});
|
|
83
75
|
case 'text/typescript-jsx':
|
|
84
|
-
return
|
|
76
|
+
return CodeMirror.javascript.javascript({typescript: true, jsx: true});
|
|
85
77
|
|
|
86
78
|
case 'text/css':
|
|
87
79
|
case 'text/x-scss':
|
|
88
|
-
return
|
|
80
|
+
return CodeMirror.css.css();
|
|
89
81
|
|
|
90
82
|
case 'text/html':
|
|
91
|
-
return
|
|
83
|
+
return CodeMirror.html.html();
|
|
92
84
|
|
|
93
85
|
case 'application/xml':
|
|
94
|
-
return (await
|
|
86
|
+
return (await CodeMirror.xml()).xml();
|
|
95
87
|
|
|
96
88
|
case 'text/webassembly':
|
|
97
|
-
return (await
|
|
89
|
+
return (await CodeMirror.wast()).wast();
|
|
98
90
|
|
|
99
91
|
case 'text/x-c++src':
|
|
100
|
-
return (await
|
|
92
|
+
return (await CodeMirror.cpp()).cpp();
|
|
101
93
|
|
|
102
94
|
case 'text/x-java':
|
|
103
|
-
return (await
|
|
95
|
+
return (await CodeMirror.java()).java();
|
|
104
96
|
|
|
105
97
|
case 'application/json':
|
|
106
|
-
return (await
|
|
98
|
+
return (await CodeMirror.json()).json();
|
|
107
99
|
|
|
108
100
|
case 'application/x-httpd-php':
|
|
109
|
-
return (await
|
|
101
|
+
return (await CodeMirror.php()).php();
|
|
110
102
|
|
|
111
103
|
case 'text/x-python':
|
|
112
|
-
return (await
|
|
104
|
+
return (await CodeMirror.python()).python();
|
|
113
105
|
|
|
114
106
|
case 'text/markdown':
|
|
115
|
-
return (await
|
|
107
|
+
return (await CodeMirror.markdown()).markdown();
|
|
116
108
|
|
|
117
109
|
case 'text/x-sh':
|
|
118
|
-
return new
|
|
110
|
+
return new CodeMirror.LanguageSupport(await CodeMirror.shell());
|
|
119
111
|
|
|
120
112
|
case 'text/x-coffeescript':
|
|
121
|
-
return new
|
|
113
|
+
return new CodeMirror.LanguageSupport(await CodeMirror.coffeescript());
|
|
122
114
|
|
|
123
115
|
case 'text/x-clojure':
|
|
124
|
-
return new
|
|
116
|
+
return new CodeMirror.LanguageSupport(await CodeMirror.clojure());
|
|
125
117
|
|
|
126
118
|
default:
|
|
127
119
|
return null;
|
|
@@ -129,7 +121,7 @@ export async function languageFromMIME(mimeType: string): Promise<CodeMirror.Lan
|
|
|
129
121
|
}
|
|
130
122
|
|
|
131
123
|
export class CodeHighlighter {
|
|
132
|
-
constructor(readonly code: string, readonly tree: CodeMirror.Tree
|
|
124
|
+
constructor(readonly code: string, readonly tree: CodeMirror.Tree) {
|
|
133
125
|
}
|
|
134
126
|
|
|
135
127
|
highlight(token: (text: string, style: string) => void): void {
|
|
@@ -144,7 +136,7 @@ export class CodeHighlighter {
|
|
|
144
136
|
pos = to;
|
|
145
137
|
}
|
|
146
138
|
};
|
|
147
|
-
|
|
139
|
+
CodeMirror.highlightTree(this.tree, highlightStyle.match, (from, to, style) => {
|
|
148
140
|
flush(from, '');
|
|
149
141
|
flush(to, style);
|
|
150
142
|
}, from, to);
|
|
@@ -120,21 +120,23 @@ th.firstVisibleColumn {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
[aria-sort="descending"]::after {
|
|
123
|
-
content: "
|
|
124
|
-
|
|
125
|
-
border-
|
|
126
|
-
border-
|
|
123
|
+
content: "";
|
|
124
|
+
width: 0;
|
|
125
|
+
border-left: 0.4em solid transparent;
|
|
126
|
+
border-right: 0.4em solid transparent;
|
|
127
|
+
border-top: 0.4em solid var(--color-text-secondary);
|
|
127
128
|
position: absolute;
|
|
128
129
|
right: 0.5em;
|
|
129
|
-
top: 0.
|
|
130
|
+
top: 0.85em;
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
[aria-sort="ascending"]::after {
|
|
133
|
-
content: "
|
|
134
|
-
|
|
135
|
-
border-
|
|
136
|
-
border-
|
|
134
|
+
content: "";
|
|
135
|
+
width: 0;
|
|
136
|
+
border-bottom: 0.4em solid var(--color-text-secondary);
|
|
137
|
+
border-left: 0.4em solid transparent;
|
|
138
|
+
border-right: 0.4em solid transparent;
|
|
137
139
|
position: absolute;
|
|
138
140
|
right: 0.5em;
|
|
139
|
-
top: 0.
|
|
141
|
+
top: 0.7em;
|
|
140
142
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Copyright 2021 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
|
+
<!DOCTYPE html>
|
|
7
|
+
<html>
|
|
8
|
+
<head>
|
|
9
|
+
<meta charset="UTF-8" />
|
|
10
|
+
<meta name="viewport" content="width=device-width" />
|
|
11
|
+
<title>CSS Overview Start View</title>
|
|
12
|
+
<style>
|
|
13
|
+
#container {
|
|
14
|
+
width: 80%;
|
|
15
|
+
border: 1px solid black;
|
|
16
|
+
padding: 10px;
|
|
17
|
+
}
|
|
18
|
+
</style>
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
<div id="container">
|
|
22
|
+
</div>
|
|
23
|
+
<script type="module" src="./start_view.js"></script>
|
|
24
|
+
</body>
|
|
25
|
+
</html>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright 2021 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 FrontendHelpers from '../../../../../test/unittests/front_end/helpers/EnvironmentHelpers.js';
|
|
6
|
+
import * as CSSOverviewComponents from '../../../../panels/css_overview/components/components.js';
|
|
7
|
+
import * as ComponentHelpers from '../../helpers/helpers.js';
|
|
8
|
+
|
|
9
|
+
await ComponentHelpers.ComponentServerSetup.setup();
|
|
10
|
+
await FrontendHelpers.initializeGlobalVars();
|
|
11
|
+
|
|
12
|
+
const component = new CSSOverviewComponents.CSSOverviewStartView.CSSOverviewStartView();
|
|
13
|
+
|
|
14
|
+
document.getElementById('container')?.appendChild(component);
|
|
@@ -8,7 +8,8 @@ import * as LitHtml from '../../lit-html/lit-html.js';
|
|
|
8
8
|
import * as CodeHighlighter from '../code_highlighter/code_highlighter.js';
|
|
9
9
|
import * as ComponentHelpers from '../helpers/helpers.js';
|
|
10
10
|
|
|
11
|
-
import {baseConfiguration, dynamicSetting} from './config.js';
|
|
11
|
+
import {baseConfiguration, dynamicSetting, DynamicSetting} from './config.js';
|
|
12
|
+
import {toLineColumn, toOffset} from './position.js';
|
|
12
13
|
|
|
13
14
|
declare global {
|
|
14
15
|
interface HTMLElementTagNameMap {
|
|
@@ -21,6 +22,7 @@ export class TextEditor extends HTMLElement {
|
|
|
21
22
|
|
|
22
23
|
private readonly shadow = this.attachShadow({mode: 'open'});
|
|
23
24
|
private activeEditor: CodeMirror.EditorView|undefined = undefined;
|
|
25
|
+
private dynamicSettings: readonly DynamicSetting<unknown>[] = DynamicSetting.none;
|
|
24
26
|
private activeSettingListeners: [Common.Settings.Setting<unknown>, (event: {data: unknown}) => void][] = [];
|
|
25
27
|
private pendingState: CodeMirror.EditorState|undefined;
|
|
26
28
|
|
|
@@ -32,10 +34,17 @@ export class TextEditor extends HTMLElement {
|
|
|
32
34
|
|
|
33
35
|
private createEditor(): CodeMirror.EditorView {
|
|
34
36
|
this.activeEditor = new CodeMirror.EditorView({
|
|
35
|
-
state: this.
|
|
37
|
+
state: this.state,
|
|
36
38
|
parent: this.shadow,
|
|
37
39
|
root: this.shadow,
|
|
40
|
+
dispatch: (tr: CodeMirror.Transaction): void => {
|
|
41
|
+
this.editor.update([tr]);
|
|
42
|
+
if (tr.reconfigured) {
|
|
43
|
+
this.ensureSettingListeners();
|
|
44
|
+
}
|
|
45
|
+
},
|
|
38
46
|
});
|
|
47
|
+
this.ensureSettingListeners();
|
|
39
48
|
return this.activeEditor;
|
|
40
49
|
}
|
|
41
50
|
|
|
@@ -43,6 +52,10 @@ export class TextEditor extends HTMLElement {
|
|
|
43
52
|
return this.activeEditor || this.createEditor();
|
|
44
53
|
}
|
|
45
54
|
|
|
55
|
+
dispatch(spec: CodeMirror.TransactionSpec): void {
|
|
56
|
+
return this.editor.dispatch(spec);
|
|
57
|
+
}
|
|
58
|
+
|
|
46
59
|
get state(): CodeMirror.EditorState {
|
|
47
60
|
if (this.activeEditor) {
|
|
48
61
|
return this.activeEditor.state;
|
|
@@ -65,7 +78,6 @@ export class TextEditor extends HTMLElement {
|
|
|
65
78
|
if (!this.activeEditor) {
|
|
66
79
|
this.createEditor();
|
|
67
80
|
}
|
|
68
|
-
this.registerSettingHandlers();
|
|
69
81
|
}
|
|
70
82
|
|
|
71
83
|
disconnectedCallback(): void {
|
|
@@ -73,63 +85,94 @@ export class TextEditor extends HTMLElement {
|
|
|
73
85
|
this.pendingState = this.activeEditor.state;
|
|
74
86
|
this.activeEditor.destroy();
|
|
75
87
|
this.activeEditor = undefined;
|
|
88
|
+
this.ensureSettingListeners();
|
|
76
89
|
}
|
|
77
|
-
for (const [setting, listener] of this.activeSettingListeners) {
|
|
78
|
-
setting.removeChangeListener(listener);
|
|
79
|
-
}
|
|
80
|
-
this.activeSettingListeners = [];
|
|
81
90
|
}
|
|
82
91
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
for (const opt of state.facet(dynamicSetting)) {
|
|
87
|
-
const mustUpdate = opt.sync(state, settings.moduleSetting(opt.settingName).get());
|
|
88
|
-
if (mustUpdate) {
|
|
89
|
-
changes.push(mustUpdate);
|
|
90
|
-
}
|
|
92
|
+
focus(): void {
|
|
93
|
+
if (this.activeEditor) {
|
|
94
|
+
this.activeEditor.focus();
|
|
91
95
|
}
|
|
92
|
-
return changes.length ? state.update({effects: changes}).state : state;
|
|
93
96
|
}
|
|
94
97
|
|
|
95
|
-
private
|
|
98
|
+
private ensureSettingListeners(): void {
|
|
99
|
+
const dynamicSettings = this.activeEditor ? this.activeEditor.state.facet(dynamicSetting) : DynamicSetting.none;
|
|
100
|
+
if (dynamicSettings === this.dynamicSettings) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
this.dynamicSettings = dynamicSettings;
|
|
104
|
+
|
|
105
|
+
for (const [setting, listener] of this.activeSettingListeners) {
|
|
106
|
+
setting.removeChangeListener(listener);
|
|
107
|
+
}
|
|
108
|
+
this.activeSettingListeners = [];
|
|
109
|
+
|
|
96
110
|
const settings = Common.Settings.Settings.instance();
|
|
97
|
-
for (const
|
|
111
|
+
for (const dynamicSetting of dynamicSettings) {
|
|
98
112
|
const handler = ({data}: {data: unknown}): void => {
|
|
99
|
-
const change =
|
|
113
|
+
const change = dynamicSetting.sync(this.state, data);
|
|
100
114
|
if (change && this.activeEditor) {
|
|
101
115
|
this.activeEditor.dispatch({effects: change});
|
|
102
116
|
}
|
|
103
117
|
};
|
|
104
|
-
const setting = settings.moduleSetting(
|
|
118
|
+
const setting = settings.moduleSetting(dynamicSetting.settingName);
|
|
105
119
|
setting.addChangeListener(handler);
|
|
106
120
|
this.activeSettingListeners.push([setting, handler]);
|
|
107
121
|
}
|
|
108
122
|
}
|
|
109
123
|
|
|
110
|
-
revealPosition(
|
|
124
|
+
revealPosition(selection: CodeMirror.EditorSelection, highlight: boolean = true): void {
|
|
111
125
|
const view = this.activeEditor;
|
|
112
126
|
if (!view) {
|
|
113
127
|
return;
|
|
114
128
|
}
|
|
115
129
|
|
|
116
|
-
const line = view.state.doc.lineAt(
|
|
130
|
+
const line = view.state.doc.lineAt(selection.main.head);
|
|
131
|
+
const effects: CodeMirror.StateEffect<unknown>[] = [];
|
|
132
|
+
if (highlight) {
|
|
133
|
+
effects.push(
|
|
134
|
+
view.state.field(highlightState, false) ?
|
|
135
|
+
setHighlightLine.of(line.from) :
|
|
136
|
+
CodeMirror.StateEffect.appendConfig.of(highlightState.init(() => highlightDeco(line.from))));
|
|
137
|
+
}
|
|
138
|
+
const editorRect = view.scrollDOM.getBoundingClientRect();
|
|
139
|
+
const targetPos = view.coordsAtPos(selection.main.head);
|
|
140
|
+
if (!targetPos || targetPos.top < editorRect.top || targetPos.bottom > editorRect.bottom) {
|
|
141
|
+
effects.push(CodeMirror.EditorView.centerOn.of(selection.main));
|
|
142
|
+
}
|
|
143
|
+
|
|
117
144
|
view.dispatch({
|
|
118
|
-
selection
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
[view.state.field(highlightState, false) ?
|
|
122
|
-
setHighlightLine.of(line.from) :
|
|
123
|
-
CodeMirror.StateEffect.appendConfig.of(highlightState.init(() => highlightDeco(line.from)))],
|
|
145
|
+
selection,
|
|
146
|
+
effects,
|
|
147
|
+
userEvent: 'select.reveal',
|
|
124
148
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
view.
|
|
131
|
-
|
|
132
|
-
|
|
149
|
+
if (highlight) {
|
|
150
|
+
const {id} = view.state.field(highlightState);
|
|
151
|
+
// Reset the highlight state if, after 2 seconds (the animation
|
|
152
|
+
// duration) it is still showing this highlight.
|
|
153
|
+
setTimeout(() => {
|
|
154
|
+
if (view.state.field(highlightState).id === id) {
|
|
155
|
+
view.dispatch({effects: setHighlightLine.of(null)});
|
|
156
|
+
}
|
|
157
|
+
}, 2000);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
createSelection(head: {lineNumber: number, columnNumber: number}, anchor?: {
|
|
162
|
+
lineNumber: number,
|
|
163
|
+
columnNumber: number,
|
|
164
|
+
}): CodeMirror.EditorSelection {
|
|
165
|
+
const {doc} = this.state;
|
|
166
|
+
const headPos = toOffset(doc, head);
|
|
167
|
+
return CodeMirror.EditorSelection.single(anchor ? toOffset(doc, anchor) : headPos, headPos);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
toLineColumn(pos: number): {lineNumber: number, columnNumber: number} {
|
|
171
|
+
return toLineColumn(this.state.doc, pos);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
toOffset(pos: {lineNumber: number, columnNumber: number}): number {
|
|
175
|
+
return toOffset(this.state.doc, pos);
|
|
133
176
|
}
|
|
134
177
|
}
|
|
135
178
|
|
|
@@ -31,24 +31,35 @@ export const dynamicSetting = CM.Facet.define<DynamicSetting<unknown>>();
|
|
|
31
31
|
|
|
32
32
|
export class DynamicSetting<T> {
|
|
33
33
|
compartment = new CM.Compartment();
|
|
34
|
-
extension: CM.Extension;
|
|
35
34
|
|
|
36
35
|
constructor(
|
|
37
36
|
readonly settingName: string,
|
|
38
|
-
private readonly getExtension: (value: T
|
|
37
|
+
private readonly getExtension: (value: T) => CM.Extension,
|
|
39
38
|
) {
|
|
40
|
-
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
settingValue(): T {
|
|
42
|
+
return Common.Settings.Settings.instance().moduleSetting(this.settingName).get() as T;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
instance(): CM.Extension {
|
|
46
|
+
return [
|
|
47
|
+
this.compartment.of(this.getExtension(this.settingValue())),
|
|
48
|
+
dynamicSetting.of(this as DynamicSetting<unknown>),
|
|
49
|
+
];
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
sync(state: CM.EditorState, value: T): CM.StateEffect<unknown>|null {
|
|
44
53
|
const cur = this.compartment.get(state);
|
|
45
|
-
const needed = this.getExtension(value
|
|
54
|
+
const needed = this.getExtension(value);
|
|
46
55
|
return cur === needed ? null : this.compartment.reconfigure(needed);
|
|
47
56
|
}
|
|
48
57
|
|
|
49
58
|
static bool(name: string, enabled: CM.Extension, disabled: CM.Extension = empty): DynamicSetting<boolean> {
|
|
50
59
|
return new DynamicSetting<boolean>(name, val => val ? enabled : disabled);
|
|
51
60
|
}
|
|
61
|
+
|
|
62
|
+
static none: readonly DynamicSetting<unknown>[] = [];
|
|
52
63
|
}
|
|
53
64
|
|
|
54
65
|
export const tabMovesFocus = DynamicSetting.bool('textEditorTabMovesFocus', CM.keymap.of([{
|
|
@@ -82,23 +93,15 @@ export function guessIndent(doc: CM.Text): string {
|
|
|
82
93
|
values[space] = (values[space] || 0) + 1;
|
|
83
94
|
}
|
|
84
95
|
const minOccurrence = scanned * 0.05;
|
|
85
|
-
const
|
|
86
|
-
|
|
96
|
+
const shortest = Object.entries(values).reduce((shortest, [string, count]): string|null => {
|
|
97
|
+
return count < minOccurrence || shortest && shortest.length < string.length ? shortest : string;
|
|
98
|
+
}, null as string | null);
|
|
99
|
+
return shortest ?? Common.Settings.Settings.instance().moduleSetting('textEditorIndent').get();
|
|
87
100
|
}
|
|
88
101
|
|
|
89
|
-
const
|
|
102
|
+
const deriveIndentUnit = CM.Prec.highest(CM.indentUnit.compute([], (state: CM.EditorState) => guessIndent(state.doc)));
|
|
90
103
|
|
|
91
|
-
|
|
92
|
-
let value = cachedIndentUnit[indent];
|
|
93
|
-
if (!value) {
|
|
94
|
-
value = cachedIndentUnit[indent] = CM.indentUnit.of(indent);
|
|
95
|
-
}
|
|
96
|
-
return value;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export const autoDetectIndent = new DynamicSetting<boolean>('textEditorAutoDetectIndent', (on, state) => {
|
|
100
|
-
return on ? CM.Prec.override(getIndentUnit(guessIndent(state.doc))) : empty;
|
|
101
|
-
});
|
|
104
|
+
export const autoDetectIndent = DynamicSetting.bool('textEditorAutoDetectIndent', deriveIndentUnit);
|
|
102
105
|
|
|
103
106
|
function matcher(decorator: CM.MatchDecorator): CM.Extension {
|
|
104
107
|
return CM.ViewPlugin.define(
|
|
@@ -154,6 +157,16 @@ export const showWhitespace = new DynamicSetting<string>('showWhitespacesInEdito
|
|
|
154
157
|
|
|
155
158
|
export const allowScrollPastEof = DynamicSetting.bool('allowScrollPastEof', CM.scrollPastEnd());
|
|
156
159
|
|
|
160
|
+
const cachedIndentUnit: {[indent: string]: CM.Extension} = Object.create(null);
|
|
161
|
+
|
|
162
|
+
function getIndentUnit(indent: string): CM.Extension {
|
|
163
|
+
let value = cachedIndentUnit[indent];
|
|
164
|
+
if (!value) {
|
|
165
|
+
value = cachedIndentUnit[indent] = CM.indentUnit.of(indent);
|
|
166
|
+
}
|
|
167
|
+
return value;
|
|
168
|
+
}
|
|
169
|
+
|
|
157
170
|
export const indentUnit = new DynamicSetting<string>('textEditorIndent', getIndentUnit);
|
|
158
171
|
|
|
159
172
|
export const domWordWrap = DynamicSetting.bool('domWordWrap', CM.EditorView.lineWrapping);
|
|
@@ -184,22 +197,25 @@ function themeIsDark(): boolean {
|
|
|
184
197
|
|
|
185
198
|
const dummyDarkTheme = CM.EditorView.theme({}, {dark: true});
|
|
186
199
|
|
|
200
|
+
export function theme(): CM.Extension {
|
|
201
|
+
return [editorTheme, themeIsDark() ? dummyDarkTheme : []];
|
|
202
|
+
}
|
|
203
|
+
|
|
187
204
|
export function baseConfiguration(text: string): CM.Extension {
|
|
188
205
|
return [
|
|
189
|
-
|
|
190
|
-
themeIsDark() ? dummyDarkTheme : [],
|
|
206
|
+
theme(),
|
|
191
207
|
CM.highlightSpecialChars(),
|
|
192
208
|
CM.history(),
|
|
193
209
|
CM.drawSelection(),
|
|
194
210
|
CM.EditorState.allowMultipleSelections.of(true),
|
|
195
211
|
CM.indentOnInput(),
|
|
196
|
-
CodeHighlighter.CodeHighlighter.
|
|
212
|
+
CodeHighlighter.CodeHighlighter.highlightStyle,
|
|
197
213
|
CM.closeBrackets(),
|
|
198
214
|
baseKeymap,
|
|
199
|
-
tabMovesFocus,
|
|
200
|
-
bracketMatching,
|
|
201
|
-
indentUnit,
|
|
202
|
-
CM.Prec.
|
|
215
|
+
tabMovesFocus.instance(),
|
|
216
|
+
bracketMatching.instance(),
|
|
217
|
+
indentUnit.instance(),
|
|
218
|
+
CM.Prec.lowest(CM.EditorView.contentAttributes.of({'aria-label': i18nString(UIStrings.codeEditor)})),
|
|
203
219
|
detectLineSeparator(text),
|
|
204
220
|
autocompletion,
|
|
205
221
|
CM.tooltips({parent: getTooltipHost() as unknown as HTMLElement}),
|
|
@@ -221,7 +237,7 @@ function getTooltipHost(): ShadowRoot {
|
|
|
221
237
|
extensions: [
|
|
222
238
|
editorTheme,
|
|
223
239
|
themeIsDark() ? dummyDarkTheme : [],
|
|
224
|
-
CodeHighlighter.CodeHighlighter.
|
|
240
|
+
CodeHighlighter.CodeHighlighter.highlightStyle,
|
|
225
241
|
CM.showTooltip.of({
|
|
226
242
|
pos: 0,
|
|
227
243
|
create() {
|
|
@@ -9,9 +9,8 @@ import * as CodeMirror from '../../../third_party/codemirror.next/codemirror.nex
|
|
|
9
9
|
import * as UI from '../../legacy/legacy.js';
|
|
10
10
|
import {cursorTooltip} from './cursor_tooltip.js';
|
|
11
11
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
return javascriptLanguage.data.of({
|
|
12
|
+
export function completion(): CodeMirror.Extension {
|
|
13
|
+
return CodeMirror.javascript.javascriptLanguage.data.of({
|
|
15
14
|
autocomplete: javascriptCompletionSource,
|
|
16
15
|
});
|
|
17
16
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright 2021 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 type * as CodeMirror from '../../../third_party/codemirror.next/codemirror.next.js';
|
|
6
|
+
|
|
7
|
+
export function toOffset(
|
|
8
|
+
doc: CodeMirror.Text, {lineNumber, columnNumber}: {lineNumber: number, columnNumber: number}): number {
|
|
9
|
+
const line = doc.line(Math.max(1, Math.min(doc.lines, lineNumber + 1)));
|
|
10
|
+
return Math.max(line.from, Math.min(line.to, line.from + columnNumber));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function toLineColumn(doc: CodeMirror.Text, offset: number): {lineNumber: number, columnNumber: number} {
|
|
14
|
+
offset = Math.max(0, Math.min(offset, doc.length));
|
|
15
|
+
const line = doc.lineAt(offset);
|
|
16
|
+
return {lineNumber: line.number - 1, columnNumber: offset - line.from};
|
|
17
|
+
}
|