Skip to content

Commit

Permalink
事件防抖
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Mar 28, 2024
1 parent 87812f9 commit 093c541
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ class EnvPath {
}
}

private _timer?: NodeJS.Timeout;
private fireOnDidReload() {
if (this._timer) {
return;
}
this._timer = setTimeout(() => {
this._timer = undefined;
this.reloadEmitter.fire();
}, 100);
}

@rePrepare
public async updateEditor(askUser = false) {
let editorUri = await this.searchEditorUri(askUser);
Expand All @@ -270,6 +281,7 @@ class EnvPath {
tools.log.info(`editorUri: ${this.editorUri?.fsPath}`);
tools.log.info(`editorExeUri: ${this.editorExeUri?.fsPath}`);
tools.log.info(`editorVersion: ${this.editorVersion}`);
this.fireOnDidReload();
}

public async editorReady(askUser = false) {
Expand Down Expand Up @@ -299,6 +311,7 @@ class EnvPath {
tools.log.info(`scriptUri: ${this.scriptUri?.fsPath}`);
tools.log.info(`y3Uri: ${this.y3Uri?.fsPath}`);
tools.log.info(`editorTableUri: ${this.editorTableUri?.fsPath}`);
this.fireOnDidReload();
}

public async mapReady(askUser = false) {
Expand All @@ -311,7 +324,7 @@ class EnvPath {
public reload() {
this.mapUri = undefined;
this.editorUri = undefined;
this.reloadEmitter.fire();
this.fireOnDidReload();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Helper {

private registerCommonCommands() {
vscode.commands.registerCommand('y3-helper.reloadEnv', async () => {
env.reload();
env.updateMap(true);
});
vscode.commands.registerCommand('y3-helper.shell', async (...args: any[]) => {
runShell("执行命令", args[0], args.slice(1));
Expand Down

0 comments on commit 093c541

Please sign in to comment.