Skip to content

Commit

Permalink
Added meta+alt+click to copy current line as an option (see settings).
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan J.A. Murphy committed Nov 10, 2020
1 parent a079dc9 commit ada1143
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
66 changes: 35 additions & 31 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,38 +349,41 @@ export default class WorkbenchPlugin extends Plugin {

let clickType = this.settings.metaAltClickType;

let linkPrefix = "";

if (clickType === "Embed") {
linkPrefix = "!";
}

if (lineText != "") {

console.log("Checking for block:");
if (this.getBlock(lineText, currentNoteFile) === "") { // The line is not already a block
lineText = lineText.trim();
console.log("This line is not currently a block. Adding a block ID.");
lineBlockID = this.createBlockHash(lineText).toString();
let lineWithBlock = lineText + " ^" + lineBlockID;
obsidianApp.vault.read(currentNoteFile).then(function (result) {
let previousNoteText = result;
let newNoteText = previousNoteText.replace(lineText, lineWithBlock);
obsidianApp.vault.modify(currentNoteFile, newNoteText);
})

if (clickType === "Copy") {
let newMaterial = lineText;
this.saveToWorkbench(newMaterial, "a copy of the selected line/block");
} else {
let lineBlockID = this.getBlock(lineText, currentNoteFile);
console.log(lineBlockID);
}

let newMaterial = linkPrefix + "[[" + noteLink + "#^" + lineBlockID + "]]";
console.log(newMaterial);
this.saveToWorkbench(newMaterial, "a link to the selected block");
let linkPrefix = "";

if (clickType === "Embed") {
linkPrefix = "!";
}

console.log("Checking for block:");
if (this.getBlock(lineText, currentNoteFile) === "") { // The line is not already a block
lineText = lineText.trim();
console.log("This line is not currently a block. Adding a block ID.");
lineBlockID = this.createBlockHash(lineText).toString();
let lineWithBlock = lineText + " ^" + lineBlockID;
obsidianApp.vault.read(currentNoteFile).then(function (result) {
let previousNoteText = result;
let newNoteText = previousNoteText.replace(lineText, lineWithBlock);
obsidianApp.vault.modify(currentNoteFile, newNoteText);
})
} else {
let lineBlockID = this.getBlock(lineText, currentNoteFile);
console.log(lineBlockID);
}

let newMaterial = linkPrefix + "[[" + noteLink + "#^" + lineBlockID + "]]";
console.log(newMaterial);
this.saveToWorkbench(newMaterial, "a link to the selected line/block");
}
} else {
new Notice("There is nothing on the selected line.");
}


}

linkNoteInWorkbench() { // Saves a link to the current note to the workbench
Expand Down Expand Up @@ -616,8 +619,8 @@ class WorkbenchSettingTab extends PluginSettingTab {
.setDesc('Set what happens when you alt+click on a link. Default is to copy the link into the Workbench. Note: if your cursor is not already on the targeted line, you may need to double-click!')
.addDropdown(dropDown =>
dropDown
.addOption("Link", "Link")
.addOption("Embed", "Embed")
.addOption("Link", "Link selected note in Workbench")
.addOption("Embed", "Embed selected note in Workbench")
.addOption("Nothing", "Nothing")
.setValue(plugin.settings.altClickType)
.onChange((value: string) => {
Expand All @@ -631,8 +634,9 @@ class WorkbenchSettingTab extends PluginSettingTab {
.setDesc('Set what happens when you cmd/ctrl+alt+click on a line. Default is to link the line as a block into the Workbench. Note: if your cursor is not already on the targeted line, you may need to double-click!')
.addDropdown(dropDown =>
dropDown
.addOption("Link", "Link")
.addOption("Embed", "Embed")
.addOption("Link", "Link block")
.addOption("Embed", "Embed block")
.addOption("Copy", "Copy line")
.addOption("Nothing", "Nothing")
.setValue(plugin.settings.metaAltClickType)
.onChange((value: string) => {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "workbench-obsidian",
"name": "Workbench",
"version": "1.2.0",
"version": "1.3.0",
"description": "Keep a workbench of knowledge materials.",
"author": "ryanjamurphy",
"authorUrl": "axle.design",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "workbench-obsidian",
"version": "1.2.0",
"version": "1.3.0",
"description": "Keep a workbench of knowledge materials.",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit ada1143

Please sign in to comment.