Skip to content

Commit

Permalink
A few refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan J.A. Murphy committed Jan 22, 2021
1 parent bc1b931 commit 25d9928
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
62 changes: 35 additions & 27 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { App, Modal, ItemView, Notice, Plugin, PluginSettingTab, Setting, WorkspaceLeaf, TFile, ToggleComponent, TextComponent, DropdownComponent, ButtonComponent } from 'obsidian';
import { App, Modal, ItemView, MarkdownView, Notice, Plugin, PluginSettingTab, Setting, WorkspaceLeaf, TFile, ToggleComponent, TextComponent, DropdownComponent, ButtonComponent, Workspace } from 'obsidian';
import { start } from 'repl';
import { createDailyNote } from 'obsidian-daily-notes-interface';
import * as moment from 'moment';

export default class MyVantagePlugin extends Plugin {
onload() {
Expand Down Expand Up @@ -80,28 +79,28 @@ export default class MyVantagePlugin extends Plugin {
}
}

openAnchorPane(someLeaf: WorkspaceLeaf) {
let obsidianApp = this.app;
let currentLeaf = someLeaf;
let editor = obsidianApp.workspace.activeLeaf.view.sourceMode.cmEditor;
let currentFile = currentLeaf.view.file;
let currentFileName = currentFile.basename;
let doc = editor.getDoc();
let cursor = editor.getCursor();
// openAnchorPane(someLeaf: WorkspaceLeaf) { // Old method for an old design
// let obsidianApp = this.app;
// let currentLeaf = someLeaf;
// let editor = obsidianApp.workspace.activeLeaf.view.sourceMode.cmEditor;
// let currentFile = currentLeaf.view.file;
// let currentFileName = currentFile.basename;
// let doc = editor.getDoc();
// let cursor = editor.getCursor();

console.log(obsidianApp.metadataCache.getFileCache(currentFile));
// console.log(obsidianApp.metadataCache.getFileCache(currentFile));

let theBacklinks = this.getBacklinks(currentFile);
// let theBacklinks = this.getBacklinks(currentFile);

//This successfully generates a list of links to the current note, including the start and end position of those links.
console.log(theBacklinks);
// //This successfully generates a list of links to the current note, including the start and end position of those links.
// console.log(theBacklinks);

// ☐ How do I get the plugin to notice when a new backlink has been added, and refresh the list?
// ☐ How do I display this list in a pane that can be customized/moved around?
// ☐ How do I make sure the items in this list are links to their source?
// ☑︎ How do I do the above with tags? Answer: use search, riffing off of MrJackPhil's expand embeds workflow. See getSearch above
// // ☐ How do I get the plugin to notice when a new backlink has been added, and refresh the list?
// // ☐ How do I display this list in a pane that can be customized/moved around?
// // ☐ How do I make sure the items in this list are links to their source?
// // ☑︎ How do I do the above with tags? Answer: use search, riffing off of MrJackPhil's expand embeds workflow. See getSearch above

}
// }


}
Expand Down Expand Up @@ -222,7 +221,6 @@ class VantageModal extends Modal {
tagInfoDiv.append(noteTagText);
let tagInput = contentEl.createEl("input", {"type": "text"});
tagControlDiv.append(tagInput);
// tagInput.setAttr("style", "float: right; width: 50%");
tagDiv.append(tagInfoDiv);
tagDiv.append(tagControlDiv);
vantageSettingsDiv.append(tagDiv);
Expand All @@ -243,7 +241,6 @@ class VantageModal extends Modal {
notesPathInfoDiv.append(notePathDescription);
let notesPathInput = contentEl.createEl("input", {"type": "text"});
notesPathControlDiv.append(notesPathInput);
// notesPathInput.setAttr("style", "float: right; width: 50%");
notesPathDiv.append(notesPathInfoDiv);
notesPathDiv.append(notesPathControlDiv);
vantageSettingsDiv.append(notesPathDiv);
Expand Down Expand Up @@ -572,17 +569,28 @@ class VantageModal extends Modal {
}
if (!(naturalLanguageDates.getFormattedDate(parsedStartDate.moment).contains("Invalid")) && !(naturalLanguageDates.getFormattedDate(parsedEndDate.moment).contains("Invalid"))) { // otherwise go ahead with the search
embeddedSearchQuery = embeddedSearchQueryHeader + setSearchQuery() + embeddedSearchQueryFooter;
let doc = this.app.workspace.activeLeaf.view.sourceMode.cmEditor.getDoc();
// let doc = this.app.workspace.activeLeaf.view.sourceMode.cmEditor.getDoc();
let view = this.app.workspace.getActiveViewOfType(MarkdownView);
if (!view) {
new Notice("No editable document is open. Perhaps you meant to click \"New search\"?");
return;
}
this.close();
let doc = view.sourceMode.cmEditor.getDoc();
let cursor = doc.getCursor();
doc.replaceRange(embeddedSearchQuery, cursor);
this.close();
}
} else { // no dates have been entered, so the search can continue
embeddedSearchQuery = embeddedSearchQueryHeader + setSearchQuery() + embeddedSearchQueryFooter;
let doc = this.app.workspace.activeLeaf.view.sourceMode.cmEditor.getDoc();
let cursor = doc.getCursor();
doc.replaceRange(embeddedSearchQuery, cursor);
this.close();
let view = this.app.workspace.getActiveViewOfType(MarkdownView);
if (!view) {
new Notice("No editable document is open. Perhaps you meant to click \"New search\"?");
return;
}
this.close();
let doc = view.sourceMode.cmEditor.getDoc();
let cursor = doc.getCursor();
doc.replaceRange(embeddedSearchQuery, cursor);
}

});
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-typescript": "^6.0.0",
"@types/node": "^14.14.2",
"@types/node": "^14.14.22",
"obsidian": "https://github.com/obsidianmd/obsidian-api/tarball/master",
"rollup": "^2.32.1",
"rollup": "^2.38.0",
"tslib": "^2.0.3",
"typescript": "^4.0.3"
},
"dependencies": {
"moment": "^2.29.1"
}
"dependencies": {}
}

0 comments on commit 25d9928

Please sign in to comment.