From b33f4b16eb7ba48b559d9172d26e783f5495212b Mon Sep 17 00:00:00 2001 From: fofolee Date: Wed, 20 Apr 2022 13:00:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=90=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=A1=86=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CommandRunResult.vue | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/components/CommandRunResult.vue b/src/components/CommandRunResult.vue index 276c0b1..b6e80ed 100644 --- a/src/components/CommandRunResult.vue +++ b/src/components/CommandRunResult.vue @@ -60,7 +60,7 @@ export default { subInputValue: "", listener: null, history: [], - historyIdx: 1, + historyIdx: null, }; }, props: { @@ -147,7 +147,7 @@ export default { setSubInput(currentCommand) { this.fromUtools && utools.setExpendHeight(0); let matched = specialVars.subinput.match.exec(currentCommand.cmd); - let placeholder = matched[1] || "回车键执行命令,方向键上下切换历史"; + let placeholder = matched[1] || "↩ 执行命令,↑↓ 切换历史"; utools.setSubInput(({ text }) => { this.subInputValue = text; }, placeholder); @@ -158,6 +158,7 @@ export default { this.subInputValue ); this.history.push(this.subInputValue); + this.historyIdx = this.history.length; utools.setSubInputValue(""); this.fire(command); }; @@ -173,20 +174,16 @@ export default { break; case 38: if (!this.history.length) break; - this.historyIdx = Math.min( - this.history.length + 1, - this.historyIdx + 1 - ); - utools.setSubInputValue( - this.history[this.history.length - this.historyIdx + 1] - ); + this.historyIdx = Math.max(0, this.historyIdx - 1); + utools.setSubInputValue(this.history[this.historyIdx] || ""); break; case 40: - if (this.historyIdx === 1) break; - this.historyIdx = Math.max(1, this.historyIdx - 1); - utools.setSubInputValue( - this.history[this.history.length - this.historyIdx] + if (this.historyIdx === this.history.length) break; + this.historyIdx = Math.min( + this.history.length - 1, + this.historyIdx + 1 ); + utools.setSubInputValue(this.history[this.historyIdx] || ""); default: break; }