tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 7eed621ff220c3baf8e592ef9789e32f78712180
parent 673deb90455c4227f6f08eb51f4dcc42850b1a6b
Author: Hubert Boma Manilla <hmanilla@mozilla.com>
Date:   Mon,  6 Oct 2025 12:24:21 +0000

Bug 1988710 - [devtools] Cleanup setCursorAt for just CM6 r=devtools-reviewers,nchevobbe

Differential Revision: https://phabricator.services.mozilla.com/D267380

Diffstat:
Mdevtools/client/debugger/src/components/Editor/index.js | 2+-
Mdevtools/client/debugger/test/mochitest/browser_dbg-breakpoints-columns.js | 1-
Mdevtools/client/debugger/test/mochitest/browser_dbg-breakpoints.js | 4++--
Mdevtools/client/debugger/test/mochitest/browser_dbg-editor-select.js | 11++++-------
Mdevtools/client/debugger/test/mochitest/head.js | 14--------------
Mdevtools/client/debugger/test/mochitest/shared-head.js | 22+++++++++++++++++++---
Mdevtools/client/debugger/test/mochitest/sourcemaps/browser_dbg-sourcemaps.js | 2+-
Mdevtools/client/netmonitor/src/components/previews/SourcePreview.js | 2+-
Mdevtools/client/shared/sourceeditor/editor.js | 35++++++++++++++++-------------------
9 files changed, 44 insertions(+), 49 deletions(-)

