diff --git a/README.md b/README.md index 4845cd2..32ab85e 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,8 @@ The plugin offers three simple features at the moment: 1. **Open literature note** (Ctrl+Shift+O): automatically create or open a literature note for a particular reference. The title, folder, and initial content of the note can be configured in the plugin settings. 2. **Insert literature note reference** (Ctrl+Shift+E): insert a link to the literature note corresponding to a particular reference. -3. **Insert Markdown citation** (no hotkey by default): insert a [Pandoc-style citation][3] for a particular reference. (The exact format of the citation can be configured in the plugin settings.) +3. **Insert literature note content in the current pane** (no hotkey by default): insert content describing a particular reference into the current pane. (This can be useful for updating literature notes you already have but which are missing reference information.) +4. **Insert Markdown citation** (no hotkey by default): insert a [Pandoc-style citation][3] for a particular reference. (The exact format of the citation can be configured in the plugin settings.) ## License diff --git a/src/main.ts b/src/main.ts index 9413577..12a2f65 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,6 +18,7 @@ import { import { InsertCitationModal, InsertNoteLinkModal, + InsertNoteContentModal, OpenNoteModal, } from './modals'; @@ -128,6 +129,15 @@ export default class CitationPlugin extends Plugin { }, }); + this.addCommand({ + id: 'insert-literature-note-content', + name: 'Insert literature note content in the current pane', + callback: () => { + const modal = new InsertNoteContentModal(this.app, this); + modal.open(); + }, + }); + this.addCommand({ id: 'insert-markdown-citation', name: 'Insert Markdown citation', @@ -306,9 +316,6 @@ export default class CitationPlugin extends Plugin { async insertLiteratureNoteLink(citekey: string): Promise { this.getOrCreateLiteratureNoteFile(citekey) .then(() => { - // TODO what is the API for this? - console.log(this.app.workspace.activeLeaf); - const title = this.getTitleForCitekey(citekey), linkText = `[[${title}]]`; // console.log(this.app.metadataCache.fileToLinktext(file, this.app.vault.getRoot().path, true)) @@ -317,6 +324,15 @@ export default class CitationPlugin extends Plugin { .catch(console.error); } + /** + * Format literature note content for a given reference and insert in the + * currently active pane. + */ + async insertLiteratureNoteContent(citekey: string): Promise { + const content = this.getInitialContentForCitekey(citekey); + this.editor.replaceRange(content, this.editor.getCursor()); + } + async insertMarkdownCitation( citekey: string, alternative = false, diff --git a/src/modals.ts b/src/modals.ts index d80d314..bfc5da4 100644 --- a/src/modals.ts +++ b/src/modals.ts @@ -232,6 +232,26 @@ export class InsertNoteLinkModal extends SearchModal { } } +export class InsertNoteContentModal extends SearchModal { + constructor(app: App, plugin: CitationPlugin) { + super(app, plugin); + + this.setInstructions([ + { command: '↑↓', purpose: 'to navigate' }, + { + command: '↵', + purpose: 'to insert literature note content in active pane', + }, + { command: 'esc', purpose: 'to dismiss' }, + ]); + } + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + onChooseItem(item: Entry, evt: unknown): void { + this.plugin.insertLiteratureNoteContent(item.id).catch(console.error); + } +} + export class InsertCitationModal extends SearchModal { constructor(app: App, plugin: CitationPlugin) { super(app, plugin);