Skip to content

Commit

Permalink
adjustments for submission
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-dot-earth committed Aug 7, 2024
1 parent 6c2606e commit 0540c78
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 64 deletions.
51 changes: 4 additions & 47 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, FuzzyMatch, FuzzySuggestModal, MarkdownView, Plugin, PluginSettingTab, Setting, TFile } from 'obsidian';
import { App, FuzzyMatch, FuzzySuggestModal, MarkdownView, Plugin, TFile } from 'obsidian';

export default class Blockreffer extends Plugin {
async onload() {
Expand Down Expand Up @@ -35,13 +35,9 @@ export default class Blockreffer extends Plugin {
}).open();
}
});

// This adds a settings tab so the user can configure various aspects of the plugin
this.addSettingTab(new BlockrefferSettingsTab({ app: this.app, plugin: this }));
}

onunload() {

}

async getBlocksWithIds(app: App): Promise<BlockSuggestion[]> {
Expand Down Expand Up @@ -152,7 +148,7 @@ class BlockSearchModal extends FuzzySuggestModal<BlockSuggestion> {
fragment.appendChild(document.createTextNode(text.slice(lastIndex, match.index)));
}
const span = document.createElement('span');
span.className = 'suggestion-block-link';
span.className = 'blockreffer-suggestion-block-link';
span.textContent = match[1];
fragment.appendChild(span);
lastIndex = regex.lastIndex;
Expand All @@ -169,35 +165,20 @@ class BlockSearchModal extends FuzzySuggestModal<BlockSuggestion> {
el.createDiv({ cls: "suggestion-content" }, (contentDiv) => {
contentDiv.createDiv({
// text: sansLink,
cls: "suggestion-block-text",
cls: "blockreffer-suggestion-block-text",
}).appendChild(sansLink);

// TODO setting for path vs basename
const from = item.file.basename;
contentDiv.createEl('small', {
text: `${from}#^${item.id}`,
cls: "suggestion-block-file",
cls: "blockreffer-suggestion-block-file",
});

// TODO maybe use markdownRenderer? doesn't quite look right though..
// but alternative is that i handle markdown like `**bold**` i guess? 🤔
// OTOH markdown is just readable text too... so maybe not a big deal?
//
// here's an example anyway:
//
// const markdownDiv = contentDiv.createDiv({
// cls: "suggestion-markdown-test",
// });
// const sourcePath = this.app.workspace.getActiveFile()?.path;
// if (!sourcePath) throw new Error("No source path"); // TODO feels wrong
// MarkdownRenderer.render(this.app, contentWithoutId, markdownDiv, sourcePath, this.plugin)
});
}

onChooseItem(item: BlockSuggestion, evt: MouseEvent | KeyboardEvent) {
if (this.action === "embed") {
console.log('embed', { item });

const editor = this.app.workspace.getActiveViewOfType(MarkdownView)?.editor;
if (editor) {
// Embed the block using the ref
Expand All @@ -212,27 +193,3 @@ class BlockSearchModal extends FuzzySuggestModal<BlockSuggestion> {
}
}
}

class BlockrefferSettingsTab extends PluginSettingTab {
plugin: Blockreffer;

constructor({ app, plugin }: { app: App; plugin: Blockreffer }) {
super(app, plugin);
this.plugin = plugin;
}

display(): void {
const { containerEl } = this;

containerEl.empty();

new Setting(containerEl)
.setName("Bugs and feature requests")
.setDesc("Encounter an issue or have an idea? Please open an issue on GitHub")
.addButton((button) => {
button.setButtonText("Open GitHub").onClick(() => {
window.open(`https://github.com/tyler-dot-earth/obsidian-blockreffer/issues`);
});
});
}
}
2 changes: 1 addition & 1 deletion manifest-beta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "blockreffer",
"name": "Blockreffer",
"version": "1.3.3",
"version": "1.4.0",
"minAppVersion": "0.15.0",
"description": "Search and embed blocks with ^block-references (aka ^block-ids)",
"author": "tyler.earth",
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": "blockreffer",
"name": "Blockreffer",
"version": "1.3.3",
"version": "1.4.0",
"minAppVersion": "0.15.0",
"description": "Search and embed blocks with ^block-references (aka ^block-ids)",
"author": "tyler.earth",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Blockreffer",
"version": "1.3.3",
"version": "1.4.0",
"description": "Search and embed blocks with ^block-references (aka ^block-ids)",
"main": "main.js",
"scripts": {
Expand Down
15 changes: 3 additions & 12 deletions styles.css
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
/*
This CSS file will be included with your plugin, and
available in the app when your plugin is enabled.
If your plugin does not need CSS, delete this file.
*/

.suggestion-content {
.blockreffer-suggestion-content {
display: flex;
flex-direction: column;
gap: 0.15rem;
}

.suggestion-block-link {
.blockreffer-suggestion-block-link {
text-decoration: underline;
text-decoration-color: var(--text-faint);
text-underline-offset: 0.2rem;
}

.suggestion-block-file {
.blockreffer-suggestion-block-file {
color: var(--text-muted);
}

0 comments on commit 0540c78

Please sign in to comment.