From 3fa62f9f2950b00c2956c10bb16ee8b684d1157a Mon Sep 17 00:00:00 2001 From: fofolee Date: Thu, 25 Jun 2020 20:15:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=BE=93=E5=87=BA=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=BB=9A=E5=8A=A8=E5=92=8C=E8=87=AA=E5=8A=A8=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E9=AB=98=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/index.js | 46 ++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/assets/index.js b/src/assets/index.js index a982b9c..2b84f8b 100644 --- a/src/assets/index.js +++ b/src/assets/index.js @@ -1,4 +1,5 @@ utools.onPluginEnter(async ({ code, type, payload }) => { + var handleEnter utools.onPluginOut(() => { if (code == "code") { var cmd = window.editor.getValue(); @@ -13,8 +14,12 @@ utools.onPluginEnter(async ({ code, type, payload }) => { } putDB('history', { cmd: cmd, program: program, scptarg: scptarg, customoptions: customoptions }, 'codeHistory') } + // 初始化 $("#options").empty() $("#out").empty() + $("#quickselect").remove() + swal.close() + if(handleEnter) document.removeEventListener('keydown', handleEnter) }) // 配置页面 if (code == 'options') { @@ -23,7 +28,7 @@ utools.onPluginEnter(async ({ code, type, payload }) => { showOptions(); } else if (code == 'code') { var file = "" - utools.setExpendHeight(600); + // utools.setExpendHeight(600); if (type == 'files') file = payload[0].path showCodeEditor(file) } else { @@ -75,58 +80,57 @@ utools.onPluginEnter(async ({ code, type, payload }) => { subinput = text; }, ''); } - var handleEnter = (event) => { + handleEnter = (event) => { if (event.keyCode == 13) { - $("#out").empty(); + $("#out").append('\n-------------------------------------\n\n'); var execmd = cmd.replace(/\{\{subinput\}\}/mg, subinput); - runQuickCommand(execmd, option, db.output); + runQuickCommand(execmd, option, db.output, true); } }; setSubInput(); document.addEventListener('keydown', handleEnter); - // 移除监听 - utools.onPluginOut(() => { - document.removeEventListener('keydown', handleEnter); - }) } else { - runQuickCommand(cmd, option, db.output); + runQuickCommand(cmd, option, db.output, false); } } }); -let runQuickCommand = (cmd, option, output) => { +let runQuickCommand = (cmd, option, output, autoScroll = false, autoHeight = true) => { // 不需要输出的,提前关闭窗口 if (['ignore', 'clip', 'send', 'notice', 'terminal'].indexOf(output) !== -1) { utools.hideMainWindow(); - setTimeout(() => { - utools.outPlugin(); - }, 500); + setTimeout(() => { utools.outPlugin(); }, 500); } - var maxheight = true if (option == "simulation") { // 内置环境 runCodeInVm(cmd, (stdout, stderr) => { - if (cmd.includes("utools.setExpendHeight")) maxheight = false - switchQuickCommandResult(stdout, stderr, output, maxheight) + if (cmd.includes("utools.setExpendHeight")) autoHeight = false + switchQuickCommandResult(stdout, stderr, output, autoScroll, autoHeight) }) } else { var terminal = output == 'terminal' ? true : false // 执行脚本 runCodeFile(cmd, option, terminal, (stdout, stderr) => { - switchQuickCommandResult(stdout, stderr, output, maxheight) + switchQuickCommandResult(stdout, stderr, output, autoScroll, autoHeight) }) } } -switchQuickCommandResult = (stdout, stderr, output, maxheight) => { +switchQuickCommandResult = (stdout, stderr, output, autoScroll, autoHeight) => { + var outputAutoFix = (autoScroll, autoHeight) => { + var outputHeight = $("#out").height() + 26 + if (outputHeight > 600) outputHeight = 600 + if (autoHeight) utools.setExpendHeight(outputHeight); + if (outputHeight == 600 && autoScroll) $(document).scrollTop($(document).height()); + } if (stderr) { $("#out").addClass('error') // 报错 if (output == 'text' || output == 'html') { - utools.setExpendHeight(600); $("#out").append(stderr) + outputAutoFix(autoScroll, autoHeight) } else { var index = utools.showMessageBox({ type: 'error', @@ -146,12 +150,12 @@ switchQuickCommandResult = (stdout, stderr, output, maxheight) => { // 有输出 switch (output) { case "text": - if(maxheight) utools.setExpendHeight(600); $("#out").append(htmlEncode(stdout, true)) + outputAutoFix(autoScroll, autoHeight) break; case "html": - if(maxheight) utools.setExpendHeight(600); $("#out").append(stdout) + outputAutoFix(autoScroll, autoHeight) break; case "clip": copyTo(stdout)