Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit a23f3e6

Browse files
committed
Merge pull request #116 from facebook/chrome-hide-highlight
[chrome] hide highlight when switching devtools tab
2 parents 32ff902 + cbbd856 commit a23f3e6

4 files changed

Lines changed: 27 additions & 5 deletions

File tree

frontend/Panel.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ class Panel extends React.Component {
9898
this.props.getNewSelection(this._bridge);
9999
}
100100

101+
hideHighlight() {
102+
this._store.hideHighlight();
103+
}
104+
101105
sendSelection(id: string) {
102106
if (!this._bridge || (!id && !this._store.selected)) {
103107
return;

frontend/Store.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,21 @@ class Store extends EventEmitter {
288288
this.emit('hover');
289289
this._bridge.send('highlight', id);
290290
} else if (this.hovered === id) {
291-
this.hovered = null;
292-
this.emit(id);
293-
this.emit('hover');
294-
this._bridge.send('hideHighlight');
291+
this.hideHighlight();
295292
}
296293
}
297294

295+
hideHighlight() {
296+
this._bridge.send('hideHighlight');
297+
if (!this.hovered) {
298+
return;
299+
}
300+
var id = this.hovered;
301+
this.hovered = null;
302+
this.emit(id);
303+
this.emit('hover');
304+
}
305+
298306
selectTop(id: ?ElementID, noHighlight?: boolean) {
299307
this.isBottomTagSelected = false;
300308
this.select(id, noHighlight);

shells/chrome/src/GlobalHook.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var checkForOld = `
2020
if (window.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
2121
console.error("REACT DEVTOOLS ERROR\\nYou need to disable the official version of React Devtools in order to use the beta.");
2222
}
23-
`
23+
`;
2424

2525
var js = (
2626
';(' + globalHook.toString() + '(window))'

shells/chrome/src/main.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
'use strict';
1212

1313
type Panel = { // eslint-disable-line no-unused-vars
14+
onHidden: {
15+
addListener: (cb: (window: Object) => void) => void,
16+
},
1417
onShown: {
1518
addListener: (cb: (window: Object) => void) => void,
1619
}
@@ -35,10 +38,17 @@ chrome.devtools.inspectedWindow.eval(`!!(
3538
}
3639

3740
chrome.devtools.panels.create('React', '', 'panel.html', function (panel) {
41+
var reactPanel = null;
3842
panel.onShown.addListener(function (window) {
3943
// when the user switches to the panel, check for an elements tab
4044
// selection
4145
window.panel.getNewSelection();
46+
reactPanel = window.panel;
47+
});
48+
panel.onHidden.addListener(function () {
49+
if (reactPanel) {
50+
reactPanel.hideHighlight();
51+
}
4252
});
4353
});
4454
});

0 commit comments

Comments
 (0)