Skip to content

Commit 7973477

Browse files
author
Brian Vaughn
authored
Disable "copy to clipboard" and "go to definition" context menu options for Firefox addon (facebook#17668)
1 parent dbc46ac commit 7973477

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

packages/react-devtools-extensions/src/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,15 @@ function createPanelIfReactLoaded() {
211211
browserTheme: getBrowserTheme(),
212212
componentsPortalContainer,
213213
enabledInspectedElementContextMenu: true,
214+
enabledInspectedElementContextMenuCopy: isChrome,
214215
overrideTab,
215216
profilerPortalContainer,
216217
showTabBar: false,
217218
store,
218219
warnIfUnsupportedVersionDetected: true,
219-
viewAttributeSourceFunction,
220+
viewAttributeSourceFunction: isChrome
221+
? viewAttributeSourceFunction
222+
: null,
220223
viewElementSourceFunction,
221224
}),
222225
);

packages/react-devtools-shared/src/devtools/views/Components/SelectedElement.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ function InspectedElementView({
303303

304304
const {
305305
isEnabledForInspectedElement,
306+
supportsCopyOperation,
306307
viewAttributeSourceFunction,
307308
} = useContext(ContextMenuContext);
308309

@@ -444,12 +445,14 @@ function InspectedElementView({
444445
<ContextMenu id="SelectedElement">
445446
{data => (
446447
<Fragment>
447-
<ContextMenuItem
448-
onClick={() => copyInspectedElementPath(id, data.path)}
449-
title="Copy value to clipboard">
450-
<Icon className={styles.ContextMenuIcon} type="copy" /> Copy
451-
value to clipboard
452-
</ContextMenuItem>
448+
{supportsCopyOperation && (
449+
<ContextMenuItem
450+
onClick={() => copyInspectedElementPath(id, data.path)}
451+
title="Copy value to clipboard">
452+
<Icon className={styles.ContextMenuIcon} type="copy" /> Copy
453+
value to clipboard
454+
</ContextMenuItem>
455+
)}
453456
<ContextMenuItem
454457
onClick={() => storeAsGlobal(id, data.path)}
455458
title="Store as global variable">

packages/react-devtools-shared/src/devtools/views/DevTools.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export type Props = {|
5454
canViewElementSourceFunction?: ?CanViewElementSource,
5555
defaultTab?: TabID,
5656
enabledInspectedElementContextMenu?: boolean,
57+
enabledInspectedElementContextMenuCopy?: boolean,
5758
showTabBar?: boolean,
5859
store: Store,
5960
warnIfLegacyBackendDetected?: boolean,
@@ -96,6 +97,7 @@ export default function DevTools({
9697
componentsPortalContainer,
9798
defaultTab = 'components',
9899
enabledInspectedElementContextMenu = false,
100+
enabledInspectedElementContextMenuCopy = false,
99101
overrideTab,
100102
profilerPortalContainer,
101103
showTabBar = false,
@@ -121,9 +123,14 @@ export default function DevTools({
121123
const contextMenu = useMemo(
122124
() => ({
123125
isEnabledForInspectedElement: enabledInspectedElementContextMenu,
126+
supportsCopyOperation: enabledInspectedElementContextMenuCopy,
124127
viewAttributeSourceFunction: viewAttributeSourceFunction || null,
125128
}),
126-
[enabledInspectedElementContextMenu, viewAttributeSourceFunction],
129+
[
130+
enabledInspectedElementContextMenu,
131+
enabledInspectedElementContextMenuCopy,
132+
viewAttributeSourceFunction,
133+
],
127134
);
128135

129136
useEffect(

packages/react-devtools-shared/src/devtools/views/context.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ StoreContext.displayName = 'StoreContext';
2323

2424
export type ContextMenuContextType = {|
2525
isEnabledForInspectedElement: boolean,
26+
supportsCopyOperation: boolean,
2627
viewAttributeSourceFunction?: ?ViewAttributeSource,
2728
|};
2829

2930
export const ContextMenuContext = createContext<ContextMenuContextType>({
3031
isEnabledForInspectedElement: false,
32+
supportsCopyOperation: false,
3133
viewAttributeSourceFunction: null,
3234
});
3335
ContextMenuContext.displayName = 'ContextMenuContext';

packages/react-devtools-shell/src/devtools.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ inject('dist/app.js', () => {
5656
createElement(DevTools, {
5757
browserTheme: 'light',
5858
enabledInspectedElementContextMenu: true,
59+
enabledInspectedElementContextMenuCopy: true,
5960
showTabBar: true,
6061
warnIfLegacyBackendDetected: true,
6162
warnIfUnsupportedVersionDetected: true,

0 commit comments

Comments
 (0)