From 26098abf2629828aa57c84fec5c428872a840278 Mon Sep 17 00:00:00 2001 From: elliot Date: Wed, 24 Sep 2025 15:53:45 -0400 Subject: [PATCH 1/6] use statementRangeProvider in Positron to execute statements at cursor in VE --- apps/vscode/src/providers/cell/commands.ts | 37 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/apps/vscode/src/providers/cell/commands.ts b/apps/vscode/src/providers/cell/commands.ts index 11a07a39..420a9667 100644 --- a/apps/vscode/src/providers/cell/commands.ts +++ b/apps/vscode/src/providers/cell/commands.ts @@ -51,6 +51,10 @@ import { ExtensionHost } from "../../host"; import { hasHooks } from "../../host/hooks"; import { isKnitrDocument } from "../../host/executors"; import { commands } from "vscode"; +import { virtualDocForCode, withVirtualDocUri } from "../../vdoc/vdoc"; +import { embeddedLanguage } from "../../vdoc/languages"; +import { Uri } from "vscode"; +import { StatementRange } from "positron"; export function cellCommands(host: ExtensionHost, engine: MarkdownEngine): Command[] { return [ @@ -348,17 +352,40 @@ class RunCurrentCommand extends RunCommand implements Command { await activateIfRequired(editor); } } - } else { - // if the selection is empty take the whole line, otherwise take the selected text exactly let action: CodeViewSelectionAction | undefined; - if (selection.length <= 0) { - if (activeBlock) { - selection = lines(activeBlock.code)[context.selection.start.line]; + + // if the selection is empty and we are in Positron: + // try to get the statement's range and use that as the selection + if (selection.length <= 0 && activeBlock && hasHooks()) { + const language = embeddedLanguage(activeBlock.language); + const vdoc = virtualDocForCode(lines(activeBlock.code), language!); + const parentUri = Uri.file(editor.document.fileName); + if (vdoc) { + const result = await withVirtualDocUri(vdoc, parentUri, "statementRange", async (uri) => { + return await commands.executeCommand( + "vscode.executeStatementRangeProvider", + uri, + context.selection.start + ); + }); + const { range: { start, end } } = result + const slicedLines = lines(activeBlock.code).slice(start.line, end.line + 1) + slicedLines[0] = slicedLines[0].slice(start.character) + slicedLines[slicedLines.length - 1] = slicedLines[slicedLines.length - 1].slice(0, end.character) + + selection = slicedLines.join('\n') action = "nextline"; } } + // if the selection is still empty: + // take the whole line as the selection + if (selection.length <= 0 && activeBlock) { + selection = lines(activeBlock.code)[context.selection.start.line]; + action = "nextline"; + } + // run code const executor = await this.cellExecutorForLanguage(context.activeLanguage, editor.document, this.engine_); if (executor) { From 3a513f02d98c74e70460d706127b129c3dc6af45 Mon Sep 17 00:00:00 2001 From: elliot Date: Fri, 3 Oct 2025 15:31:25 -0400 Subject: [PATCH 2/6] WIP fix advancing to next statement I don't think my changes to `codeViewSetBlockSelection` work. It seems that `navigateToPos` does not work inside codeMirror? That must be why only "nextline" works in the command - it doesn't use `navigateToPos` it uses a special codeView thing. --- apps/vscode/src/providers/cell/commands.ts | 33 +++++++++++++++++++--- packages/editor-types/src/codeview.ts | 2 +- packages/editor/src/api/codeview.ts | 21 ++++++++++---- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/apps/vscode/src/providers/cell/commands.ts b/apps/vscode/src/providers/cell/commands.ts index 420a9667..1917be56 100644 --- a/apps/vscode/src/providers/cell/commands.ts +++ b/apps/vscode/src/providers/cell/commands.ts @@ -358,10 +358,10 @@ class RunCurrentCommand extends RunCommand implements Command { // if the selection is empty and we are in Positron: // try to get the statement's range and use that as the selection if (selection.length <= 0 && activeBlock && hasHooks()) { - const language = embeddedLanguage(activeBlock.language); - const vdoc = virtualDocForCode(lines(activeBlock.code), language!); - const parentUri = Uri.file(editor.document.fileName); + const codeLines = lines(activeBlock.code) + const vdoc = virtualDocForCode(codeLines, embeddedLanguage(activeBlock.language)!); if (vdoc) { + const parentUri = Uri.file(editor.document.fileName); const result = await withVirtualDocUri(vdoc, parentUri, "statementRange", async (uri) => { return await commands.executeCommand( "vscode.executeStatementRangeProvider", @@ -376,6 +376,29 @@ class RunCurrentCommand extends RunCommand implements Command { selection = slicedLines.join('\n') action = "nextline"; + + // ref: https://github.com/posit-dev/positron/blob/main/src/vs/workbench/contrib/positronConsole/browser/positronConsoleActions.ts#L428 + if (end.line + 1 <= codeLines.length) { + const nextStatementRange = await withVirtualDocUri(vdoc, parentUri, "statementRange", async (uri) => { + return await commands.executeCommand( + "vscode.executeStatementRangeProvider", + uri, + new Position(end.line + 1, 1) + ); + }); + const nextStatement = nextStatementRange.range; + if (nextStatement.start.line > end.line) { + // If the next statement's start is after this statement's end, + // then move to the start of the next statement. + action = nextStatement.start + } else if (nextStatement.end.line > end.line) { + // If the above condition failed, but the next statement's end + // is after this statement's end, assume we are exiting some + // nested scope (like running an individual line of an R + // function) and move to the end of the next statement. + action = nextStatement.end + } + } } } @@ -392,8 +415,10 @@ class RunCurrentCommand extends RunCommand implements Command { await executeInteractive(executor, [selection], editor.document); // advance cursor if necessary + // if (action) { - editor.setBlockSelection(context, "nextline"); + console.log('action!!!', action, this.id) + await editor.setBlockSelection(context, action); } } } diff --git a/packages/editor-types/src/codeview.ts b/packages/editor-types/src/codeview.ts index 2977f404..e40da3ba 100644 --- a/packages/editor-types/src/codeview.ts +++ b/packages/editor-types/src/codeview.ts @@ -34,7 +34,7 @@ export interface CodeViewActiveBlockContext { selectedText: string; } -export type CodeViewSelectionAction = "nextline" | "nextblock" | "prevblock"; +export type CodeViewSelectionAction = "nextline" | "nextblock" | "prevblock" | { line: number, character: number }; export interface CodeViewCellContext { filepath: string; diff --git a/packages/editor/src/api/codeview.ts b/packages/editor/src/api/codeview.ts index 25e4df42..201ccfe2 100644 --- a/packages/editor/src/api/codeview.ts +++ b/packages/editor/src/api/codeview.ts @@ -205,12 +205,23 @@ export function codeViewSetBlockSelection( context: CodeViewActiveBlockContext, action: CodeViewSelectionAction ) { - - const activeIndex = context.blocks.findIndex(block => block.active); if (activeIndex !== -1) { - if (action === "nextline") { + if (typeof action === 'object') { + // convert action line and character in code block space to pos in prosemirror space + const block = context.blocks[activeIndex] + const code = lines(block.code) + if (action.line > code.length) throw 'trying to move cursor outside block!' + let pos = block.pos + for (let i = 0; i <= action.line; i++) { + pos += code[i].length + } + pos += action.character + + console.log('yoooo', pos, navigateToPos(view, pos, false)); + } + else if (action === "nextline") { const tr = view.state.tr; tr.setMeta(kCodeViewNextLineTransaction, true); view.dispatch(tr); @@ -222,13 +233,11 @@ export function codeViewSetBlockSelection( navigatePos = context.blocks[activeIndex - 1]?.pos; } if (navigatePos) { + console.log('yoooo22', navigatePos) navigateToPos(view, navigatePos!, false); } } } - - - } From 81924682e614a83f9ad2a0ea4b46cba38f70f08b Mon Sep 17 00:00:00 2001 From: elliot Date: Fri, 3 Oct 2025 16:45:17 -0400 Subject: [PATCH 3/6] fix advancing to next statement --- apps/vscode/src/providers/cell/commands.ts | 14 +++++------- .../src/behaviors/trackselection.ts | 22 +++++++++---------- packages/editor/src/api/codeview.ts | 10 +++++---- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/apps/vscode/src/providers/cell/commands.ts b/apps/vscode/src/providers/cell/commands.ts index 1917be56..1e826fa9 100644 --- a/apps/vscode/src/providers/cell/commands.ts +++ b/apps/vscode/src/providers/cell/commands.ts @@ -377,28 +377,26 @@ class RunCurrentCommand extends RunCommand implements Command { selection = slicedLines.join('\n') action = "nextline"; - // ref: https://github.com/posit-dev/positron/blob/main/src/vs/workbench/contrib/positronConsole/browser/positronConsoleActions.ts#L428 + // BEGIN ref: https://github.com/posit-dev/positron/blob/main/src/vs/workbench/contrib/positronConsole/browser/positronConsoleActions.ts#L428 + // strategy from Positron using `StatementRangeProvider` to find range of next statement + // and move cursor based on that. if (end.line + 1 <= codeLines.length) { const nextStatementRange = await withVirtualDocUri(vdoc, parentUri, "statementRange", async (uri) => { return await commands.executeCommand( "vscode.executeStatementRangeProvider", uri, - new Position(end.line + 1, 1) + new Position(end.line + 1, 1) // look for statement at line after current statement ); }); const nextStatement = nextStatementRange.range; if (nextStatement.start.line > end.line) { - // If the next statement's start is after this statement's end, - // then move to the start of the next statement. action = nextStatement.start + // the nextStatement may start before & end after the current statement if e.g. inside a function: } else if (nextStatement.end.line > end.line) { - // If the above condition failed, but the next statement's end - // is after this statement's end, assume we are exiting some - // nested scope (like running an individual line of an R - // function) and move to the end of the next statement. action = nextStatement.end } } + // END ref. } } diff --git a/packages/editor-codemirror/src/behaviors/trackselection.ts b/packages/editor-codemirror/src/behaviors/trackselection.ts index bfcd073f..79a4b84f 100644 --- a/packages/editor-codemirror/src/behaviors/trackselection.ts +++ b/packages/editor-codemirror/src/behaviors/trackselection.ts @@ -27,7 +27,7 @@ import { DispatchEvent, codeViewCellContext, kCodeViewNextLineTransaction } from import { Behavior, BehaviorContext, State } from "."; // track the selection in prosemirror -export function trackSelectionBehavior(context: BehaviorContext) : Behavior { +export function trackSelectionBehavior(context: BehaviorContext): Behavior { let unsubscribe: VoidFunction; @@ -50,32 +50,32 @@ export function trackSelectionBehavior(context: BehaviorContext) : Behavior { unsubscribe = context.pmContext.events.subscribe(DispatchEvent, (tr: Transaction | undefined) => { if (tr) { // track selection changes that occur when we don't have focus - if (!cmView.hasFocus && tr.selectionSet && !tr.docChanged && (tr.selection instanceof TextSelection)) { + if (tr.selectionSet && !tr.docChanged && (tr.selection instanceof TextSelection)) { const cmSelection = asCodeMirrorSelection(context.view, cmView, context.getPos); context.withState(State.Updating, () => { if (cmSelection) { cmView.dispatch({ selection: cmSelection }); } else { - cmView.dispatch({ selection: EditorSelection.single(0)}) - } + cmView.dispatch({ selection: EditorSelection.single(0) }) + } }) } else if (tr.getMeta(kCodeViewNextLineTransaction) === true) { // NOTE: this is a special directive to advance to the next line. as distinct // from the block above it is not a reporting of a change in the PM selection - // but rather an instruction to move the CM selection to the next line. as + // but rather an instruction to move the CM selection to the next line. as // such we do not encose the code in State.Updating, because we want an update // to the PM selection to occur const cmSelection = asCodeMirrorSelection(context.view, cmView, context.getPos); if (cmSelection) { if (cursorLineDown(cmView)) { cursorLineStart(cmView); - } + } } - // for other selection changes + // for other selection changes } else if (cmView.hasFocus && tr.selectionSet && (tr.selection instanceof TextSelection)) { codeViewAssist(); } - } + } }); }, @@ -91,7 +91,7 @@ export const asCodeMirrorSelection = ( cmView: EditorView, getPos: (() => number) | boolean ) => { - if (typeof(getPos) === "function") { + if (typeof (getPos) === "function") { const offset = getPos() + 1; const node = pmView.state.doc.nodeAt(getPos()); if (node) { @@ -104,8 +104,8 @@ export const asCodeMirrorSelection = ( } else if (selection.from <= cmRange.from && selection.to >= cmRange.to) { return EditorSelection.single(0, cmView.state.doc.length); } - + } } return undefined; -} \ No newline at end of file +} diff --git a/packages/editor/src/api/codeview.ts b/packages/editor/src/api/codeview.ts index 201ccfe2..8e372b83 100644 --- a/packages/editor/src/api/codeview.ts +++ b/packages/editor/src/api/codeview.ts @@ -211,15 +211,17 @@ export function codeViewSetBlockSelection( if (typeof action === 'object') { // convert action line and character in code block space to pos in prosemirror space const block = context.blocks[activeIndex] + // asummes the meta line looks like this: + const metaLine = '{' + block.language + '}\n' const code = lines(block.code) if (action.line > code.length) throw 'trying to move cursor outside block!' - let pos = block.pos - for (let i = 0; i <= action.line; i++) { - pos += code[i].length + let pos = block.pos + metaLine.length + for (let i = 0; i < action.line; i++) { + pos += code[i].length + 1 } pos += action.character - console.log('yoooo', pos, navigateToPos(view, pos, false)); + navigateToPos(view, pos, false) } else if (action === "nextline") { const tr = view.state.tr; From f688c6f39e79f315ee3320a0ed05c83d30281219 Mon Sep 17 00:00:00 2001 From: elliot Date: Tue, 21 Oct 2025 10:50:33 -0400 Subject: [PATCH 4/6] WIP move to next statement --- apps/vscode/src/providers/cell/commands.ts | 36 ++++++++++++++-------- packages/editor/src/api/codeview.ts | 1 - 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/apps/vscode/src/providers/cell/commands.ts b/apps/vscode/src/providers/cell/commands.ts index 1e826fa9..07671160 100644 --- a/apps/vscode/src/providers/cell/commands.ts +++ b/apps/vscode/src/providers/cell/commands.ts @@ -343,8 +343,11 @@ class RunCurrentCommand extends RunCommand implements Command { let selection = context.selectedText; const activeBlock = context.blocks.find(block => block.active); + // idea: first check that we are in Positron + // and leave the others untouched + // if the selection is empty and this isn't a knitr document then it resolves to run cell - if (selection.length <= 0 && !isKnitrDocument(editor.document, this.engine_)) { + if (false) { if (activeBlock) { const executor = await this.cellExecutorForLanguage(activeBlock.language, editor.document, this.engine_); if (executor) { @@ -362,37 +365,46 @@ class RunCurrentCommand extends RunCommand implements Command { const vdoc = virtualDocForCode(codeLines, embeddedLanguage(activeBlock.language)!); if (vdoc) { const parentUri = Uri.file(editor.document.fileName); + const injectedLines = (vdoc.language?.inject?.length ?? 0) + + const positionIntoVdoc = (p: { line: number, character: number }) => + new Position(p.line + injectedLines, p.character) + const positionOutOfVdoc = (p: { line: number, character: number }) => + new Position(p.line - injectedLines, p.character) + const result = await withVirtualDocUri(vdoc, parentUri, "statementRange", async (uri) => { return await commands.executeCommand( "vscode.executeStatementRangeProvider", uri, - context.selection.start + positionIntoVdoc(context.selection.start) ); }); - const { range: { start, end } } = result - const slicedLines = lines(activeBlock.code).slice(start.line, end.line + 1) - slicedLines[0] = slicedLines[0].slice(start.character) - slicedLines[slicedLines.length - 1] = slicedLines[slicedLines.length - 1].slice(0, end.character) + const { range, code } = result + if (code === undefined) return + const adjustedEnd = positionOutOfVdoc(range.end) - selection = slicedLines.join('\n') + selection = code action = "nextline"; // BEGIN ref: https://github.com/posit-dev/positron/blob/main/src/vs/workbench/contrib/positronConsole/browser/positronConsoleActions.ts#L428 // strategy from Positron using `StatementRangeProvider` to find range of next statement // and move cursor based on that. - if (end.line + 1 <= codeLines.length) { + if (adjustedEnd.line + 1 <= codeLines.length) { const nextStatementRange = await withVirtualDocUri(vdoc, parentUri, "statementRange", async (uri) => { return await commands.executeCommand( "vscode.executeStatementRangeProvider", uri, - new Position(end.line + 1, 1) // look for statement at line after current statement + positionIntoVdoc(new Position(adjustedEnd.line + 1, 1)) // look for statement at line after current statement ); }); - const nextStatement = nextStatementRange.range; - if (nextStatement.start.line > end.line) { + const nextStatement = { + start: positionOutOfVdoc(nextStatementRange.range.start), + end: positionOutOfVdoc(nextStatementRange.range.end) + }; + if (nextStatement.start.line > adjustedEnd.line) { action = nextStatement.start // the nextStatement may start before & end after the current statement if e.g. inside a function: - } else if (nextStatement.end.line > end.line) { + } else if (nextStatement.end.line > adjustedEnd.line) { action = nextStatement.end } } diff --git a/packages/editor/src/api/codeview.ts b/packages/editor/src/api/codeview.ts index 8e372b83..3f664d11 100644 --- a/packages/editor/src/api/codeview.ts +++ b/packages/editor/src/api/codeview.ts @@ -235,7 +235,6 @@ export function codeViewSetBlockSelection( navigatePos = context.blocks[activeIndex - 1]?.pos; } if (navigatePos) { - console.log('yoooo22', navigatePos) navigateToPos(view, navigatePos!, false); } } From f8347edd319a64d699bd15243f5d47be070f51c6 Mon Sep 17 00:00:00 2001 From: elliot Date: Fri, 31 Oct 2025 14:53:00 -0400 Subject: [PATCH 5/6] Working Positron VE statement range execution in r and python --- apps/vscode/src/providers/cell/commands.ts | 138 +++++++++++---------- 1 file changed, 70 insertions(+), 68 deletions(-) diff --git a/apps/vscode/src/providers/cell/commands.ts b/apps/vscode/src/providers/cell/commands.ts index 07671160..1531abea 100644 --- a/apps/vscode/src/providers/cell/commands.ts +++ b/apps/vscode/src/providers/cell/commands.ts @@ -263,7 +263,19 @@ class RunPreviousCellCommand extends RunCommand implements Command { } } +// More permissive type than `Position` so its easier to construct via a literal +type LineAndCharPos = { line: number, character: number } +// More permissive type than `Range` so its easier to construct via a literal +type LineAndCharRange = { start: LineAndCharPos, end: LineAndCharPos } + +function extractRangeFromCode(code: string, range: LineAndCharRange): string { + const extractedRange = lines(code).slice(range.start.line, range.end.line + 1) + extractedRange[0] = extractedRange[0].slice(range.start.character) + extractedRange[extractedRange.length - 1] = extractedRange[extractedRange.length - 1].slice(0, range.end.character) + return extractedRange.join('\n') +} +// Run the code at the cursor class RunCurrentCommand extends RunCommand implements Command { constructor( host: ExtensionHost, @@ -340,95 +352,85 @@ class RunCurrentCommand extends RunCommand implements Command { context: CodeViewActiveBlockContext ): Promise { // get selection and active block - let selection = context.selectedText; + const selection = context.selectedText; const activeBlock = context.blocks.find(block => block.active); - // idea: first check that we are in Positron - // and leave the others untouched - - // if the selection is empty and this isn't a knitr document then it resolves to run cell - if (false) { - if (activeBlock) { - const executor = await this.cellExecutorForLanguage(activeBlock.language, editor.document, this.engine_); - if (executor) { - await executeInteractive(executor, [activeBlock.code], editor.document); - await activateIfRequired(editor); - } + const exec = async (action: CodeViewSelectionAction, selection: string) => { + const executor = await this.cellExecutorForLanguage(context.activeLanguage, editor.document, this.engine_); + if (executor) { + await executeInteractive(executor, [selection], editor.document); + await editor.setBlockSelection(context, action); } - } else { - let action: CodeViewSelectionAction | undefined; + } - // if the selection is empty and we are in Positron: - // try to get the statement's range and use that as the selection - if (selection.length <= 0 && activeBlock && hasHooks()) { + // if in Positron + if (hasHooks()) { + if (activeBlock && selection.length <= 0) { const codeLines = lines(activeBlock.code) const vdoc = virtualDocForCode(codeLines, embeddedLanguage(activeBlock.language)!); if (vdoc) { const parentUri = Uri.file(editor.document.fileName); const injectedLines = (vdoc.language?.inject?.length ?? 0) - const positionIntoVdoc = (p: { line: number, character: number }) => + const positionIntoVdoc = (p: LineAndCharPos) => new Position(p.line + injectedLines, p.character) - const positionOutOfVdoc = (p: { line: number, character: number }) => + const positionOutOfVdoc = (p: LineAndCharPos) => new Position(p.line - injectedLines, p.character) - - const result = await withVirtualDocUri(vdoc, parentUri, "statementRange", async (uri) => { - return await commands.executeCommand( - "vscode.executeStatementRangeProvider", - uri, - positionIntoVdoc(context.selection.start) - ); - }); - const { range, code } = result - if (code === undefined) return - const adjustedEnd = positionOutOfVdoc(range.end) - - selection = code - action = "nextline"; - - // BEGIN ref: https://github.com/posit-dev/positron/blob/main/src/vs/workbench/contrib/positronConsole/browser/positronConsoleActions.ts#L428 - // strategy from Positron using `StatementRangeProvider` to find range of next statement - // and move cursor based on that. - if (adjustedEnd.line + 1 <= codeLines.length) { - const nextStatementRange = await withVirtualDocUri(vdoc, parentUri, "statementRange", async (uri) => { + const rangeOutOfVdoc = (r: Range): LineAndCharRange => ({ + start: positionOutOfVdoc(r.start), + end: positionOutOfVdoc(r.end) + }) + const getStatementRange = async (pos: LineAndCharPos) => { + const result = await withVirtualDocUri(vdoc, parentUri, "statementRange", async (uri) => { return await commands.executeCommand( "vscode.executeStatementRangeProvider", uri, - positionIntoVdoc(new Position(adjustedEnd.line + 1, 1)) // look for statement at line after current statement + positionIntoVdoc(pos) ); }); - const nextStatement = { - start: positionOutOfVdoc(nextStatementRange.range.start), - end: positionOutOfVdoc(nextStatementRange.range.end) - }; - if (nextStatement.start.line > adjustedEnd.line) { - action = nextStatement.start - // the nextStatement may start before & end after the current statement if e.g. inside a function: - } else if (nextStatement.end.line > adjustedEnd.line) { - action = nextStatement.end + return rangeOutOfVdoc(result.range) + } + + const range = await getStatementRange(context.selection.start) + const code = extractRangeFromCode(activeBlock.code, range) + + // BEGIN ref: https://github.com/posit-dev/positron/blob/main/src/vs/workbench/contrib/positronConsole/browser/positronConsoleActions.ts#L428 + // strategy from Positron using `StatementRangeProvider` to find range of next statement + // and move cursor based on that. + if (range.end.line + 1 <= codeLines.length) { + // get range of statement at line after current statement) + const nextRange = await getStatementRange(new Position(range.end.line + 1, 1)) + + if (nextRange.start.line > range.end.line) { + exec(nextRange.start, code) + // the next statement range may start before & end after the current statement if e.g. inside a function: + } else if (nextRange.end.line > range.end.line) { + exec(nextRange.end, code) + } else { + exec("nextline", code) } + } else { + exec("nextline", code) } // END ref. } } - - // if the selection is still empty: - // take the whole line as the selection - if (selection.length <= 0 && activeBlock) { - selection = lines(activeBlock.code)[context.selection.start.line]; - action = "nextline"; - } - - // run code - const executor = await this.cellExecutorForLanguage(context.activeLanguage, editor.document, this.engine_); - if (executor) { - await executeInteractive(executor, [selection], editor.document); - - // advance cursor if necessary - // - if (action) { - console.log('action!!!', action, this.id) - await editor.setBlockSelection(context, action); + // if not in Positron + } else { + // if the selection is empty and this isn't a knitr document then it resolves to run cell + if (selection.length <= 0 && !isKnitrDocument(editor.document, this.engine_)) { + if (activeBlock) { + const executor = await this.cellExecutorForLanguage(activeBlock.language, editor.document, this.engine_); + if (executor) { + await executeInteractive(executor, [activeBlock.code], editor.document); + await activateIfRequired(editor); + } + } + } else { + if (selection.length > 0) { + exec("nextline", selection) + } else if (activeBlock) { // if the selection is empty take the whole line as the selection + exec("nextline", lines(activeBlock.code)[context.selection.start.line]) } } } @@ -444,7 +446,7 @@ class RunSelectionCommand extends RunCurrentCommand implements Command { } - +// Run Cell and Advance class RunCurrentAdvanceCommand extends RunCommand implements Command { constructor(host: ExtensionHost, engine: MarkdownEngine) { super(host, engine); From e944e72c3af88ee638aea2781aedff351a51dd75 Mon Sep 17 00:00:00 2001 From: elliot Date: Tue, 4 Nov 2025 14:41:14 -0500 Subject: [PATCH 6/6] Add comment clarifying `codeViewExecute` --- apps/vscode/src/providers/editor/codeview.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/vscode/src/providers/editor/codeview.ts b/apps/vscode/src/providers/editor/codeview.ts index 13a990ce..d2500a6e 100644 --- a/apps/vscode/src/providers/editor/codeview.ts +++ b/apps/vscode/src/providers/editor/codeview.ts @@ -60,6 +60,11 @@ export function vscodeCodeViewServer(_engine: MarkdownEngine, document: TextDocu async codeViewAssist(context: CodeViewCellContext) { await commands.executeCommand("quarto.codeViewAssist", context, lspRequest); }, + // This execute command is used when the user clicks an execute button on a cell in the visual editor. + // + // Note: this is NOT used when the user uses a keyboard command to execute a cell, + // that goes through VSCode commands (commands are registered in package.json), + // the keyboard command code is in apps/vscode/src/providers/cell/commands.ts. async codeViewExecute(execute: CodeViewExecute) { switch (execute) { case "cell":