forked from mirrors/gecko-dev
Differential Revision: https://phabricator.services.mozilla.com/D19641 --HG-- rename : devtools/client/sourceeditor/.eslintrc.js => devtools/client/shared/sourceeditor/.eslintrc.js rename : devtools/client/sourceeditor/README => devtools/client/shared/sourceeditor/README rename : devtools/client/sourceeditor/autocomplete.js => devtools/client/shared/sourceeditor/autocomplete.js rename : devtools/client/sourceeditor/codemirror/LICENSE => devtools/client/shared/sourceeditor/codemirror/LICENSE rename : devtools/client/sourceeditor/codemirror/addon/comment/comment.js => devtools/client/shared/sourceeditor/codemirror/addon/comment/comment.js rename : devtools/client/sourceeditor/codemirror/addon/comment/continuecomment.js => devtools/client/shared/sourceeditor/codemirror/addon/comment/continuecomment.js rename : devtools/client/sourceeditor/codemirror/addon/dialog/dialog.css => devtools/client/shared/sourceeditor/codemirror/addon/dialog/dialog.css rename : devtools/client/sourceeditor/codemirror/addon/dialog/dialog.js => devtools/client/shared/sourceeditor/codemirror/addon/dialog/dialog.js rename : devtools/client/sourceeditor/codemirror/addon/edit/closebrackets.js => devtools/client/shared/sourceeditor/codemirror/addon/edit/closebrackets.js rename : devtools/client/sourceeditor/codemirror/addon/edit/closetag.js => devtools/client/shared/sourceeditor/codemirror/addon/edit/closetag.js rename : devtools/client/sourceeditor/codemirror/addon/edit/continuelist.js => devtools/client/shared/sourceeditor/codemirror/addon/edit/continuelist.js rename : devtools/client/sourceeditor/codemirror/addon/edit/matchbrackets.js => devtools/client/shared/sourceeditor/codemirror/addon/edit/matchbrackets.js rename : devtools/client/sourceeditor/codemirror/addon/edit/matchtags.js => devtools/client/shared/sourceeditor/codemirror/addon/edit/matchtags.js rename : devtools/client/sourceeditor/codemirror/addon/edit/trailingspace.js => devtools/client/shared/sourceeditor/codemirror/addon/edit/trailingspace.js rename : devtools/client/sourceeditor/codemirror/addon/fold/brace-fold.js => devtools/client/shared/sourceeditor/codemirror/addon/fold/brace-fold.js rename : devtools/client/sourceeditor/codemirror/addon/fold/comment-fold.js => devtools/client/shared/sourceeditor/codemirror/addon/fold/comment-fold.js rename : devtools/client/sourceeditor/codemirror/addon/fold/foldcode.js => devtools/client/shared/sourceeditor/codemirror/addon/fold/foldcode.js rename : devtools/client/sourceeditor/codemirror/addon/fold/foldgutter.css => devtools/client/shared/sourceeditor/codemirror/addon/fold/foldgutter.css rename : devtools/client/sourceeditor/codemirror/addon/fold/foldgutter.js => devtools/client/shared/sourceeditor/codemirror/addon/fold/foldgutter.js rename : devtools/client/sourceeditor/codemirror/addon/fold/indent-fold.js => devtools/client/shared/sourceeditor/codemirror/addon/fold/indent-fold.js rename : devtools/client/sourceeditor/codemirror/addon/fold/markdown-fold.js => devtools/client/shared/sourceeditor/codemirror/addon/fold/markdown-fold.js rename : devtools/client/sourceeditor/codemirror/addon/fold/xml-fold.js => devtools/client/shared/sourceeditor/codemirror/addon/fold/xml-fold.js rename : devtools/client/sourceeditor/codemirror/addon/hint/show-hint.js => devtools/client/shared/sourceeditor/codemirror/addon/hint/show-hint.js rename : devtools/client/sourceeditor/codemirror/addon/runmode/runmode.js => devtools/client/shared/sourceeditor/codemirror/addon/runmode/runmode.js rename : devtools/client/sourceeditor/codemirror/addon/search/match-highlighter.js => devtools/client/shared/sourceeditor/codemirror/addon/search/match-highlighter.js rename : devtools/client/sourceeditor/codemirror/addon/search/search.js => devtools/client/shared/sourceeditor/codemirror/addon/search/search.js rename : devtools/client/sourceeditor/codemirror/addon/search/searchcursor.js => devtools/client/shared/sourceeditor/codemirror/addon/search/searchcursor.js rename : devtools/client/sourceeditor/codemirror/addon/selection/active-line.js => devtools/client/shared/sourceeditor/codemirror/addon/selection/active-line.js rename : devtools/client/sourceeditor/codemirror/addon/selection/mark-selection.js => devtools/client/shared/sourceeditor/codemirror/addon/selection/mark-selection.js rename : devtools/client/sourceeditor/codemirror/addon/tern/tern.css => devtools/client/shared/sourceeditor/codemirror/addon/tern/tern.css rename : devtools/client/sourceeditor/codemirror/addon/tern/tern.js => devtools/client/shared/sourceeditor/codemirror/addon/tern/tern.js rename : devtools/client/sourceeditor/codemirror/cmiframe.html => devtools/client/shared/sourceeditor/codemirror/cmiframe.html rename : devtools/client/sourceeditor/codemirror/codemirror.bundle.js => devtools/client/shared/sourceeditor/codemirror/codemirror.bundle.js rename : devtools/client/sourceeditor/codemirror/keymap/emacs.js => devtools/client/shared/sourceeditor/codemirror/keymap/emacs.js rename : devtools/client/sourceeditor/codemirror/keymap/sublime.js => devtools/client/shared/sourceeditor/codemirror/keymap/sublime.js rename : devtools/client/sourceeditor/codemirror/keymap/vim.js => devtools/client/shared/sourceeditor/codemirror/keymap/vim.js rename : devtools/client/sourceeditor/codemirror/lib/codemirror.css => devtools/client/shared/sourceeditor/codemirror/lib/codemirror.css rename : devtools/client/sourceeditor/codemirror/lib/codemirror.js => devtools/client/shared/sourceeditor/codemirror/lib/codemirror.js rename : devtools/client/sourceeditor/codemirror/mode/clike/clike.js => devtools/client/shared/sourceeditor/codemirror/mode/clike/clike.js rename : devtools/client/sourceeditor/codemirror/mode/clojure/clojure.js => devtools/client/shared/sourceeditor/codemirror/mode/clojure/clojure.js rename : devtools/client/sourceeditor/codemirror/mode/coffeescript/coffeescript.js => devtools/client/shared/sourceeditor/codemirror/mode/coffeescript/coffeescript.js rename : devtools/client/sourceeditor/codemirror/mode/css/css.js => devtools/client/shared/sourceeditor/codemirror/mode/css/css.js rename : devtools/client/sourceeditor/codemirror/mode/elm/elm.js => devtools/client/shared/sourceeditor/codemirror/mode/elm/elm.js rename : devtools/client/sourceeditor/codemirror/mode/haxe/haxe.js => devtools/client/shared/sourceeditor/codemirror/mode/haxe/haxe.js rename : devtools/client/sourceeditor/codemirror/mode/htmlmixed/htmlmixed.js => devtools/client/shared/sourceeditor/codemirror/mode/htmlmixed/htmlmixed.js rename : devtools/client/sourceeditor/codemirror/mode/javascript/javascript.js => devtools/client/shared/sourceeditor/codemirror/mode/javascript/javascript.js rename : devtools/client/sourceeditor/codemirror/mode/jsx/jsx.js => devtools/client/shared/sourceeditor/codemirror/mode/jsx/jsx.js rename : devtools/client/sourceeditor/codemirror/mode/wasm/wasm.js => devtools/client/shared/sourceeditor/codemirror/mode/wasm/wasm.js rename : devtools/client/sourceeditor/codemirror/mode/xml/xml.js => devtools/client/shared/sourceeditor/codemirror/mode/xml/xml.js rename : devtools/client/sourceeditor/codemirror/mozilla.css => devtools/client/shared/sourceeditor/codemirror/mozilla.css rename : devtools/client/sourceeditor/css-autocompleter.js => devtools/client/shared/sourceeditor/css-autocompleter.js rename : devtools/client/sourceeditor/debugger.js => devtools/client/shared/sourceeditor/debugger.js rename : devtools/client/sourceeditor/editor-commands-controller.js => devtools/client/shared/sourceeditor/editor-commands-controller.js rename : devtools/client/sourceeditor/editor.js => devtools/client/shared/sourceeditor/editor.js rename : devtools/client/sourceeditor/moz.build => devtools/client/shared/sourceeditor/moz.build rename : devtools/client/sourceeditor/package.json => devtools/client/shared/sourceeditor/package.json rename : devtools/client/sourceeditor/tern/README => devtools/client/shared/sourceeditor/tern/README rename : devtools/client/sourceeditor/tern/browser.js => devtools/client/shared/sourceeditor/tern/browser.js rename : devtools/client/sourceeditor/tern/comment.js => devtools/client/shared/sourceeditor/tern/comment.js rename : devtools/client/sourceeditor/tern/condense.js => devtools/client/shared/sourceeditor/tern/condense.js rename : devtools/client/sourceeditor/tern/def.js => devtools/client/shared/sourceeditor/tern/def.js rename : devtools/client/sourceeditor/tern/ecma5.js => devtools/client/shared/sourceeditor/tern/ecma5.js rename : devtools/client/sourceeditor/tern/infer.js => devtools/client/shared/sourceeditor/tern/infer.js rename : devtools/client/sourceeditor/tern/moz.build => devtools/client/shared/sourceeditor/tern/moz.build rename : devtools/client/sourceeditor/tern/signal.js => devtools/client/shared/sourceeditor/tern/signal.js rename : devtools/client/sourceeditor/tern/tern.js => devtools/client/shared/sourceeditor/tern/tern.js rename : devtools/client/sourceeditor/tern/tests/unit/head_tern.js => devtools/client/shared/sourceeditor/tern/tests/unit/head_tern.js rename : devtools/client/sourceeditor/tern/tests/unit/test_autocompletion.js => devtools/client/shared/sourceeditor/tern/tests/unit/test_autocompletion.js rename : devtools/client/sourceeditor/tern/tests/unit/test_import_tern.js => devtools/client/shared/sourceeditor/tern/tests/unit/test_import_tern.js rename : devtools/client/sourceeditor/tern/tests/unit/xpcshell.ini => devtools/client/shared/sourceeditor/tern/tests/unit/xpcshell.ini rename : devtools/client/sourceeditor/test/.eslintrc.js => devtools/client/shared/sourceeditor/test/.eslintrc.js rename : devtools/client/sourceeditor/test/browser.ini => devtools/client/shared/sourceeditor/test/browser.ini rename : devtools/client/sourceeditor/test/browser_codemirror.js => devtools/client/shared/sourceeditor/test/browser_codemirror.js rename : devtools/client/sourceeditor/test/browser_css_autocompletion.js => devtools/client/shared/sourceeditor/test/browser_css_autocompletion.js rename : devtools/client/sourceeditor/test/browser_css_getInfo.js => devtools/client/shared/sourceeditor/test/browser_css_getInfo.js rename : devtools/client/sourceeditor/test/browser_css_statemachine.js => devtools/client/shared/sourceeditor/test/browser_css_statemachine.js rename : devtools/client/sourceeditor/test/browser_detectindent.js => devtools/client/shared/sourceeditor/test/browser_detectindent.js rename : devtools/client/sourceeditor/test/browser_editor_addons.js => devtools/client/shared/sourceeditor/test/browser_editor_addons.js rename : devtools/client/sourceeditor/test/browser_editor_alt_b_f.js => devtools/client/shared/sourceeditor/test/browser_editor_alt_b_f.js rename : devtools/client/sourceeditor/test/browser_editor_autocomplete_basic.js => devtools/client/shared/sourceeditor/test/browser_editor_autocomplete_basic.js rename : devtools/client/sourceeditor/test/browser_editor_autocomplete_events.js => devtools/client/shared/sourceeditor/test/browser_editor_autocomplete_events.js rename : devtools/client/sourceeditor/test/browser_editor_autocomplete_js.js => devtools/client/shared/sourceeditor/test/browser_editor_autocomplete_js.js rename : devtools/client/sourceeditor/test/browser_editor_basic.js => devtools/client/shared/sourceeditor/test/browser_editor_basic.js rename : devtools/client/sourceeditor/test/browser_editor_cursor.js => devtools/client/shared/sourceeditor/test/browser_editor_cursor.js rename : devtools/client/sourceeditor/test/browser_editor_find_again.js => devtools/client/shared/sourceeditor/test/browser_editor_find_again.js rename : devtools/client/sourceeditor/test/browser_editor_goto_line.js => devtools/client/shared/sourceeditor/test/browser_editor_goto_line.js rename : devtools/client/sourceeditor/test/browser_editor_history.js => devtools/client/shared/sourceeditor/test/browser_editor_history.js rename : devtools/client/sourceeditor/test/browser_editor_markers.js => devtools/client/shared/sourceeditor/test/browser_editor_markers.js rename : devtools/client/sourceeditor/test/browser_editor_movelines.js => devtools/client/shared/sourceeditor/test/browser_editor_movelines.js rename : devtools/client/sourceeditor/test/browser_editor_prefs.js => devtools/client/shared/sourceeditor/test/browser_editor_prefs.js rename : devtools/client/sourceeditor/test/browser_editor_script_injection.js => devtools/client/shared/sourceeditor/test/browser_editor_script_injection.js rename : devtools/client/sourceeditor/test/browser_vimemacs.js => devtools/client/shared/sourceeditor/test/browser_vimemacs.js rename : devtools/client/sourceeditor/test/cm_mode_ruby.js => devtools/client/shared/sourceeditor/test/cm_mode_ruby.js rename : devtools/client/sourceeditor/test/cm_script_injection_test.js => devtools/client/shared/sourceeditor/test/cm_script_injection_test.js rename : devtools/client/sourceeditor/test/codemirror/codemirror.html => devtools/client/shared/sourceeditor/test/codemirror/codemirror.html rename : devtools/client/sourceeditor/test/codemirror/comment_test.js => devtools/client/shared/sourceeditor/test/codemirror/comment_test.js rename : devtools/client/sourceeditor/test/codemirror/doc_test.js => devtools/client/shared/sourceeditor/test/codemirror/doc_test.js rename : devtools/client/sourceeditor/test/codemirror/driver.js => devtools/client/shared/sourceeditor/test/codemirror/driver.js rename : devtools/client/sourceeditor/test/codemirror/emacs_test.js => devtools/client/shared/sourceeditor/test/codemirror/emacs_test.js rename : devtools/client/sourceeditor/test/codemirror/mode/javascript/test.js => devtools/client/shared/sourceeditor/test/codemirror/mode/javascript/test.js rename : devtools/client/sourceeditor/test/codemirror/mode_test.css => devtools/client/shared/sourceeditor/test/codemirror/mode_test.css rename : devtools/client/sourceeditor/test/codemirror/mode_test.js => devtools/client/shared/sourceeditor/test/codemirror/mode_test.js rename : devtools/client/sourceeditor/test/codemirror/multi_test.js => devtools/client/shared/sourceeditor/test/codemirror/multi_test.js rename : devtools/client/sourceeditor/test/codemirror/search_test.js => devtools/client/shared/sourceeditor/test/codemirror/search_test.js rename : devtools/client/sourceeditor/test/codemirror/sublime_test.js => devtools/client/shared/sourceeditor/test/codemirror/sublime_test.js rename : devtools/client/sourceeditor/test/codemirror/test.js => devtools/client/shared/sourceeditor/test/codemirror/test.js rename : devtools/client/sourceeditor/test/codemirror/vim_test.js => devtools/client/shared/sourceeditor/test/codemirror/vim_test.js rename : devtools/client/sourceeditor/test/codemirror/vimemacs.html => devtools/client/shared/sourceeditor/test/codemirror/vimemacs.html rename : devtools/client/sourceeditor/test/css_autocompletion_tests.json => devtools/client/shared/sourceeditor/test/css_autocompletion_tests.json rename : devtools/client/sourceeditor/test/css_statemachine_testcases.css => devtools/client/shared/sourceeditor/test/css_statemachine_testcases.css rename : devtools/client/sourceeditor/test/css_statemachine_tests.json => devtools/client/shared/sourceeditor/test/css_statemachine_tests.json rename : devtools/client/sourceeditor/test/head.js => devtools/client/shared/sourceeditor/test/head.js rename : devtools/client/sourceeditor/test/head.xul => devtools/client/shared/sourceeditor/test/head.xul rename : devtools/client/sourceeditor/test/helper_codemirror_runner.js => devtools/client/shared/sourceeditor/test/helper_codemirror_runner.js rename : devtools/client/sourceeditor/wasm.js => devtools/client/shared/sourceeditor/wasm.js rename : devtools/client/sourceeditor/webpack.config.js => devtools/client/shared/sourceeditor/webpack.config.js extra : moz-landing-system : lando
337 lines
8.3 KiB
JavaScript
337 lines
8.3 KiB
JavaScript
/* 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/. */
|
|
|
|
"use strict";
|
|
|
|
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
|
|
const dbginfo = new WeakMap();
|
|
|
|
// These functions implement search within the debugger. Since
|
|
// search in the debugger is different from other components,
|
|
// we can't use search.js CodeMirror addon. This is a slightly
|
|
// modified version of that addon. Depends on searchcursor.js.
|
|
|
|
function SearchState() {
|
|
this.posFrom = this.posTo = this.query = null;
|
|
}
|
|
|
|
function getSearchState(cm) {
|
|
return cm.state.search || (cm.state.search = new SearchState());
|
|
}
|
|
|
|
function getSearchCursor(cm, query, pos) {
|
|
// If the query string is all lowercase, do a case insensitive search.
|
|
return cm.getSearchCursor(query, pos,
|
|
typeof query == "string" && query == query.toLowerCase());
|
|
}
|
|
|
|
/**
|
|
* If there's a saved search, selects the next results.
|
|
* Otherwise, creates a new search and selects the first
|
|
* result.
|
|
*/
|
|
function doSearch(ctx, rev, query) {
|
|
const { cm } = ctx;
|
|
const state = getSearchState(cm);
|
|
|
|
if (state.query) {
|
|
searchNext(ctx, rev);
|
|
return;
|
|
}
|
|
|
|
cm.operation(function() {
|
|
if (state.query) {
|
|
return;
|
|
}
|
|
|
|
state.query = query;
|
|
state.posFrom = state.posTo = { line: 0, ch: 0 };
|
|
searchNext(ctx, rev);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Selects the next result of a saved search.
|
|
*/
|
|
function searchNext(ctx, rev) {
|
|
const { cm, ed } = ctx;
|
|
cm.operation(function() {
|
|
const state = getSearchState(cm);
|
|
let cursor = getSearchCursor(cm, state.query,
|
|
rev ? state.posFrom : state.posTo);
|
|
|
|
if (!cursor.find(rev)) {
|
|
cursor = getSearchCursor(cm, state.query, rev ?
|
|
{ line: cm.lastLine(), ch: null } : { line: cm.firstLine(), ch: 0 });
|
|
if (!cursor.find(rev)) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
ed.alignLine(cursor.from().line, "center");
|
|
cm.setSelection(cursor.from(), cursor.to());
|
|
state.posFrom = cursor.from();
|
|
state.posTo = cursor.to();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Clears the currently saved search.
|
|
*/
|
|
function clearSearch(cm) {
|
|
const state = getSearchState(cm);
|
|
|
|
if (!state.query) {
|
|
return;
|
|
}
|
|
|
|
state.query = null;
|
|
}
|
|
|
|
// Exported functions
|
|
|
|
/**
|
|
* This function is called whenever Editor is extended with functions
|
|
* from this module. See Editor.extend for more info.
|
|
*/
|
|
function initialize(ctx) {
|
|
const { ed } = ctx;
|
|
|
|
dbginfo.set(ed, {
|
|
breakpoints: {},
|
|
debugLocation: null,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* True if editor has a visual breakpoint at that line, false
|
|
* otherwise.
|
|
*/
|
|
function hasBreakpoint(ctx, line) {
|
|
const { ed } = ctx;
|
|
// In some rare occasions CodeMirror might not be properly initialized yet, so
|
|
// return an exceptional value in that case.
|
|
if (ed.lineInfo(line) === null) {
|
|
return null;
|
|
}
|
|
const markers = ed.lineInfo(line).wrapClass;
|
|
|
|
return markers != null &&
|
|
markers.includes("breakpoint");
|
|
}
|
|
|
|
/**
|
|
* Adds a visual breakpoint for a specified line. Third
|
|
* parameter 'cond' can hold any object.
|
|
*
|
|
* After adding a breakpoint, this function makes Editor to
|
|
* emit a breakpointAdded event.
|
|
*/
|
|
function addBreakpoint(ctx, line, cond) {
|
|
if (hasBreakpoint(ctx, line)) {
|
|
return null;
|
|
}
|
|
|
|
return new Promise(resolve => {
|
|
function _addBreakpoint() {
|
|
const { ed } = ctx;
|
|
const meta = dbginfo.get(ed);
|
|
const info = ed.lineInfo(line);
|
|
|
|
// The line does not exist in the editor. This is harmless, the
|
|
// architecture calling this assumes the editor will handle this
|
|
// gracefully, and make sure breakpoints exist when they need to.
|
|
if (!info) {
|
|
return;
|
|
}
|
|
|
|
ed.addLineClass(line, "breakpoint");
|
|
meta.breakpoints[line] = { condition: cond };
|
|
|
|
// TODO(jwl): why is `info` null when breaking on page reload?
|
|
info.handle.on("delete", function onDelete() {
|
|
info.handle.off("delete", onDelete);
|
|
meta.breakpoints[info.line] = null;
|
|
});
|
|
|
|
if (cond) {
|
|
setBreakpointCondition(ctx, line);
|
|
}
|
|
ed.emit("breakpointAdded", line);
|
|
resolve();
|
|
}
|
|
|
|
// If lineInfo() returns null, wait a tick to give the editor a chance to
|
|
// initialize properly.
|
|
if (ctx.ed.lineInfo(line) === null) {
|
|
DevToolsUtils.executeSoon(() => _addBreakpoint());
|
|
} else {
|
|
_addBreakpoint();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Helps reset the debugger's breakpoint state
|
|
* - removes the breakpoints in the editor
|
|
* - cleares the debugger's breakpoint state
|
|
*
|
|
* Note, does not *actually* remove a source's breakpoints.
|
|
* The canonical state is kept in the app state.
|
|
*
|
|
*/
|
|
function removeBreakpoints(ctx) {
|
|
const { ed, cm } = ctx;
|
|
|
|
const meta = dbginfo.get(ed);
|
|
if (meta.breakpoints != null) {
|
|
meta.breakpoints = {};
|
|
}
|
|
|
|
cm.doc.iter((line) => {
|
|
// The hasBreakpoint is a slow operation: checks the line type, whether cm
|
|
// is initialized and creates several new objects. Inlining the line's
|
|
// wrapClass property check directly.
|
|
if (line.wrapClass == null || !line.wrapClass.includes("breakpoint")) {
|
|
return;
|
|
}
|
|
removeBreakpoint(ctx, line);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Removes a visual breakpoint from a specified line and
|
|
* makes Editor emit a breakpointRemoved event.
|
|
*/
|
|
function removeBreakpoint(ctx, line) {
|
|
if (!hasBreakpoint(ctx, line)) {
|
|
return;
|
|
}
|
|
|
|
const { ed } = ctx;
|
|
const meta = dbginfo.get(ed);
|
|
const info = ed.lineInfo(line);
|
|
const lineOrOffset = ed.getLineOrOffset(info.line);
|
|
|
|
meta.breakpoints[lineOrOffset] = null;
|
|
ed.removeLineClass(lineOrOffset, "breakpoint");
|
|
ed.removeLineClass(lineOrOffset, "conditional");
|
|
ed.emit("breakpointRemoved", line);
|
|
}
|
|
|
|
function moveBreakpoint(ctx, fromLine, toLine) {
|
|
const { ed } = ctx;
|
|
|
|
ed.removeBreakpoint(fromLine);
|
|
ed.addBreakpoint(toLine);
|
|
}
|
|
|
|
function setBreakpointCondition(ctx, line) {
|
|
const { ed } = ctx;
|
|
const info = ed.lineInfo(line);
|
|
|
|
// The line does not exist in the editor. This is harmless, the
|
|
// architecture calling this assumes the editor will handle this
|
|
// gracefully, and make sure breakpoints exist when they need to.
|
|
if (!info) {
|
|
return;
|
|
}
|
|
|
|
ed.addLineClass(line, "conditional");
|
|
}
|
|
|
|
function removeBreakpointCondition(ctx, line) {
|
|
const { ed } = ctx;
|
|
|
|
ed.removeLineClass(line, "conditional");
|
|
}
|
|
|
|
/**
|
|
* Returns a list of all breakpoints in the current Editor.
|
|
*/
|
|
function getBreakpoints(ctx) {
|
|
const { ed } = ctx;
|
|
const meta = dbginfo.get(ed);
|
|
|
|
return Object.keys(meta.breakpoints).reduce((acc, line) => {
|
|
if (meta.breakpoints[line] != null) {
|
|
acc.push({ line: line, condition: meta.breakpoints[line].condition });
|
|
}
|
|
return acc;
|
|
}, []);
|
|
}
|
|
|
|
/**
|
|
* Saves a debug location information and adds a visual anchor to
|
|
* the breakpoints gutter. This is used by the debugger UI to
|
|
* display the line on which the Debugger is currently paused.
|
|
*/
|
|
function setDebugLocation(ctx, lineOrOffset) {
|
|
const { ed } = ctx;
|
|
const meta = dbginfo.get(ed);
|
|
const line = ed.getLineOrOffset(lineOrOffset);
|
|
|
|
clearDebugLocation(ctx);
|
|
|
|
meta.debugLocation = line;
|
|
ed.addLineClass(line, "debug-line");
|
|
}
|
|
|
|
/**
|
|
* Returns a line number that corresponds to the current debug
|
|
* location.
|
|
*/
|
|
function getDebugLocation(ctx) {
|
|
const { ed } = ctx;
|
|
const meta = dbginfo.get(ed);
|
|
|
|
return meta.debugLocation;
|
|
}
|
|
|
|
/**
|
|
* Clears the debug location. Clearing the debug location
|
|
* also removes a visual anchor from the breakpoints gutter.
|
|
*/
|
|
function clearDebugLocation(ctx) {
|
|
const { ed } = ctx;
|
|
const meta = dbginfo.get(ed);
|
|
|
|
if (meta.debugLocation != null) {
|
|
ed.removeLineClass(meta.debugLocation, "debug-line");
|
|
meta.debugLocation = null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Starts a new search.
|
|
*/
|
|
function find(ctx, query) {
|
|
clearSearch(ctx.cm);
|
|
doSearch(ctx, false, query);
|
|
}
|
|
|
|
/**
|
|
* Finds the next item based on the currently saved search.
|
|
*/
|
|
function findNext(ctx, query) {
|
|
doSearch(ctx, false, query);
|
|
}
|
|
|
|
/**
|
|
* Finds the previous item based on the currently saved search.
|
|
*/
|
|
function findPrev(ctx, query) {
|
|
doSearch(ctx, true, query);
|
|
}
|
|
|
|
// Export functions
|
|
|
|
[
|
|
initialize, hasBreakpoint, addBreakpoint, removeBreakpoint, moveBreakpoint,
|
|
setBreakpointCondition, removeBreakpointCondition, getBreakpoints, removeBreakpoints,
|
|
setDebugLocation, getDebugLocation, clearDebugLocation, find, findNext,
|
|
findPrev,
|
|
].forEach(func => {
|
|
module.exports[func.name] = func;
|
|
});
|