Skip to content

Commit

Permalink
确保在同一局游戏中自定义视图的排序稳定
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jun 11, 2024
1 parent d63834e commit 7e3e9bf
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/console/treeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export class TreeViewManager extends vscode.Disposable {
readonly treeDataProvider: TreeDataProvider;

readonly treeViews = new Array<TreeView>();
readonly treeOrder = new Map<string, number>();

// 从客户端中获取节点信息
async requestGetTreeNode(id: number): Promise<getTreeNodeResponse|undefined> {
Expand All @@ -182,6 +183,13 @@ export class TreeViewManager extends vscode.Disposable {
async createTreeView(id: number, name: string, root: number) {
let treeView = new TreeView(this, id, name, root);
this.treeViews.push(treeView);
if (this.treeOrder.has(name)) {
this.treeViews.sort((a, b) => {
return this.treeOrder.get(a.name)! - this.treeOrder.get(b.name)!;
});
} else {
this.treeOrder.set(name, this.treeOrder.size);
}
this.treeDataProvider.refresh(undefined);
return treeView;
}
Expand Down

0 comments on commit 7e3e9bf

Please sign in to comment.