Skip to content

Commit 6579ccf

Browse files
committed
Only add event handlers once
We were previsouly adding multiple event handlers, which led to over-use of CPU and un-responsiveness and other weirdness. I believe this fixes #207
1 parent 9870cbb commit 6579ccf

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

static/menus.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class Menu extends React.Component {
2020
}
2121

2222
didRender() {
23+
console.log("menu didRender")
2324
if (this.items().length == 0) {
2425
this.props.onClose();
2526
return;
@@ -82,6 +83,7 @@ export class MenuHost extends React.Component {
8283
let contextMenu = (ev) => {
8384
this.setState({ menuOpen: { "top": ev.pageY, "left": ev.pageX, target: ev.target }});
8485
ev.preventDefault();
86+
ev.stopPropagation();
8587
};
8688

8789
let onClick = null;

static/rustw.out.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6819,6 +6819,7 @@ var MenuHost = exports.MenuHost = function (_React$Component2) {
68196819
var contextMenu = function contextMenu(ev) {
68206820
_this4.setState({ menuOpen: { "top": ev.pageY, "left": ev.pageX, target: ev.target } });
68216821
ev.preventDefault();
6822+
ev.stopPropagation();
68226823
};
68236824

68246825
var onClick = null;
@@ -6951,6 +6952,7 @@ function FileResult(props) {
69516952
};
69526953
props.app.loadSource(file_name, highlight);
69536954
e.preventDefault();
6955+
e.stopPropagation();
69546956
};
69556957
var snippetClick = function snippetClick(e) {
69566958
var highlight = {
@@ -6961,6 +6963,7 @@ function FileResult(props) {
69616963
};
69626964
props.app.loadSource(file_name, highlight);
69636965
e.preventDefault();
6966+
e.stopPropagation();
69646967
};
69656968

69666969
return _react2.default.createElement(
@@ -6986,6 +6989,7 @@ function FileResult(props) {
69866989
var onClick = function onClick(e) {
69876990
props.app.loadSource(file_name);
69886991
e.preventDefault();
6992+
e.stopPropagation();
69896993
};
69906994
return _react2.default.createElement(
69916995
'div',
@@ -7422,7 +7426,9 @@ function add_ref_functionality(self) {
74227426
var showRefMenu = function showRefMenu(ev) {
74237427
self.setState({ refMenu: { "top": ev.pageY, "left": ev.pageX, target: ev.target, id: id } });
74247428
ev.preventDefault();
7429+
ev.stopPropagation();
74257430
};
7431+
element.off("contextmenu");
74267432
element.on("contextmenu", showRefMenu);
74277433
element.addClass("hand_cursor");
74287434
};
@@ -7539,6 +7545,7 @@ var SourceView = exports.SourceView = function (_React$Component) {
75397545
// The data for what to do on-click is encoded in the data-link attribute.
75407546
// We need to process it here.
75417547
e.preventDefault();
7548+
e.stopPropagation();
75427549

75437550
var docUrl = e.target.dataset.docLink;
75447551
if (docUrl) {

static/rustw.out.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/search.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function FileResult(props) {
6060
};
6161
props.app.loadSource(file_name, highlight);
6262
e.preventDefault();
63+
e.stopPropagation();
6364
};
6465
const snippetClick = (e) => {
6566
const highlight = {
@@ -70,6 +71,7 @@ function FileResult(props) {
7071
};
7172
props.app.loadSource(file_name, highlight);
7273
e.preventDefault();
74+
e.stopPropagation();
7375
};
7476

7577
return <div key={`${kind}-${count}-${l.line_start}`}>
@@ -85,6 +87,7 @@ function FileResult(props) {
8587
const onClick = (e) => {
8688
props.app.loadSource(file_name);
8789
e.preventDefault();
90+
e.stopPropagation();
8891
};
8992
return <div>
9093
<div className="div_search_file_link" onClick={onClick}>{file_name}</div>

static/srcView.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ function add_ref_functionality(self) {
3434
const showRefMenu = (ev) => {
3535
self.setState({ refMenu: { "top": ev.pageY, "left": ev.pageX, target: ev.target, id }});
3636
ev.preventDefault();
37+
ev.stopPropagation();
3738
};
39+
element.off("contextmenu");
3840
element.on("contextmenu", showRefMenu);
3941
element.addClass("hand_cursor");
4042
}
@@ -108,6 +110,7 @@ export class SourceView extends React.Component {
108110
// The data for what to do on-click is encoded in the data-link attribute.
109111
// We need to process it here.
110112
e.preventDefault();
113+
e.stopPropagation();
111114

112115
var docUrl = e.target.dataset.docLink;
113116
if (docUrl) {
@@ -146,7 +149,9 @@ export class SourceView extends React.Component {
146149

147150
let refMenu = null;
148151
if (!!this.state.refMenu) {
149-
const onClose = () => this.setState({ refMenu: null });
152+
const onClose = () => {
153+
return this.setState({ refMenu: null });
154+
};
150155

151156
refMenu = <RefMenu app={this.props.app} location={this.state.refMenu} onClose={onClose} target={this.state.refMenu.target} id={this.state.refMenu.id} />;
152157
}

0 commit comments

Comments
 (0)