Skip to content

Commit

Permalink
Present recent dirs in last access order
Browse files Browse the repository at this point in the history
Fixes #141008
  • Loading branch information
Tyriar committed Feb 23, 2022
1 parent deae6b4 commit 5d5d715
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export class CwdDetectionCapability {
private _cwds = new Map</*cwd*/string, /*frequency*/number>();

/**
* Gets the list of cwds seen in this session in order of descending frequency.
* Gets the list of cwds seen in this session in order of last accessed.
*/
get cwds(): string[] {
return Array.from(Array.from(this._cwds.entries()).sort((a, b) => b[1] - a[1])).map(s => s[0]);
return Array.from(this._cwds.keys());
}

private readonly _onDidChangeCwd = new Emitter<string>();
Expand All @@ -28,7 +28,9 @@ export class CwdDetectionCapability {
updateCwd(cwd: string): void {
const didChange = this._cwd !== cwd;
this._cwd = cwd;
this._cwds.set(this._cwd, (this._cwds.get(this._cwd) || 0) + 1);
const count = this._cwds.get(this._cwd) || 0;
this._cwds.delete(this._cwd); // Delete to put it at the bottom of the iterable
this._cwds.set(this._cwd, count + 1);
if (didChange) {
this._onDidChangeCwd.fire(cwd);
}
Expand Down

0 comments on commit 5d5d715

Please sign in to comment.