summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/components/Editor/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/client/debugger/src/components/Editor/index.js')
-rw-r--r--devtools/client/debugger/src/components/Editor/index.js145
1 files changed, 114 insertions, 31 deletions
diff --git a/devtools/client/debugger/src/components/Editor/index.js b/devtools/client/debugger/src/components/Editor/index.js
index ae9bde7657..e21e05c11a 100644
--- a/devtools/client/debugger/src/components/Editor/index.js
+++ b/devtools/client/debugger/src/components/Editor/index.js
@@ -12,6 +12,7 @@ import { connect } from "devtools/client/shared/vendor/react-redux";
import { getLineText, isLineBlackboxed } from "./../../utils/source";
import { createLocation } from "./../../utils/location";
import { getIndentation } from "../../utils/indentation";
+import { isWasm } from "../../utils/wasm";
import { features } from "../../utils/prefs";
import {
@@ -50,6 +51,7 @@ import Exceptions from "./Exceptions";
import BlackboxLines from "./BlackboxLines";
import {
+ fromEditorLine,
showSourceText,
setDocument,
resetLineNumberFormat,
@@ -68,7 +70,11 @@ import {
endOperation,
} from "../../utils/editor/index";
-import { resizeToggleButton, resizeBreakpointGutter } from "../../utils/ui";
+import {
+ resizeToggleButton,
+ getLineNumberWidth,
+ resizeBreakpointGutter,
+} from "../../utils/ui";
const { debounce } = require("resource://devtools/shared/debounce.js");
const classnames = require("resource://devtools/client/shared/classnames.js");
@@ -169,7 +175,7 @@ class Editor extends PureComponent {
if (this.props.selectedSource != nextProps.selectedSource) {
this.props.updateViewport();
resizeBreakpointGutter(editor.codeMirror);
- resizeToggleButton(editor.codeMirror);
+ resizeToggleButton(getLineNumberWidth(editor.codeMirror));
}
} else {
// For codemirror 6
@@ -180,6 +186,12 @@ class Editor extends PureComponent {
}
}
+ onEditorUpdated(v) {
+ if (v.docChanged || v.geometryChanged) {
+ resizeToggleButton(v.view.dom.querySelector(".cm-gutters").clientWidth);
+ }
+ }
+
setupEditor() {
const editor = getEditor(features.codemirrorNext);
@@ -216,32 +228,18 @@ class Editor extends PureComponent {
codeMirrorWrapper.addEventListener("keydown", e => this.onKeyDown(e));
codeMirrorWrapper.addEventListener("click", e => this.onClick(e));
codeMirrorWrapper.addEventListener("mouseover", onMouseOver(codeMirror));
-
- const toggleFoldMarkerVisibility = () => {
- if (node instanceof HTMLElement) {
- node
- .querySelectorAll(".CodeMirror-guttermarker-subtle")
- .forEach(elem => {
- elem.classList.toggle("visible");
- });
- }
- };
-
- const codeMirrorGutter = codeMirror.getGutterElement();
- codeMirrorGutter.addEventListener(
- "mouseleave",
- toggleFoldMarkerVisibility
- );
- codeMirrorGutter.addEventListener(
- "mouseenter",
- toggleFoldMarkerVisibility
- );
codeMirrorWrapper.addEventListener("contextmenu", event =>
this.openMenu(event)
);
codeMirror.on("scroll", this.onEditorScroll);
this.onEditorScroll();
+ } else {
+ editor.setUpdateListener(this.onEditorUpdated);
+ editor.setGutterEventListeners({
+ click: (event, cm, line) => this.onGutterClick(cm, line, null, event),
+ contextmenu: (event, cm, line) => this.openMenu(event, line, true),
+ });
}
this.setState({ editor });
return editor;
@@ -280,6 +278,69 @@ class Editor extends PureComponent {
}
};
+ componentDidUpdate(prevProps) {
+ const {
+ selectedSource,
+ blackboxedRanges,
+ isSourceOnIgnoreList,
+ breakableLines,
+ } = this.props;
+ const { editor } = this.state;
+
+ if (!selectedSource || !editor) {
+ return;
+ }
+
+ // Sets the breakables lines for codemirror 6
+ if (features.codemirrorNext) {
+ const shouldUpdateBreakableLines =
+ prevProps.breakableLines.size !== this.props.breakableLines.size ||
+ prevProps.selectedSource?.id !== selectedSource.id;
+
+ const isSourceWasm = isWasm(selectedSource.id);
+
+ if (shouldUpdateBreakableLines) {
+ editor.setLineGutterMarkers([
+ {
+ id: "empty-line-marker",
+ lineClassName: "empty-line",
+ condition: line => {
+ const lineNumber = fromEditorLine(
+ selectedSource.id,
+ line,
+ isSourceWasm
+ );
+ return !breakableLines.has(lineNumber);
+ },
+ },
+ ]);
+ }
+
+ function condition(line) {
+ const lineNumber = fromEditorLine(selectedSource.id, line);
+
+ return isLineBlackboxed(
+ blackboxedRanges[selectedSource.url],
+ lineNumber,
+ isSourceOnIgnoreList
+ );
+ }
+
+ editor.setLineGutterMarkers([
+ {
+ id: "blackboxed-line-gutter-marker",
+ lineClassName: "blackboxed-line",
+ condition,
+ },
+ ]);
+ editor.setLineContentMarker({
+ id: "blackboxed-line-marker",
+ lineClassName: "blackboxed-line",
+ condition,
+ });
+ }
+ }
+
componentWillUnmount() {
if (!features.codemirrorNext) {
const { editor } = this.state;
@@ -396,8 +457,9 @@ class Editor extends PureComponent {
e.preventDefault();
}
};
-
- openMenu(event) {
+ // Note: The line is optional, if not passed (as is likely for codemirror 6)
+ // it fallsback to lineAtHeight.
+ openMenu(event, line) {
event.stopPropagation();
event.preventDefault();
@@ -421,13 +483,19 @@ class Editor extends PureComponent {
const target = event.target;
const { id: sourceId } = selectedSource;
- const line = lineAtHeight(editor, sourceId, event);
+ line = line ?? lineAtHeight(editor, sourceId, event);
if (typeof line != "number") {
return;
}
- if (target.classList.contains("CodeMirror-linenumber")) {
+ if (
+ // handles codemirror 6
+ (target.classList.contains("cm-gutterElement") &&
+ target.closest(".cm-gutter.cm-lineNumbers")) ||
+ // handles codemirror 5
+ target.classList.contains("CodeMirror-linenumber")
+ ) {
const location = createLocation({
line,
column: undefined,
@@ -440,7 +508,14 @@ class Editor extends PureComponent {
line
).trim();
- this.props.showEditorGutterContextMenu(event, editor, location, lineText);
+ const lineObject = { from: { line }, to: { line } };
+
+ this.props.showEditorGutterContextMenu(
+ event,
+ lineObject,
+ location,
+ lineText
+ );
return;
}
@@ -542,10 +617,6 @@ class Editor extends PureComponent {
);
};
- onGutterContextMenu = event => {
- this.openMenu(event);
- };
-
onClick(e) {
const { selectedSource, updateCursorPosition, jumpToMappedLocation } =
this.props;
@@ -717,6 +788,18 @@ class Editor extends PureComponent {
} = this.props;
const { editor } = this.state;
+ if (features.codemirrorNext) {
+ return React.createElement(
+ React.Fragment,
+ null,
+ React.createElement(Breakpoints, {
+ editor,
+ }),
+ React.createElement(DebugLine, { editor, selectedSource }),
+ React.createElement(Exceptions, { editor })
+ );
+ }
+
if (!selectedSource || !editor || !getDocument(selectedSource.id)) {
return null;
}