@@ -26,6 +26,7 @@ import {
2626 codeFromBlock ,
2727 ensureRequiredExtension ,
2828 executeInteractive ,
29+ executeSelectionInteractive ,
2930} from "./executors" ;
3031
3132export function cellCommands ( engine : MarkdownEngine ) : Command [ ] {
@@ -165,29 +166,36 @@ class RunSelectionCommand extends RunCommand implements Command {
165166 _line : number ,
166167 block : Token
167168 ) {
168- // if the selection is empty take the whole line, otherwise
169- // take the selected text exactly
170- const selection = editor . selection . isEmpty
171- ? editor . document . getText (
172- new Range (
173- new Position ( editor . selection . start . line , 0 ) ,
174- new Position (
175- editor . selection . end . line ,
176- editor . document . lineAt ( editor . selection . end ) . text . length
169+ // get language and attempt language aware runSelection
170+ const language = languageNameFromBlock ( block ) ;
171+ const executed = await executeSelectionInteractive ( language ) ;
172+
173+ // if the executor isn't capable of lenguage aware runSelection
174+ // then determine the selection manually
175+ if ( ! executed ) {
176+ // if the selection is empty take the whole line, otherwise
177+ // take the selected text exactly
178+ const selection = editor . selection . isEmpty
179+ ? editor . document . getText (
180+ new Range (
181+ new Position ( editor . selection . start . line , 0 ) ,
182+ new Position (
183+ editor . selection . end . line ,
184+ editor . document . lineAt ( editor . selection . end ) . text . length
185+ )
177186 )
178187 )
179- )
180- : editor . document . getText ( editor . selection ) ;
188+ : editor . document . getText ( editor . selection ) ;
181189
182- // for empty selections we advance to the next line
183- if ( editor . selection . isEmpty ) {
184- const selPos = new Position ( editor . selection . start . line + 1 , 0 ) ;
185- editor . selection = new Selection ( selPos , selPos ) ;
186- }
190+ // for empty selections we advance to the next line
191+ if ( editor . selection . isEmpty ) {
192+ const selPos = new Position ( editor . selection . start . line + 1 , 0 ) ;
193+ editor . selection = new Selection ( selPos , selPos ) ;
194+ }
187195
188- // run code
189- const language = languageNameFromBlock ( block ) ;
190- await executeInteractive ( language , [ selection ] ) ;
196+ // run code
197+ await executeInteractive ( language , [ selection ] ) ;
198+ }
191199 }
192200}
193201
0 commit comments