Skip to content

Commit

Permalink
add code flash
Browse files Browse the repository at this point in the history
  • Loading branch information
mogimogitomato committed Dec 22, 2020
1 parent 70d454b commit 79232ac
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@
"type": "boolean",
"default": true,
"description": "Clear the log when executing a run"
},
"sonicpieditor.flashBackgroundColor": {
"type": "string",
"default": "rgba(255,20,147,1.0)",
"description": "Background flash color when running code"
},
"sonicpieditor.flashTextColor": {
"type": "string",
"default": "rgba(255,255,255,1.0)",
"description": "Text flash color when running code"
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ export class Config {
private rubySection: string = 'ruby.interpreter';

// sonic-pi's config
public flashBackgroundColor(): string {
return this.getConfiguration(this.section).flashBackgroundColor;
}
public flashTextColor(): string {
return this.getConfiguration(this.section).flashTextColor;
}
public launchSonicPiServerAutomatically(): string {
return this.getConfiguration(this.section).launchSonicPiServerAutomatically;
}
Expand Down
5 changes: 5 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function activate(context: vscode.ExtensionContext) {
doc = rubyEditors[0].document;
}
let code = doc.getText();
main.flashCode(textEditor, true);
main.runCode(code);
});

Expand Down Expand Up @@ -99,11 +100,13 @@ export function activate(context: vscode.ExtensionContext) {
item => {
if (item === 'Yes, once'){
code = doc.getText();
main.flashCode(textEditor, true);
main.runCode(code);
}
else if (item === 'Yes, always'){
config.updateRunFileWhenRunSelectedIsEmpty('always');
code = doc.getText();
main.flashCode(textEditor, true);
main.runCode(code);
}
else if (item === 'No, never'){
Expand All @@ -118,10 +121,12 @@ export function activate(context: vscode.ExtensionContext) {
}
else if (runFileWhenRunSelectedIsEmpty === 'always'){
code = doc.getText();
main.flashCode(textEditor, true);
main.runCode(code);
}

}
main.flashCode(textEditor, false);
main.runCode(code, textEditor.selection.start.line);
});

Expand Down
23 changes: 22 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const OSC = require('osc-js');
const utf8 = require('utf8');
const { v4: uuidv4 } = require('uuid');
import { Config } from './config';
import { Range, TextEditor, window } from 'vscode';


export class Main {
Expand Down Expand Up @@ -466,7 +467,27 @@ export class Main {
this.sendOsc(message);
}

stopAllJobs(){
flashCode(editor: TextEditor, isWhole: boolean) {
const range = isWhole ? this.getWholeRange(editor) : this.getSelectedRange(editor);
const flashDecorationType = window.createTextEditorDecorationType({
backgroundColor: this.config.flashBackgroundColor(),
color: this.config.flashTextColor()
});
editor.setDecorations(flashDecorationType, [range]);
setTimeout(function () {
flashDecorationType.dispose();
}, 250);
}
private getWholeRange(editor: TextEditor): Range {
let startPos = editor.document.positionAt(0);
let endPos = editor.document.positionAt(editor.document.getText().length - 1);
return new Range(startPos, endPos);
}
private getSelectedRange(editor: TextEditor): Range {
return new Range(editor.selection.anchor, editor.selection.active);
}

stopAllJobs() {
var message = new OSC.Message('/stop-all-jobs', this.guiUuid);
this.sendOsc(message);
}
Expand Down

0 comments on commit 79232ac

Please sign in to comment.