forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditorMenu.js
More file actions
137 lines (117 loc) · 3.75 KB
/
Copy pathEditorMenu.js
File metadata and controls
137 lines (117 loc) · 3.75 KB
1
2
3
4
5
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { showMenu } from "devtools-launchpad";
import { isOriginalId } from "devtools-source-map";
import { copyToTheClipboard } from "../../utils/clipboard";
import { getSourceLocationFromMouseEvent } from "../../utils/editor";
function getMenuItems(
event,
{
editor,
selectedLocation,
selectedSource,
showSource,
onGutterContextMenu,
jumpToMappedLocation,
toggleBlackBox,
addExpression,
getFunctionText
}
) {
const copySourceLabel = L10N.getStr("copySource");
const copySourceKey = L10N.getStr("copySource.accesskey");
const copyFunctionLabel = L10N.getStr("copyFunction.label");
const copyFunctionKey = L10N.getStr("copyFunction.accesskey");
const copySourceUri2Label = L10N.getStr("copySourceUri2");
const copySourceUri2Key = L10N.getStr("copySourceUri2.accesskey");
const revealInTreeLabel = L10N.getStr("sourceTabs.revealInTree");
const revealInTreeKey = L10N.getStr("sourceTabs.revealInTree.accesskey");
const blackboxLabel = L10N.getStr("sourceFooter.blackbox");
const unblackboxLabel = L10N.getStr("sourceFooter.unblackbox");
const blackboxKey = L10N.getStr("sourceFooter.blackbox.accesskey");
const toggleBlackBoxLabel = selectedSource.get("isBlackBoxed")
? unblackboxLabel
: blackboxLabel;
const copySourceUri2 = {
id: "node-menu-copy-source-url",
label: copySourceUri2Label,
accesskey: copySourceUri2Key,
disabled: false,
click: () => copyToTheClipboard(selectedSource.get("url"))
};
const selectionText = editor.codeMirror.getSelection().trim();
const copySource = {
id: "node-menu-copy-source",
label: copySourceLabel,
accesskey: copySourceKey,
disabled: selectionText.length === 0,
click: () => copyToTheClipboard(selectionText)
};
const { line } = editor.codeMirror.coordsChar({
left: event.clientX
});
const sourceLocation = getSourceLocationFromMouseEvent(
editor,
selectedLocation,
event
);
const pairedType = isOriginalId(selectedLocation.sourceId)
? L10N.getStr("generated")
: L10N.getStr("original");
const jumpLabel = {
accesskey: "C",
disabled: false,
label: L10N.getFormatStr("editor.jumpToMappedLocation1", pairedType),
click: () => jumpToMappedLocation(sourceLocation)
};
const watchExpressionLabel = {
accesskey: "E",
label: L10N.getStr("expressions.placeholder"),
click: () => addExpression(editor.codeMirror.getSelection())
};
const blackBoxMenuItem = {
id: "node-menu-blackbox",
label: toggleBlackBoxLabel,
accesskey: blackboxKey,
disabled: false,
click: () => toggleBlackBox(selectedSource.toJS())
};
// TODO: Find a new way to only add this for mapped sources?
const textSelected = editor.codeMirror.somethingSelected();
const showSourceMenuItem = {
id: "node-menu-show-source",
label: revealInTreeLabel,
accesskey: revealInTreeKey,
disabled: false,
click: () => showSource(selectedSource.get("id"))
};
const functionText = getFunctionText(line + 1);
const copyFunction = {
id: "node-menu-copy-function",
label: copyFunctionLabel,
accesskey: copyFunctionKey,
disabled: !functionText,
click: () => copyToTheClipboard(functionText)
};
const menuItems = [
copySource,
copySourceUri2,
copyFunction,
{ type: "separator" },
jumpLabel,
showSourceMenuItem,
blackBoxMenuItem
];
if (textSelected) {
menuItems.push(watchExpressionLabel);
}
return menuItems;
}
async function EditorMenu(options) {
const { event, onGutterContextMenu } = options;
if (event.target.classList.contains("CodeMirror-linenumber")) {
return onGutterContextMenu(event);
}
event.stopPropagation();
event.preventDefault();
showMenu(event, getMenuItems(event, options));
}
export default EditorMenu;