Skip to content

Commit

Permalink
fix: capture to active line captured to anywhere but active line - no…
Browse files Browse the repository at this point in the history
…w fixed

fix #439 #196
  • Loading branch information
chhoumann committed Apr 4, 2023
1 parent e566d35 commit 107c9e1
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/engine/CaptureChoiceEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ export class CaptureChoiceEngine extends QuickAddChoiceEngine {
return;
}

const { file, content: newFileContent } =
const { file, newFileContent, captureContent } =
await getFileAndAddContentFn(filePath, content);

await this.app.vault.modify(file, newFileContent);

if (this.choice.captureToActiveFile && !this.choice.prepend) {
appendToCurrentLine(captureContent, this.app);
} else {
await this.app.vault.modify(file, newFileContent);
}

if (this.choice.appendLink) {
const markdownLink = this.app.fileManager.generateMarkdownLink(
Expand Down Expand Up @@ -122,7 +127,7 @@ export class CaptureChoiceEngine extends QuickAddChoiceEngine {
private async onFileExists(
filePath: string,
content: string
): Promise<{ file: TFile; content: string }> {
): Promise<{ file: TFile; newFileContent: string, captureContent: string }> {
const file: TFile = this.getFileByPath(filePath);
if (!file) throw new Error("File not found");

Expand Down Expand Up @@ -160,13 +165,13 @@ export class CaptureChoiceEngine extends QuickAddChoiceEngine {
newFileContent = res.joinedResults() as string;
}

return { file, content: newFileContent };
return { file, newFileContent, captureContent: formatted };
}

private async onCreateFileIfItDoesntExist(
filePath: string,
content: string
): Promise<{ file: TFile; content: string }> {
captureContent: string
): Promise<{ file: TFile; newFileContent: string, captureContent: string }> {
let fileContent = "";

if (this.choice.createFileIfItDoesntExist.createWithTemplate) {
Expand All @@ -192,13 +197,13 @@ export class CaptureChoiceEngine extends QuickAddChoiceEngine {
);
const newFileContent: string =
await this.formatter.formatContentWithFile(
content,
captureContent,
this.choice,
updatedFileContent,
file
);

return { file, content: newFileContent };
return { file, newFileContent, captureContent };
}

private async formatFilePath(captureTo: string) {
Expand Down

1 comment on commit 107c9e1

@vercel
Copy link

@vercel vercel bot commented on 107c9e1 Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

quickadd – ./

quickadd-chrisbbh.vercel.app
quickadd-git-master-chrisbbh.vercel.app
quickadd.obsidian.guide

Please sign in to comment.