@@ -355,10 +355,10 @@ class RunCurrentCommand extends RunCommand implements Command {
355355 // if the selection is empty and we are in Positron:
356356 // try to get the statement's range and use that as the selection
357357 if ( selection . length <= 0 && activeBlock && hasHooks ( ) ) {
358- const language = embeddedLanguage ( activeBlock . language ) ;
359- const vdoc = virtualDocForCode ( lines ( activeBlock . code ) , language ! ) ;
360- const parentUri = Uri . file ( editor . document . fileName ) ;
358+ const codeLines = lines ( activeBlock . code )
359+ const vdoc = virtualDocForCode ( codeLines , embeddedLanguage ( activeBlock . language ) ! ) ;
361360 if ( vdoc ) {
361+ const parentUri = Uri . file ( editor . document . fileName ) ;
362362 const result = await withVirtualDocUri ( vdoc , parentUri , "statementRange" , async ( uri ) => {
363363 return await commands . executeCommand < StatementRange > (
364364 "vscode.executeStatementRangeProvider" ,
@@ -373,6 +373,29 @@ class RunCurrentCommand extends RunCommand implements Command {
373373
374374 selection = slicedLines . join ( '\n' )
375375 action = "nextline" ;
376+
377+ // ref: https://github.com/posit-dev/positron/blob/main/src/vs/workbench/contrib/positronConsole/browser/positronConsoleActions.ts#L428
378+ if ( end . line + 1 <= codeLines . length ) {
379+ const nextStatementRange = await withVirtualDocUri ( vdoc , parentUri , "statementRange" , async ( uri ) => {
380+ return await commands . executeCommand < StatementRange > (
381+ "vscode.executeStatementRangeProvider" ,
382+ uri ,
383+ new Position ( end . line + 1 , 1 )
384+ ) ;
385+ } ) ;
386+ const nextStatement = nextStatementRange . range ;
387+ if ( nextStatement . start . line > end . line ) {
388+ // If the next statement's start is after this statement's end,
389+ // then move to the start of the next statement.
390+ action = nextStatement . start
391+ } else if ( nextStatement . end . line > end . line ) {
392+ // If the above condition failed, but the next statement's end
393+ // is after this statement's end, assume we are exiting some
394+ // nested scope (like running an individual line of an R
395+ // function) and move to the end of the next statement.
396+ action = nextStatement . end
397+ }
398+ }
376399 }
377400 }
378401
@@ -389,8 +412,10 @@ class RunCurrentCommand extends RunCommand implements Command {
389412 await executeInteractive ( executor , [ selection ] , editor . document ) ;
390413
391414 // advance cursor if necessary
415+ //
392416 if ( action ) {
393- editor . setBlockSelection ( context , "nextline" ) ;
417+ console . log ( 'action!!!' , action , this . id )
418+ await editor . setBlockSelection ( context , action ) ;
394419 }
395420 }
396421 }
0 commit comments