Skip to content

Commit

Permalink
fix(CreateIndex): 🐛 deep clone allPaths to mutate the copy instead
Browse files Browse the repository at this point in the history
I was mutating `allPaths`, so the index got shorter by 1 level each time the button was pressed
  • Loading branch information
SkepticMystic committed Jul 21, 2021
1 parent 300ebf1 commit 664db77
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-typescript": "^8.2.1",
"@types/graphlib": "^2.1.7",
"@types/lodash": "^4.14.171",
"@types/node": "^14.14.37",
"@typescript-eslint/eslint-plugin": "^4.27.0",
"@typescript-eslint/parser": "^4.27.0",
Expand Down
8 changes: 6 additions & 2 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Graph } from "graphlib";
import { cloneDeep } from "lodash";
import { ItemView, TFile, WorkspaceLeaf } from "obsidian";
import { closeImpliedLinks, copyToClipboard, debug } from "src/sharedFunctions";
import {
Expand Down Expand Up @@ -132,7 +133,8 @@ export default class MatrixView extends ItemView {
currFile: string,
settings: BreadcrumbsSettings
): string {
const reversed = allPaths.map((path) => path.reverse());
const copy = cloneDeep(allPaths);
const reversed = copy.map((path) => path.reverse());
reversed.forEach((path) => path.shift());

let txt = currFile + "\n";
Expand Down Expand Up @@ -194,7 +196,9 @@ export default class MatrixView extends ItemView {
text: "Create Index ⚠️",
});
createIndexButton.addEventListener("click", () => {
copyToClipboard(this.createIndex(allPaths, currFile.basename, settings));
const index = this.createIndex(allPaths, currFile.basename, settings);
debug(settings, { index });
copyToClipboard(index);
});

const [parentFieldName, siblingFieldName, childFieldName] = [
Expand Down

0 comments on commit 664db77

Please sign in to comment.