Skip to content

Commit

Permalink
chore: copy to clipboard util
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed May 30, 2024
1 parent 2ffa1f6 commit 38550ae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/views/TemplateBuilderModal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { App, Modal } from "obsidian";
import { TemplateBuilderModel } from "./components/TemplateBuilder";
import TemplateBuilder from "./components/TemplateBuilder.svelte";
import { copyToClipboard } from "./copyToClipboard";
/**
* This class is just the minimum glue code to bind our core logic
* with the svelte UI and obsidian API modal.
Expand All @@ -23,7 +24,7 @@ export class TemplateBuilderModal extends Modal {
const { contentEl } = this;
this._component = new TemplateBuilder({
target: contentEl,
props: { model: this.deps },
props: { model: this.deps, copyToClipboard },
});
}
}
14 changes: 2 additions & 12 deletions src/views/TemplateBuilderView.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import { ItemView, Notice, ViewStateResult, WorkspaceLeaf } from "obsidian";
import { ItemView, ViewStateResult, WorkspaceLeaf } from "obsidian";
import { FormDefinition } from "src/core/formDefinition";
import ModalFormPlugin from "src/main";
import { makeModel } from "./components/TemplateBuilder";
import TemplateBuilder from "./components/TemplateBuilder.svelte";

function copyToClipboard(text: string) {
navigator.clipboard.writeText(text).then(
() => {
new Notice("Template has been copied to the clipboard");
},
(err) => {
console.error("Could not copy text: ", err);
},
);
}
import { copyToClipboard } from "./copyToClipboard";

export const TEMPLATE_BUILDER_VIEW = "modal-form-template-builder-view";
/**
Expand Down
12 changes: 12 additions & 0 deletions src/views/copyToClipboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Notice } from "obsidian";

export function copyToClipboard(text: string) {
navigator.clipboard.writeText(text).then(
() => {
new Notice("Template has been copied to the clipboard");
},
(err) => {
console.error("Could not copy text: ", err);
},
);
}

0 comments on commit 38550ae

Please sign in to comment.