/* 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/>. */
import PropTypes from "devtools/client/shared/vendor/react-prop-types"; import React, { PureComponent } from "devtools/client/shared/vendor/react"; import { div } from "devtools/client/shared/vendor/react-dom-factories"; import { bindActionCreators } from "devtools/client/shared/vendor/redux"; import ReactDOM from "devtools/client/shared/vendor/react-dom"; 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 { features } from "../../utils/prefs"; import { markerTypes } from "../../constants"; import { asSettled, isFulfilled, isRejected } from "../../utils/async-value";
// Redux actions import actions from "../../actions/index";
import SearchInFileBar from "./SearchInFileBar"; import HighlightLines from "./HighlightLines"; import Preview from "./Preview/index"; import Breakpoints from "./Breakpoints"; import ColumnBreakpoints from "./ColumnBreakpoints"; import DebugLine from "./DebugLine"; import HighlightLine from "./HighlightLine"; import EmptyLines from "./EmptyLines"; import ConditionalPanel from "./ConditionalPanel"; import InlinePreviews from "./InlinePreviews"; import Exceptions from "./Exceptions"; import BlackboxLines from "./BlackboxLines";
async setTextContent(nextProps, editor, prevEditor) { const shouldUpdateText =
nextProps.selectedSource !== this.props.selectedSource ||
nextProps.selectedSourceTextContent?.value !== this.props.selectedSourceTextContent?.value || // If the selectedSource gets set before the editor get selected, make sure we update the text
prevEditor !== editor;
if (!features.codemirrorNext) { const { codeMirror } = editor;
this.abortController = new window.AbortController();
// CodeMirror refreshes its internal state on window resize, but we need to also // refresh it when the side panels are resized. // We could have a ResizeObserver instead, but we wouldn't be able to differentiate // between window resize and side panel resize and as a result, might refresh // codeMirror twice, which is wasteful.
window.document
.querySelector(".editor-pane")
.addEventListener("resizeend", () => codeMirror.refresh(), {
signal: this.abortController.signal,
});
// Sets the breakables lines for codemirror 6 if (features.codemirrorNext) { const shouldUpdateBreakableLines =
prevProps.breakableLines.size !== this.props.breakableLines.size ||
prevProps.selectedSource?.id !== selectedSource.id || // Make sure we update after the editor has loaded
(!prevState.editor && !!editor);
const lines = []; for (const range of blackboxedRanges[selectedSource.url]) { for (let line = range.start.line; line <= range.end.line; line++) {
lines.push({ line });
}
}
editor.setLineContentMarker({
id: markerTypes.BLACKBOX_LINE_MARKER,
lineClassName: "blackboxed-line", // If the the whole source is blackboxed, lets just mark all positions.
shouldMarkAllLines: !blackboxedRanges[selectedSource.url].length,
lines,
});
}
}
}
if (this.abortController) { this.abortController.abort(); this.abortController = null;
}
if (editor) { if (!features.codemirrorNext) {
editor.codeMirror.off("scroll", this.onEditorScroll);
}
editor.destroy(); this.setState({ editor: null });
}
}
getCurrentPosition() { const { editor } = this.state; const { selectedLocation } = this.props; if (!selectedLocation) { returnnull;
}
let { line, column } = selectedLocation; // When no specific line has been selected, fallback to the current cursor posiiton if (line == 0) { const selectionCursor = editor.getSelectionCursor();
line = toSourceLine(selectedLocation.source, selectionCursor.from.line);
column = selectionCursor.from.ch + 1;
} return { line, column };
}
onToggleBreakpoint = e => {
e.preventDefault();
e.stopPropagation();
/* * The default Esc command is overridden in the CodeMirror keymap to allow * the Esc keypress event to be catched by the toolbox and trigger the * split console. Restore it here, but preventDefault if and only if there * is a multiselection.
*/
onEscape = e => { if (!this.state.editor) { return;
}
if (!features.codemirrorNext) { const { codeMirror } = this.state.editor; if (codeMirror.listSelections().length > 1) {
codeMirror.execCommand("singleSelection");
e.preventDefault();
}
}
}; // Note: The line is optional, if not passed it fallsback to lineAtHeight.
openMenu(event, line, ch) {
event.stopPropagation();
event.preventDefault();
// check if we previously had a selected source if (!selectedSource) { if (!features.codemirrorNext) { this.clearEditor();
} return;
}
if (!selectedSourceTextContent?.value) { this.showLoadingMessage(editor); return;
}
if (isRejected(selectedSourceTextContent)) {
let { value } = selectedSourceTextContent; if (typeof value !== "string") {
value = "Unexpected source error";
}
let error; if (msg.includes("WebAssembly binary source is not available")) {
error = L10N.getStr("wasmIsNotAvailable");
} else {
error = L10N.getFormatStr("errorLoadingText3", msg);
} if (!features.codemirrorNext) { const doc = editor.createDocument(error, { name: "text" });
editor.replaceDocument(doc);
resetLineNumberFormat(editor);
} else {
editor.setText(error);
}
}
showLoadingMessage(editor) { if (!features.codemirrorNext) { // Create the "loading message" document only once
let doc = getDocument("loading"); if (!doc) {
doc = editor.createDocument(L10N.getStr("loadingText"), {
name: "text",
});
setDocument("loading", doc);
} // `createDocument` won't be used right away in the editor, we still need to // explicitely update it
editor.replaceDocument(doc);
} else {
editor.setText(L10N.getStr("loadingText"));
}
}
if (features.codemirrorNext) { // Only load the sub components if the content has loaded without issues. if (
selectedSourceTextContent &&
!isFulfilled(selectedSourceTextContent)
) { returnnull;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.