Skip to content

Commit

Permalink
improve suggestion clickability and styles
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-dot-earth committed Jul 20, 2024
1 parent cd84fbe commit 4fbf8da
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 22 deletions.
52 changes: 37 additions & 15 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, Editor, FuzzyMatch, FuzzySuggestModal, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting, TFile } from 'obsidian';
import { App, Editor, FuzzyMatch, FuzzySuggestModal, MarkdownRenderer, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting, TFile } from 'obsidian';

// TODO Remember to rename these classes and interfaces!

Expand Down Expand Up @@ -172,22 +172,44 @@ class BlockSearchModal extends FuzzySuggestModal<BlockSuggestion> {
}

renderSuggestion({ item }: FuzzyMatch<BlockSuggestion>, el: HTMLElement ) {
const suggestionEl = el.createEl("div", {
cls: "suggestion-item",
});

// TODO make this optional
const contentWithoutId = item.content.replace(`^${item.id}`, "");

suggestionEl.createEl("div", {
text: contentWithoutId,
cls: "suggestion-content",
});

// TODO setting for path vs basename
const from = item.file.basename;
suggestionEl.createEl("small", {
text: `${from}#^${item.id}`,
cls: "suggestion-file",
// TODO make this optional
function unlinkfy(text: string): string {
return text.replace(
/\[([^\]]+)\]\([^)]+\)/g,
`<span class="suggestion-block-link">$1</span>`
);
}
const sansLink = unlinkfy(contentWithoutId);

el.createDiv({ cls: "suggestion-content" }, (contentDiv) => {
const textDiv = contentDiv.createDiv({
// text: sansLink,
cls: "suggestion-block-text",
});
textDiv.innerHTML = sansLink;

// TODO setting for path vs basename
const from = item.file.basename;
contentDiv.createDiv({
text: `${from}#^${item.id}`,
cls: "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)
});
}

Expand Down
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.1.0",
"version": "1.2.0",
"minAppVersion": "0.15.0",
"description": "Search and embed blocks with ^block-references (aka ^block-ids)",
"author": "tyler-dot-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.1.0",
"version": "1.2.0",
"minAppVersion": "0.15.0",
"description": "Search and embed blocks with ^block-references (aka ^block-ids)",
"author": "tyler-dot-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.1.0",
"version": "1.2.0",
"description": "Search and embed blocks with ^block-references (aka ^block-ids)",
"main": "main.js",
"scripts": {
Expand Down
15 changes: 13 additions & 2 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@ If your plugin does not need CSS, delete this file.
*/

.suggestion-file {
font-size: 0.8rem;
.suggestion-content {
display: flex;
flex-direction: column;
gap: 0.15rem;
}

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

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

0 comments on commit 4fbf8da

Please sign in to comment.