summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/utils/editor
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/client/debugger/src/utils/editor')
-rw-r--r--devtools/client/debugger/src/utils/editor/create-editor.js5
-rw-r--r--devtools/client/debugger/src/utils/editor/index.js14
-rw-r--r--devtools/client/debugger/src/utils/editor/source-documents.js55
-rw-r--r--devtools/client/debugger/src/utils/editor/source-search.js22
-rw-r--r--devtools/client/debugger/src/utils/editor/tests/__snapshots__/create-editor.spec.js.snapbin3275 -> 3327 bytes
5 files changed, 27 insertions, 69 deletions
diff --git a/devtools/client/debugger/src/utils/editor/create-editor.js b/devtools/client/debugger/src/utils/editor/create-editor.js
index 6bb280fc4d..74b41ff78b 100644
--- a/devtools/client/debugger/src/utils/editor/create-editor.js
+++ b/devtools/client/debugger/src/utils/editor/create-editor.js
@@ -5,7 +5,7 @@
import SourceEditor from "devtools/client/shared/sourceeditor/editor";
import { features, prefs } from "../prefs";
-export function createEditor() {
+export function createEditor(useCm6 = false) {
const gutters = ["breakpoints", "hit-markers", "CodeMirror-linenumbers"];
if (features.codeFolding) {
@@ -13,7 +13,8 @@ export function createEditor() {
}
return new SourceEditor({
- mode: "javascript",
+ mode: SourceEditor.modes.js,
+ cm6: useCm6,
foldGutter: features.codeFolding,
enableCodeFolding: features.codeFolding,
readOnly: true,
diff --git a/devtools/client/debugger/src/utils/editor/index.js b/devtools/client/debugger/src/utils/editor/index.js
index 1adc73b4f8..d12e2f29f1 100644
--- a/devtools/client/debugger/src/utils/editor/index.js
+++ b/devtools/client/debugger/src/utils/editor/index.js
@@ -14,12 +14,12 @@ import { createLocation } from "../location";
let editor;
-export function getEditor() {
+export function getEditor(useCm6) {
if (editor) {
return editor;
}
- editor = createEditor();
+ editor = createEditor(useCm6);
return editor;
}
@@ -27,6 +27,16 @@ export function removeEditor() {
editor = null;
}
+/**
+ * Update line wrapping for the codemirror editor.
+ */
+export function updateEditorLineWrapping(value) {
+ if (!editor) {
+ return;
+ }
+ editor.setLineWrapping(value);
+}
+
function getCodeMirror() {
return editor && editor.hasCodeMirror ? editor.codeMirror : null;
}
diff --git a/devtools/client/debugger/src/utils/editor/source-documents.js b/devtools/client/debugger/src/utils/editor/source-documents.js
index 2ddb0b1965..53ee4f2f35 100644
--- a/devtools/client/debugger/src/utils/editor/source-documents.js
+++ b/devtools/client/debugger/src/utils/editor/source-documents.js
@@ -35,7 +35,7 @@ export function clearDocumentsForSources(sources) {
}
}
-function resetLineNumberFormat(editor) {
+export function resetLineNumberFormat(editor) {
const cm = editor.codeMirror;
cm.setOption("lineNumberFormatter", number => number);
resizeBreakpointGutter(cm);
@@ -54,59 +54,6 @@ function updateLineNumberFormat(editor, sourceId) {
resizeToggleButton(cm);
}
-export function updateDocument(editor, source) {
- if (!source) {
- return;
- }
-
- const sourceId = source.id;
- const doc = getDocument(sourceId) || editor.createDocument();
- editor.replaceDocument(doc);
-
- updateLineNumberFormat(editor, sourceId);
-}
-
-/* used to apply the context menu wrap line option change to all the docs */
-export function updateDocuments(updater) {
- for (const doc of sourceDocs.values()) {
- if (doc.cm == null) {
- continue;
- } else {
- updater(doc);
- }
- }
-}
-
-export function clearEditor(editor) {
- const doc = editor.createDocument("", { name: "text" });
- editor.replaceDocument(doc);
- resetLineNumberFormat(editor);
-}
-
-export function showLoading(editor) {
- // 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);
-}
-
-export function showErrorMessage(editor, msg) {
- let error;
- if (msg.includes("WebAssembly binary source is not available")) {
- error = L10N.getStr("wasmIsNotAvailable");
- } else {
- error = L10N.getFormatStr("errorLoadingText3", msg);
- }
- const doc = editor.createDocument(error, { name: "text" });
- editor.replaceDocument(doc);
- resetLineNumberFormat(editor);
-}
-
const contentTypeModeMap = new Map([
["text/javascript", { name: "javascript" }],
["text/typescript", { name: "javascript", typescript: true }],
diff --git a/devtools/client/debugger/src/utils/editor/source-search.js b/devtools/client/debugger/src/utils/editor/source-search.js
index 92097377ba..2316cd2ccb 100644
--- a/devtools/client/debugger/src/utils/editor/source-search.js
+++ b/devtools/client/debugger/src/utils/editor/source-search.js
@@ -27,7 +27,7 @@ function SearchState() {
* @memberof utils/source-search
* @static
*/
-function getSearchState(cm, query) {
+function getSearchState(cm) {
const state = cm.state.search || (cm.state.search = new SearchState());
return state;
}
@@ -55,7 +55,7 @@ function searchOverlay(query, modifiers) {
});
return {
- token: function (stream, state) {
+ token(stream) {
// set the last index to be the current stream position
// this acts as an offset
regexQuery.lastIndex = stream.pos;
@@ -141,11 +141,11 @@ function doSearch(
return cm.operation(function () {
if (!query || isWhitespace(query)) {
- clearSearch(cm, query);
+ clearSearch(cm);
return null;
}
- const state = getSearchState(cm, query);
+ const state = getSearchState(cm);
const isNewQuery = state.query !== query;
state.query = query;
@@ -179,7 +179,7 @@ export function searchSourceForHighlight(
}
cm.operation(function () {
- const state = getSearchState(cm, query);
+ const state = getSearchState(cm);
const isNewQuery = state.query !== query;
state.query = query;
@@ -207,7 +207,7 @@ function searchNext(ctx, rev, query, newQuery, modifiers) {
const { cm } = ctx;
let nextMatch;
cm.operation(function () {
- const state = getSearchState(cm, query);
+ const state = getSearchState(cm);
const pos = getCursorPos(newQuery, rev, state);
if (!state.query) {
@@ -261,8 +261,8 @@ function findNextOnLine(ctx, rev, query, newQuery, modifiers, line, ch) {
* @memberof utils/source-search
* @static
*/
-export function removeOverlay(ctx, query) {
- const state = getSearchState(ctx.cm, query);
+export function removeOverlay(ctx) {
+ const state = getSearchState(ctx.cm);
ctx.cm.removeOverlay(state.overlay);
const { line, ch } = ctx.cm.getCursor();
ctx.cm.doc.setSelection({ line, ch }, { line, ch }, { scroll: false });
@@ -274,8 +274,8 @@ export function removeOverlay(ctx, query) {
* @memberof utils/source-search
* @static
*/
-export function clearSearch(cm, query) {
- const state = getSearchState(cm, query);
+export function clearSearch(cm) {
+ const state = getSearchState(cm);
state.results = [];
@@ -293,7 +293,7 @@ export function clearSearch(cm, query) {
* @static
*/
export function find(ctx, query, keepSelection, modifiers, focusFirstResult) {
- clearSearch(ctx.cm, query);
+ clearSearch(ctx.cm);
return doSearch(
ctx,
false,
diff --git a/devtools/client/debugger/src/utils/editor/tests/__snapshots__/create-editor.spec.js.snap b/devtools/client/debugger/src/utils/editor/tests/__snapshots__/create-editor.spec.js.snap
index 843647731b..5c47ed94c7 100644
--- a/devtools/client/debugger/src/utils/editor/tests/__snapshots__/create-editor.spec.js.snap
+++ b/devtools/client/debugger/src/utils/editor/tests/__snapshots__/create-editor.spec.js.snap
Binary files differ