diff --git a/devtools/client/debugger/src/components/Editor/index.js b/devtools/client/debugger/src/components/Editor/index.js @@ -649,7 +649,7 @@ class Editor extends PureComponent { editor.focus(); } - await editor.setCursorAt(line - 1, column); + await editor.setCursorAt(line, column); } async setText(props, editor) { diff --git a/devtools/client/debugger/test/mochitest/browser_dbg-breakpoints-columns.js b/devtools/client/debugger/test/mochitest/browser_dbg-breakpoints-columns.js @@ -43,7 +43,6 @@ add_task(async function () { }); async function enableFirstBreakpoint(dbg) { - setEditorCursorAt(dbg, 32, 0); await addBreakpoint(dbg, "long.js", 32); const bpMarkers = await waitForAllElements(dbg, "columnBreakpoints"); diff --git a/devtools/client/debugger/test/mochitest/browser_dbg-breakpoints.js b/devtools/client/debugger/test/mochitest/browser_dbg-breakpoints.js @@ -85,8 +85,8 @@ add_task(async function testBreakpointsKeyboardEvents() { await addBreakpoint(dbg, "simple2.js", 3); await addBreakpoint(dbg, "simple2.js", 4); - info("Add conditional breakpoint to line 4"); - setEditorCursorAt(dbg, 4, 2); + info("Add conditional breakpoint to line 5"); + await setEditorCursorAt(dbg, 5, 2); await setConditionalBreakpointWithKeyboardShortcut(dbg, "3"); pressKey(dbg, "Enter"); await waitForCondition(dbg, "3"); diff --git a/devtools/client/debugger/test/mochitest/browser_dbg-editor-select.js b/devtools/client/debugger/test/mochitest/browser_dbg-editor-select.js @@ -30,12 +30,10 @@ add_task(async function () { ); assertHighlightLocation(dbg, "simple1.js", 1); - // Note that CodeMirror is 0-based while the footer displays 1-based - setEditorCursorAt(dbg, 1, 0); - await waitForCursorPosition(dbg, 2); + await setEditorCursorAt(dbg, 1, 0); assertCursorPosition( dbg, - 2, + 1, 1, "when moving the cursor, the position footer updates" ); @@ -44,11 +42,10 @@ add_task(async function () { "Moving the cursor resets the highlighted line" ); - setEditorCursorAt(dbg, 2, 0); - await waitForCursorPosition(dbg, 3); + await setEditorCursorAt(dbg, 2, 0); assertCursorPosition( dbg, - 3, + 2, 1, "when moving the cursor a second time, the position footer still updates" ); diff --git a/devtools/client/debugger/test/mochitest/head.js b/devtools/client/debugger/test/mochitest/head.js @@ -190,20 +190,6 @@ function assertCursorPosition(dbg, expectedLine, expectedColumn, message) { is(cursor.from.ch + 1, expectedColumn, message + " (actual cursor column)"); } -async function waitForCursorPosition(dbg, expectedLine) { - return waitFor(() => { - const cursorPosition = findElementWithSelector(dbg, ".cursor-position"); - if (!cursorPosition) { - return false; - } - const { innerText } = cursorPosition; - // Cursor position text has the following shape: (L, C) - // where L is the line number, and C the column number - const line = innerText.substring(1, innerText.indexOf(",")); - return parseInt(line, 10) == expectedLine; - }); -} - /** * @see selectDebuggerContextMenuItem in debugger/test/mochitest/shared-head.js */ diff --git a/devtools/client/debugger/test/mochitest/shared-head.js b/devtools/client/debugger/test/mochitest/shared-head.js @@ -2343,16 +2343,32 @@ function getCodeMirrorInstance(dbg, panelName = null) { return dbg.win.codeMirrorSourceEditorTestInstance.codeMirror; } +async function waitForCursorPosition(dbg, expectedLine) { + return waitFor(() => { + const cursorPosition = findElementWithSelector(dbg, ".cursor-position"); + if (!cursorPosition) { + return false; + } + const { innerText } = cursorPosition; + // Cursor position text has the following shape: (L, C) + // where L is the line number, and C the column number + const line = innerText.substring(1, innerText.indexOf(",")); + return parseInt(line, 10) == expectedLine; + }); +} + /** * Set the cursor at a specific location in the editor * @param {*} dbg * @param {Number} line * @param {Number} column - * @returns + * @returns {Promise} */ -function setEditorCursorAt(dbg, line, column) { +async function setEditorCursorAt(dbg, line, column) { scrollEditorIntoView(dbg, line, 0); - return getCMEditor(dbg).setCursorAt(line, column); + const cursorSet = waitForCursorPosition(dbg, line); + await getCMEditor(dbg).setCursorAt(line, column); + return cursorSet; } /** diff --git a/devtools/client/debugger/test/mochitest/sourcemaps/browser_dbg-sourcemaps.js b/devtools/client/debugger/test/mochitest/sourcemaps/browser_dbg-sourcemaps.js @@ -161,7 +161,7 @@ add_task(async function () { ); info("Move the cursor within the bundle to another original source"); - setEditorCursorAt(dbg, 70, 0); + await setEditorCursorAt(dbg, 71, 0); mappedSourceLink = await waitFor(() => findElement(dbg, "mappedSourceLink")); is( mappedSourceLink.textContent, diff --git a/devtools/client/netmonitor/src/components/previews/SourcePreview.js b/devtools/client/netmonitor/src/components/previews/SourcePreview.js @@ -112,7 +112,7 @@ class SourcePreview extends Component { // with the target search result if (this.editor) { await this.editor.scrollTo(line, 0); - await this.editor.setCursorAt(line - 1, 0); + await this.editor.setCursorAt(line, 0); // Highlight line this.editor.setLineContentMarker({ diff --git a/devtools/client/shared/sourceeditor/editor.js b/devtools/client/shared/sourceeditor/editor.js @@ -3628,31 +3628,28 @@ class Editor extends EventEmitter { /** * Move CodeMirror cursor to a given location. - * + * Used only for CM6 * @param {Number} line * @param {Number} column */ setCursorAt(line, column) { const cm = editors.get(this); - if (this.config.cm6) { - const { lines } = cm.state.doc; - if (line > lines) { - console.error( - `Trying to set the cursor on a non-existing line ${line} > ${lines}` - ); - return null; - } - const lineInfo = cm.state.doc.line(line + 1); - if (column >= lineInfo.length) { - console.error( - `Trying to set the cursor on a non-existing column ${column} >= ${lineInfo.length}` - ); - return null; - } - const position = lineInfo.from + column; - return cm.dispatch({ selection: { anchor: position, head: position } }); + const { lines } = cm.state.doc; + if (line > lines) { + console.error( + `Trying to set the cursor on a non-existing line ${line} > ${lines}` + ); + return null; + } + const lineInfo = cm.state.doc.line(line); + if (column >= lineInfo.length) { + console.error( + `Trying to set the cursor on a non-existing column ${column} >= ${lineInfo.length}` + ); + return null; } - return cm.setCursor({ line, ch: column }); + const position = lineInfo.from + column; + return cm.dispatch({ selection: { anchor: position, head: position } }); } // Used only in tests