Skip to content

Commit 9a58c11

Browse files
committed
Merge branch 'development' into feature/shortcuts
2 parents 7c6cdde + a24311d commit 9a58c11

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

ui/arduino/store.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff 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 {

0 commit comments

Comments
 (0)