Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put placeholder at cusor #93

Merged
merged 2 commits into from
Mar 6, 2024
Merged
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
22 changes: 12 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export default class CloudAtlasPlugin extends Plugin {
console.log("Running flow: ", flow);
const inputFlowFile = this.app.workspace.getActiveFile();

if (!inputFlowFile) {
if (!inputFlowFile || !editor) {
console.debug("No active file");
new Notice("No active file in the editor, open one and try again.");
return null;
Expand All @@ -334,21 +334,23 @@ export default class CloudAtlasPlugin extends Plugin {
const input = editor?.getSelection();
const fromSelection = Boolean(input);

if (fromSelection) {
editor?.replaceSelection(
if (fromSelection) {
editor.replaceSelection(
input +
"\n\n---\n\n" +
`\u{1F4C4}\u{2194}\u{1F916}` +
"\n\n---\n\n"
);
} else {
const current = await this.app.vault.read(inputFlowFile);
const output =
current +
"\n\n---\n\n" +
`\u{1F4C4}\u{2194}\u{1F916}` +
"\n\n---\n\n";
await this.app.vault.modify(inputFlowFile, output);
// Create the placeholder content to be inserted
const curCursor = editor.getCursor();
const placeholderContent =
"\n\n---\n\n" +
`\u{1F4C4}\u{2194}\u{1F916}` +
"\n\n---\n\n";

// Insert the placeholder content at the cursor position
editor.replaceRange(placeholderContent, curCursor);
}

const notice = new Notice(`Running ${flow} flow ...`, 0);
Expand Down
Loading