Skip to content

Commit

Permalink
refactor: ♻️ copy function
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Aug 3, 2021
1 parent 8c71661 commit 2740784
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 3 additions & 9 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
d3Graph,
} from "src/interfaces";
import type BreadcrumbsPlugin from "src/main";
import { closeImpliedLinks, debug } from "src/sharedFunctions";
import { closeImpliedLinks, copy, debug } from "src/sharedFunctions";
import Lists from "./Components/Lists.svelte";
import Matrix from "./Components/Matrix.svelte";

Expand Down Expand Up @@ -55,10 +55,7 @@ export default class MatrixView extends ItemView {
);
const index = this.createIndex(currFile + "\n", allPaths, settings);
debug(settings, { index });
await navigator.clipboard.writeText(index).then(
() => new Notice("Index copied to clipboard"),
() => new Notice("Could not copy index to clipboard")
);
await copy(index);
},
});

Expand All @@ -81,10 +78,7 @@ export default class MatrixView extends ItemView {
});

debug(settings, { globalIndex });
await navigator.clipboard.writeText(globalIndex).then(
() => new Notice("Index copied to clipboard"),
() => new Notice("Could not copy index to clipboard")
);
await copy(globalIndex);
},
});
}
Expand Down
10 changes: 9 additions & 1 deletion src/sharedFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { Graph } from "graphlib";
import * as graphlib from "graphlib";
import { parseTypedLink } from "juggl-api";
import type {
import {
App,
FrontMatterCache,
Notice,
Pos,
TFile,
WorkspaceLeaf,
Expand Down Expand Up @@ -406,3 +407,10 @@ export const range = (n: number) => [...Array(5).keys()];
export function complement<T>(A: T[], B: T[]) {
return A.filter((a) => !B.includes(a));
}

export async function copy(content: string) {
await navigator.clipboard.writeText(content).then(
() => new Notice("Copied to clipboard"),
() => new Notice("Could not copy to clipboard")
);
}

0 comments on commit 2740784

Please sign in to comment.