File tree 1 file changed +17
-1
lines changed
1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -193,7 +193,23 @@ async function store(state, emitter) {
193
193
emitter . on ( 'run' , async ( ) => {
194
194
log ( 'run' )
195
195
const openFile = state . openFiles . find ( f => f . id == state . editingFile )
196
- const code = openFile . editor . editor . state . doc . toString ( )
196
+ let code = openFile . editor . editor . state . doc . toString ( )
197
+
198
+ // If there is a selection, run only the selected code
199
+ const startIndex = openFile . editor . editor . state . selection . ranges [ 0 ] . from
200
+ const endIndex = openFile . editor . editor . state . selection . ranges [ 0 ] . to
201
+ if ( endIndex - startIndex > 0 ) {
202
+ selectedCode = openFile . editor . editor . state . doc . toString ( ) . substring ( startIndex , endIndex )
203
+ // Checking to see if the user accidentally double-clicked some whitespace
204
+ // While a random selection would yield an error when executed,
205
+ // selecting only whitespace would not and the user would have no feedback.
206
+ // This check only replaces the full content of the currently selected tab
207
+ // with a text selection if the selection is not empty and contains only whitespace.
208
+ if ( selectedCode . trim ( ) . length > 0 ) {
209
+ code = selectedCode
210
+ }
211
+ }
212
+
197
213
emitter . emit ( 'open-panel' )
198
214
emitter . emit ( 'render' )
199
215
try {
You can’t perform that action at this time.
0 commit comments