File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -206,7 +206,23 @@ async function store(state, emitter) {
206206 emitter . on ( 'run' , async ( ) => {
207207 log ( 'run' )
208208 const openFile = state . openFiles . find ( f => f . id == state . editingFile )
209- const code = openFile . editor . editor . state . doc . toString ( )
209+ let code = openFile . editor . editor . state . doc . toString ( )
210+
211+ // If there is a selection, run only the selected code
212+ const startIndex = openFile . editor . editor . state . selection . ranges [ 0 ] . from
213+ const endIndex = openFile . editor . editor . state . selection . ranges [ 0 ] . to
214+ if ( endIndex - startIndex > 0 ) {
215+ selectedCode = openFile . editor . editor . state . doc . toString ( ) . substring ( startIndex , endIndex )
216+ // Checking to see if the user accidentally double-clicked some whitespace
217+ // While a random selection would yield an error when executed,
218+ // selecting only whitespace would not and the user would have no feedback.
219+ // This check only replaces the full content of the currently selected tab
220+ // with a text selection if the selection is not empty and contains only whitespace.
221+ if ( selectedCode . trim ( ) . length > 0 ) {
222+ code = selectedCode
223+ }
224+ }
225+
210226 emitter . emit ( 'open-panel' )
211227 emitter . emit ( 'render' )
212228 try {
You can’t perform that action at this time.
0 commit comments