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
100 lines (85 loc) · 2.36 KB
/
Copy pathEditorMenu.js
File metadata and controls
100 lines (85 loc) · 2.36 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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// @flow
import { Component } from "react";
import { connect } from "../../utils/connect";
import { showMenu } from "devtools-contextmenu";
import { getSourceLocationFromMouseEvent } from "../../utils/editor";
import {
getPrettySource,
getIsPaused,
getCurrentThread,
getThreadContext
} from "../../selectors";
import { editorMenuItems, editorItemActions } from "./menus/editor";
import type { SourceWithContent, ThreadContext } from "../../types";
import type { EditorItemActions } from "./menus/editor";
import type SourceEditor from "../../utils/editor/source-editor";
type Props = {
cx: ThreadContext,
contextMenu: ?MouseEvent,
editorActions: EditorItemActions,
clearContextMenu: () => void,
editor: SourceEditor,
hasPrettySource: boolean,
isPaused: boolean,
selectedSourceWithContent: SourceWithContent
};
class EditorMenu extends Component<Props> {
props: Props;
componentWillUpdate(nextProps: Props) {
this.props.clearContextMenu();
if (nextProps.contextMenu) {
this.showMenu(nextProps);
}
}
showMenu(props) {
const {
cx,
editor,
selectedSourceWithContent,
editorActions,
hasPrettySource,
isPaused,
contextMenu: event
} = props;
const location = getSourceLocationFromMouseEvent(
editor,
selectedSourceWithContent.source,
// Use a coercion, as contextMenu is optional
(event: any)
);
showMenu(
event,
editorMenuItems({
cx,
editorActions,
selectedSourceWithContent,
hasPrettySource,
location,
isPaused,
selectionText: editor.codeMirror.getSelection().trim(),
isTextSelected: editor.codeMirror.somethingSelected()
})
);
}
render() {
return null;
}
}
const mapStateToProps = (state, props) => ({
cx: getThreadContext(state),
isPaused: getIsPaused(state, getCurrentThread(state)),
hasPrettySource: !!getPrettySource(
state,
props.selectedSourceWithContent.source.id
)
});
const mapDispatchToProps = dispatch => ({
editorActions: editorItemActions(dispatch)
});
export default connect(
mapStateToProps,
mapDispatchToProps
)(EditorMenu);