mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 14:34:13 +08:00
ctrl+space 快速 console.log
This commit is contained in:
parent
adfc2b5130
commit
ac3a1e235a
@ -368,8 +368,9 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
// 运行
|
// 运行
|
||||||
runCurrentCommand() {
|
runCurrentCommand(cmd) {
|
||||||
let command = _.cloneDeep(this.quickcommandInfo);
|
let command = _.cloneDeep(this.quickcommandInfo);
|
||||||
|
if (cmd) command.cmd = cmd;
|
||||||
command.output =
|
command.output =
|
||||||
this.$refs.sidebar?.currentCommand.output ||
|
this.$refs.sidebar?.currentCommand.output ||
|
||||||
(command.program === "html" ? "html" : "text");
|
(command.program === "html" ? "html" : "text");
|
||||||
@ -382,7 +383,7 @@ export default {
|
|||||||
command.cursorPosition = this.$refs.editor.getCursorPosition();
|
command.cursorPosition = this.$refs.editor.getCursorPosition();
|
||||||
this.$root.utools.putDB(command, "cfg_codeHistory");
|
this.$root.utools.putDB(command, "cfg_codeHistory");
|
||||||
},
|
},
|
||||||
monacoKeyStroke(event) {
|
monacoKeyStroke(event, data) {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case "run":
|
case "run":
|
||||||
this.runCurrentCommand();
|
this.runCurrentCommand();
|
||||||
@ -390,6 +391,10 @@ export default {
|
|||||||
case "save":
|
case "save":
|
||||||
this.saveCurrentCommand();
|
this.saveCurrentCommand();
|
||||||
break;
|
break;
|
||||||
|
case "log":
|
||||||
|
if (this.quickcommandInfo.program !== "quickcommand") return;
|
||||||
|
this.runCurrentCommand(`console.log(${data})`);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,9 @@
|
|||||||
:textbtn="!enableHtml"
|
:textbtn="!enableHtml"
|
||||||
:imagebtn="!enableHtml && isDataUrl"
|
:imagebtn="!enableHtml && isDataUrl"
|
||||||
@showImg="showBase64Img"
|
@showImg="showBase64Img"
|
||||||
|
:style="{
|
||||||
|
height: headerHeight + 'px',
|
||||||
|
}"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@ -143,17 +146,12 @@ export default {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
utools.outPlugin();
|
utools.outPlugin();
|
||||||
}, 500);
|
}, 500);
|
||||||
|
let resultOpts = { outPlugin, action, earlyExit };
|
||||||
switch (currentCommand.program) {
|
switch (currentCommand.program) {
|
||||||
case "quickcommand":
|
case "quickcommand":
|
||||||
window.runCodeInSandbox(
|
window.runCodeInSandbox(
|
||||||
currentCommand.cmd,
|
currentCommand.cmd,
|
||||||
(stdout, stderr) => {
|
(stdout, stderr) => this.handleResult(stdout, stderr, resultOpts),
|
||||||
this.handleResult(stdout, stderr, {
|
|
||||||
outPlugin,
|
|
||||||
action,
|
|
||||||
earlyExit,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
{ enterData: this.$root.enterData }
|
{ enterData: this.$root.enterData }
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
@ -165,13 +163,7 @@ export default {
|
|||||||
currentCommand.cmd,
|
currentCommand.cmd,
|
||||||
this.getCommandOpt(currentCommand),
|
this.getCommandOpt(currentCommand),
|
||||||
currentCommand.output === "terminal",
|
currentCommand.output === "terminal",
|
||||||
(stdout, stderr) => {
|
(stdout, stderr) => this.handleResult(stdout, stderr, resultOpts)
|
||||||
this.handleResult(stdout, stderr, {
|
|
||||||
outPlugin,
|
|
||||||
action,
|
|
||||||
earlyExit,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
this.listenStopSign();
|
this.listenStopSign();
|
||||||
break;
|
break;
|
||||||
|
@ -232,6 +232,27 @@ export default {
|
|||||||
that.$emit("keyStroke", "save");
|
that.$emit("keyStroke", "save");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
// ctrl + space 快速 console.log
|
||||||
|
this.rawEditor.addCommand(
|
||||||
|
monaco.KeyMod.CtrlCmd | monaco.KeyCode.Space,
|
||||||
|
() => {
|
||||||
|
that.$emit("keyStroke", "log", that.getSelectionOrLineContent());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
getSelectionOrLineContent() {
|
||||||
|
let selection = this.rawEditor.getSelection();
|
||||||
|
let range = new monaco.Range(
|
||||||
|
selection.startLineNumber,
|
||||||
|
selection.startColumn,
|
||||||
|
selection.endLineNumber,
|
||||||
|
selection.endColumn
|
||||||
|
);
|
||||||
|
let model = this.rawEditor.getModel();
|
||||||
|
return (
|
||||||
|
model.getValueInRange(range) ||
|
||||||
|
model.getLineContent(selection.startLineNumber)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
beforeUnmount() {
|
beforeUnmount() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user