Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm: watch"
"preLaunchTask": "watch"
}
]
}
5 changes: 5 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"kind": "build",
"isDefault": true
}
},
{
"type": "npm",
"script": "build:watch",
"problemMatcher": []
}
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"test": "jest --passWithNoTests",
"test:watch": "jest --watch --passWithNoTests",
"vscode:prepublish": "npm run build",
"watch": "tsc -watch -p ./"
"watch": "npm run build:watch"
},
"devDependencies": {
"@semantic-release/changelog": "^3.0.2",
Expand Down
1 change: 1 addition & 0 deletions src/tag-tree-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface IFileInfo {

class TagTreeDataProvider
implements vscode.TreeDataProvider<TagNode | FileNode> {

private tagTree: TagTree;
// Responsible for notifying the TreeDataProvider to update for the specified element in tagTree
private _onDidChangeTreeData: vscode.EventEmitter< TagNode | FileNode | null> = new vscode.EventEmitter<TagNode | FileNode | null>();
Expand Down
20 changes: 2 additions & 18 deletions src/tag-tree/__snapshots__/tag-tree.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,7 @@ exports[`TagTree deleteFile Delete file under shared tag with empty node 1`] = `
tags: [ 'hello' ] } },
pathToNode: 'hello',
tag: 'hello',
tags:
Map {
'world' => TagNode {
parent: [Circular],
displayName: 'world',
files: Map {},
pathToNode: 'hello/world',
tag: 'world',
tags: Map {} } } } } },
tags: Map {} } } },
fileIndex:
Map {
'|Users|test|bar.md' => [ TagNode {
Expand All @@ -426,15 +418,7 @@ exports[`TagTree deleteFile Delete file under shared tag with empty node 1`] = `
tags: [ 'hello' ] } },
pathToNode: 'hello',
tag: 'hello',
tags:
Map {
'world' => TagNode {
parent: [Circular],
displayName: 'world',
files: Map {},
pathToNode: 'hello/world',
tag: 'world',
tags: Map {} } } } ] } }"
tags: Map {} } ] } }"
`;

exports[`TagTree deleteFile Delete node under root 1`] = `
Expand Down
13 changes: 13 additions & 0 deletions src/tag-tree/tag-tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ describe("TagTree", () => {
tagTree.deleteFile(filePath);
expect(createDeepSnapshot(tagTree)).toMatchSnapshot();
});

test("Move tag tree from one top level node to another", () => {
const tagTree = new TagTree();
const filePath = "/Users/test/foo.md";
tagTree.addFile(filePath, ["hello/world"], "foo.md");
tagTree.deleteFile(filePath);
tagTree.addFile(filePath, ["goodbye/world"], "foo.md");
const tag = tagTree.root.getTag("hello");
const renamedTag = tagTree.root.getTag("goodbye");

expect(tag).toBeUndefined();
expect(renamedTag).toBeDefined();
});
});
describe("getTagsForFile", () => {
test("Retrieves all tags for a file", () => {
Expand Down
4 changes: 3 additions & 1 deletion src/tag-tree/tag-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ class TagTree {

while (currentNode!.files.size === 0 && currentNode!.tags.size === 0) {
const { parent } = currentNode;
// We're not at the root of the tree yet
if (parent !== null) {
parent!.deleteTag(node.tag);
parent!.deleteTag(currentNode.tag);
// @ts-ignore
currentNode = parent;
// At this point we've hit the root of the tree
} else {
break;
}
Expand Down