8000 Implemented ALT option to run code selection. · arduino/lab-micropython-editor@88fe9a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 88fe9a2

Browse files
committed
Implemented ALT option to run code selection.
Signed-off-by: ubi de feo <me@ubidefeo.com>
1 parent 9a58c11 commit 88fe9a2

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ function registerShortcuts() {
9090
console.log('Running Program')
9191
shortcutAction('r')
9292
})
93+
globalShortcut.register('CommandOrControl+Alt+R', () => {
94+
console.log('Running Code Selection')
95+
shortcutAction('_r')
96+
})
9397
globalShortcut.register('CommandOrControl+H', () => {
9498
console.log('Stopping Program (Halt)')
9599
shortcutAction('h')

ui/arduino/store.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,15 @@ async function store(state, emitter) {
203203
})
204204

205205
// CODE EXECUTION
206-
emitter.on('run', async () => {
206+
emitter.on('run', async (selection = false) => {
207207
log('run')
208208
const openFile = state.openFiles.find(f => f.id == state.editingFile)
209209
let code = openFile.editor.editor.state.doc.toString()
210210

211211
// If there is a selection, run only the selected code
212212
const startIndex = openFile.editor.editor.state.selection.ranges[0].from
213213
const endIndex = openFile.editor.editor.state.selection.ranges[0].to
214-
if (endIndex - startIndex > 0) {
214+
if (endIndex - startIndex > 0 && selection) {
215215
selectedCode = openFile.editor.editor.state.doc.toString().substring(startIndex, endIndex)
216216
// Checking to see if the user accidentally double-clicked some whitespace
217217
// While a random selection would yield an error when executed,
@@ -1430,6 +1430,10 @@ async function store(state, emitter) {
14301430
if (state.view != 'editor') return
14311431< 8000 /code>
runCode()
14321432
}
1433+
if (key === '_r') {
1434+
if (state.view != 'editor') return
1435+
runCodeSelection()
1436+
}
14331437
if (key === 'h') {
14341438
if (state.view != 'editor') return
14351439
stopCode()
@@ -1451,6 +1455,11 @@ async function store(state, emitter) {
14511455
emitter.emit('run')
14521456
}
14531457
}
1458+
function runCodeSelection() {
1459+
if (canExecute({ view: state.view, isConnected: state.isConnected })) {
1460+
emitter.emit('run', true)
1461+
}
1462+
}
14541463
function stopCode() {
14551464
if (canExecute({ view: state.view, isConnected: state.isConnected })) {
14561465
emitter.emit('stop')

ui/arduino/views/components/elements/button.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function Button(args) {
22
const {
33
size = '',
44
icon = 'connect.svg',
5-
onClick = () => false,
5+
onClick = (e) => false,
66
disabled = false,
77
active = false,
88
tooltip,

ui/arduino/views/components/toolbar.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ function Toolbar(state, emit) {
2626
icon: 'run.svg',
2727
tooltip: `Run (${metaKeyString}+r)`,
2828
disabled: !_canExecute,
29-
onClick: () => emit('run')
29+
onClick: (e) => {
30+
if (e.altKey) {
31+
emit('run', true)
32+
}else{
33+
emit('run')
34+
}
35+
}
3036
})}
3137
${Button({
3238
icon: 'stop.svg',

0 commit comments

Comments
 (0)
0