Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Aug 12, 2023
1 parent 747cfb0 commit 6d41485
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8785,7 +8785,7 @@ DOUBLE CLICK THIS to set Hotkey. Suggested Hotkey: cmd + shift + 1</string>
<true/>
</dict>
<key>description</key>
<string>vault-relative path to your Scratchpad Note. When you append `#foobar`, the text will be added below the heading "foobar" located in that note.</string>
<string>Vault-relative path to your Scratchpad Note. When you append `#foobar`, the text will be appended to the section with the heading "foobar".</string>
<key>label</key>
<string>Scratchpad Note Path</string>
<key>type</key>
Expand Down
19 changes: 10 additions & 9 deletions scripts/append-to-note.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ function run(argv) {
let relativePath = $.getenv("relative_path");
const toAppend = $.getenv("prefix") + argv[0];

const noteHasHeading = /#[^ ][^/]*$/.test(relativePath);
if (noteHasHeading) {
const notePathHasHeading = /#[^ ][^/]*$/.test(relativePath);
if (notePathHasHeading) {
const tempArr = relativePath.split("#");
heading = tempArr.pop();
relativePath = tempArr.join("");
Expand All @@ -64,7 +64,7 @@ function run(argv) {
//───────────────────────────────────────────────────────────────────────────
// APPEND TO FILE

if (!noteHasHeading) {
if (!notePathHasHeading) {
writeToFile(absolutePath, noteContent + "\n" + toAppend);
return relativePath; // return for opening function
}
Expand All @@ -79,27 +79,28 @@ function run(argv) {
})
.indexOf(heading);

// guard: heading not found
if (headingLineNo === -1) {
console.log("Heading not found. Appending to the bottom of the note instead.");
app.displayNotification("", { withTitle: "Heading not found.", subtitle: "Appending to the bottom of the note instead." })
writeToFile(absolutePath, noteContent + "\n" + toAppend);
return relativePath; // return for opening function
}

// Appending
// Appending at last non-empty line of heading-section
let lastNonEmptyLineNo = -1;
for (let i = headingLineNo + 1; i < lines.length; i++) {
const line = lines[i];
if (isHeading(line)) break;
else if (!isEmpty(line)) lastNonEmptyLineNo = i;
}
if (lastNonEmptyLineNo > 0) {
lines.splice(lastNonEmptyLineNo + 1, 0, toAppend);
} else {
if (lastNonEmptyLineNo === -1) {
ensureEmptyLineAt(lines, headingLineNo + 1);
lines.splice(headingLineNo + 2, 0, toAppend);
ensureEmptyLineAt(lines, headingLineNo + 3);
} else {
lines.splice(lastNonEmptyLineNo + 1, 0, toAppend);
}
const content = lines.join("\n") + "\n";
const content = lines.join("\n");
writeToFile(absolutePath, content);

return relativePath; // return for opening function
Expand Down
14 changes: 0 additions & 14 deletions scripts/browse-note-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,6 @@ function run() {
if (!fileExists(recentJSON)) recentJSON = recentJSON.slice(0, -5); // Obsidian 0.16 uses workspace.json → https://discord.com/channels/686053708261228577/716028884885307432/1013906018578743478
const superIconFile = $.getenv("supercharged_icon_file");

//───────────────────────────────────────────────────────────────────────────
// GUARD: metadata does not exist since user has not run `osetup`
if (!fileExists(metadataJSON)) {
return JSON.stringify({
items: [
{
title: "⚠️ No vault metadata found.",
subtitle: "Please run the Alfred command `osetup` first. This only has to be done once.",
valid: false,
},
],
});
}

//───────────────────────────────────────────────────────────────────────────

// ICONS
Expand Down

0 comments on commit 6d41485

Please sign in to comment.