Bug 1900395 - [devtools] Migrate setting selection utility r=devtools-reviewers,nchevobbe

Differential Revision: https://phabricator.services.mozilla.com/D222875
This commit is contained in:
Hubert Boma Manilla 2024-10-11 17:41:56 +00:00
parent aed6beb04f
commit 780827af70
4 changed files with 38 additions and 22 deletions

View File

@ -436,8 +436,11 @@ async function testBlackBoxSingleLine(dbg, source) {
assertNotPaused(dbg);
info("Un-blackbox line 2 of funcA()");
selectEditorLines(dbg, 2, 2);
await openContextMenuInDebugger(dbg, "CodeMirrorLines");
await selectEditorLinesAndOpenContextMenu(
dbg,
{ startLine: 2, endLine: 2 },
"CodeMirrorLines"
);
await selectBlackBoxContextMenuItem(dbg, "blackbox-line");
await assertEditorBlackBoxBoxContextMenuItems(dbg, {
@ -717,16 +720,3 @@ async function assertEditorBlackBoxBoxContextMenuItems(dbg, testFixtures) {
await closeContextMenu(dbg, popup);
}
}
/**
* Selects a range of lines
* @param {Object} dbg
* @param {Number} startLine
* @param {Number} endLine
*/
function selectEditorLines(dbg, startLine, endLine) {
getCM(dbg).setSelection(
{ line: startLine - 1, ch: 0 },
{ line: endLine, ch: 0 }
);
}

View File

@ -15,7 +15,7 @@ add_task(async function () {
clickElement(dbg, "CodeMirrorLines");
await waitForElementWithSelector(dbg, ".CodeMirror-code");
getCM(dbg).setSelection({ line: 0, ch: 0 }, { line: 8, ch: 0 });
setSelection(dbg, 1, 7);
rightClickElement(dbg, "CodeMirrorLines");
await waitForContextMenu(dbg);

View File

@ -1557,18 +1557,19 @@ async function openContextMenuInDebugger(dbg, elementName, line) {
* Select a range of lines in the editor and open the contextmenu
* @param {Object} dbg
* @param {Object} lines
* @param {String} elementName
* @returns
*/
async function selectEditorLinesAndOpenContextMenu(dbg, lines) {
async function selectEditorLinesAndOpenContextMenu(
dbg,
lines,
elementName = "line"
) {
const { startLine, endLine } = lines;
const elementName = "line";
if (!endLine) {
await clickElement(dbg, elementName, startLine);
} else {
getCM(dbg).setSelection(
{ line: startLine - 1, ch: 0 },
{ line: endLine, ch: 0 }
);
setSelection(dbg, startLine, endLine);
}
return openContextMenuInDebugger(dbg, elementName, startLine);
}
@ -2220,6 +2221,13 @@ function isScrolledPositionVisible(dbg, line, column = 0) {
line = isCm6Enabled ? line + 1 : line;
return getCMEditor(dbg).isPositionVisible(line, column);
}
function setSelection(dbg, startLine, endLine) {
getCMEditor(dbg).setSelectionAt(
{ line: startLine, column: 0 },
{ line: endLine, column: 0 }
);
}
// Gets the mode used for the file
function getEditorFileMode(dbg) {

View File

@ -3118,6 +3118,24 @@ class Editor extends EventEmitter {
}
}
// Used only in tests
setSelectionAt(start, end) {
const cm = editors.get(this);
if (this.config.cm6) {
const from = this.#posToOffset(start.line, start.column);
const to = this.#posToOffset(end.line, end.column);
if (from == null || to == null) {
return;
}
cm.dispatch({ selection: { anchor: from, head: to } });
} else {
cm.setSelection(
{ line: start.line - 1, ch: start.column },
{ line: end.line - 1, ch: end.column }
);
}
}
// Used only in tests
setCursorAt(line, column) {
const cm = editors.get(this);