mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-29 12:22:44 +08:00
新增 listenKeydown
This commit is contained in:
parent
f99123518a
commit
e260d14a36
@ -55,7 +55,8 @@ export default {
|
||||
runResult: "",
|
||||
runResultStatus: true,
|
||||
subInputValue: "",
|
||||
listener: null,
|
||||
subInputListener: null,
|
||||
quickcommandListener: null,
|
||||
history: [],
|
||||
historyIdx: null,
|
||||
enableHtml: false,
|
||||
@ -171,7 +172,7 @@ export default {
|
||||
setTimeout(() => {
|
||||
if (this.subInputValue) querySubInput();
|
||||
}, 100);
|
||||
this.listener = (event) => {
|
||||
this.subInputListener = (event) => {
|
||||
event.preventDefault();
|
||||
switch (event.keyCode) {
|
||||
case 13:
|
||||
@ -193,7 +194,7 @@ export default {
|
||||
break;
|
||||
}
|
||||
};
|
||||
document.addEventListener("keydown", this.listener, true);
|
||||
document.addEventListener("keydown", this.subInputListener, true);
|
||||
},
|
||||
// payload 临时赋值
|
||||
async getTempPayload(currentCommand) {
|
||||
@ -243,15 +244,24 @@ export default {
|
||||
}
|
||||
quickcommand.closeWaitBtn?.();
|
||||
quickcommand.closeWaitBtn = () => {};
|
||||
if (!!this.listener) {
|
||||
if (!!this.subInputListener) {
|
||||
this.subInputValue = "";
|
||||
utools.removeSubInput();
|
||||
document.removeEventListener("keydown", this.listener, true);
|
||||
document.removeEventListener("keydown", this.subInputListener, true);
|
||||
}
|
||||
if (!!this.quickcommandListener) {
|
||||
document.removeEventListener("keydown", this.quickcommandListener);
|
||||
}
|
||||
},
|
||||
},
|
||||
unmounted() {
|
||||
this.stopRun();
|
||||
},
|
||||
mounted() {
|
||||
quickcommand.listenKeydown = (callback) => {
|
||||
this.quickcommandListener = callback;
|
||||
document.addEventListener("keydown", callback);
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
17
src/plugins/monaco/types/quickcommand.api.d.ts
vendored
17
src/plugins/monaco/types/quickcommand.api.d.ts
vendored
@ -170,13 +170,28 @@ interface quickcommandApi {
|
||||
* @param callback 点击后的回调
|
||||
* @param label 按钮的标题
|
||||
*/
|
||||
showWaitButton(callback, label?: string): void;
|
||||
showWaitButton(callback: () => void, label?: string): void;
|
||||
|
||||
/**
|
||||
* 关掉现有等待操作按钮
|
||||
*/
|
||||
closeWaitBtn(): void;
|
||||
|
||||
/**
|
||||
* 监听用户按键,并执行回调函数
|
||||
*
|
||||
* ```js
|
||||
* quickcommand.listenKeydown(e=>{
|
||||
* if(e.key === 'c' && e.ctrlKey){
|
||||
* console.log("取消")
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @param callback 按键回调函数
|
||||
*/
|
||||
listenKeydown(callback: (event) => void): void;
|
||||
|
||||
/**
|
||||
* 同步等待,会阻塞进程
|
||||
* @param ms 等待的毫秒数
|
||||
|
Loading…
x
Reference in New Issue
Block a user