Skip to content

Commit

Permalink
page search, show/hide siblings
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed May 15, 2022
1 parent 689bbbb commit 01bd071
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 71 deletions.
32 changes: 25 additions & 7 deletions src/Components/ToolsPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ToggleButton } from "src/Components/ToggleButton";
import { t } from "src/lang/helpers";
import ExcaliBrain from "src/main";
import { splitFolderAndFilename } from "src/utils/fileUtils";
import { FileSuggest } from "../Suggesters/FileSuggester";
import { PageSuggest } from "../Suggesters/PageSuggester";

export class ToolsPanel {
private wrapperDiv: HTMLDivElement;
Expand All @@ -28,13 +28,15 @@ export class ToolsPanel {
});
inputEl.ariaLabel = t("SEARCH_IN_VAULT");
inputEl.oninput = () => {
const file = app.vault.getAbstractFileByPath(inputEl.value);
if(file && file instanceof TFile) {
this.plugin.scene?.renderGraphForPath(inputEl.value);
inputEl.value = file.basename;
const page = this.plugin.pages.get(inputEl.value);
if(page) {
this.plugin.scene?.renderGraphForPath(page.path);
inputEl.value = page.file
? page.file.basename
: page.path;
}
}
new FileSuggest(
new PageSuggest(
this.plugin.app,
inputEl,
this.plugin
Expand Down Expand Up @@ -193,7 +195,23 @@ export class ToolsPanel {
tooltip: t("PIN_LEAF")
}
)
)
)

//------------
//Display siblings
//------------
this.buttons.push(
new ToggleButton(
this.plugin,
()=>this.plugin.settings.renderSiblings,
(val:boolean)=>this.plugin.settings.renderSiblings = val,
buttonsWrapperDiv,
{
display: "👨‍👩‍👧‍👦",
tooltip: t("SHOW_HIDE_SIBLINGS")
}
)
)

this.contentEl.appendChild(this.wrapperDiv);

Expand Down
22 changes: 12 additions & 10 deletions src/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class Scene {
"under 'Links and Transclusion'.\n\n⚠ ExcaliBrain may need to wait for " +
"DataView to initialize its index.\nThis can take up to a few minutes after starting Obsidian.", {textAlign:"center"});
await ea.addElementsToView();
ea.getExcalidrawAPI().zoomToFit(null, 5);
ea.getExcalidrawAPI().zoomToFit(null, 5, 0.05);

ea.targetView.linksAlwaysOpenInANewPane = true;

Expand Down Expand Up @@ -418,14 +418,16 @@ export class Scene {
friendGateOnLeft: false
});

this.addNodes({
neighbours: siblings,
layout: lSiblings,
isCentral: false,
isSibling: true,
friendGateOnLeft: true
});

if(this.plugin.settings.renderSiblings) {
this.addNodes({
neighbours: siblings,
layout: lSiblings,
isCentral: false,
isSibling: true,
friendGateOnLeft: true
});
}

//-------------------------------------------------------
// Generate links for all displayed nodes
const addLinks = (nodeA: Node, neighbours:Neighbour[],role: Role) => {
Expand Down Expand Up @@ -464,7 +466,7 @@ export class Scene {
el=>el.type==="arrow"
).concat(elements.filter(el=>el.type!=="arrow"))
})
this.ea.getExcalidrawAPI().zoomToFit(null,5);
this.ea.getExcalidrawAPI().zoomToFit(null,5,0.05);
this.blockUpdateTimer = false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface ExcaliBrainSettings {
showTagNodes: boolean;
showPageNodes: boolean;
maxItemCount: number;
renderSiblings: boolean;
baseNodeStyle: NodeStyle;
centralNodeStyle: NodeStyle;
inferredNodeStyle: NodeStyle;
Expand Down Expand Up @@ -68,6 +69,7 @@ export const DEFAULT_SETTINGS: ExcaliBrainSettings = {
showTagNodes: false,
showPageNodes: true,
maxItemCount: 30,
renderSiblings: true,
baseNodeStyle: {
prefix: "",
backgroundColor: "#00000066",
Expand Down
53 changes: 0 additions & 53 deletions src/Suggesters/FileSuggester.ts

This file was deleted.

61 changes: 61 additions & 0 deletions src/Suggesters/PageSuggester.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Credits go to Liam's Periodic Notes Plugin: https://github.com/liamcain/obsidian-periodic-notes

import { App, prepareFuzzySearch, TFile } from "obsidian";
import { Page } from "src/graph/Page";
import ExcaliBrain from "src/main";
import { TextInputSuggest } from "./Suggest";

export enum FileSuggestMode {
TemplateFiles,
ScriptFiles,
}

export class PageSuggest extends TextInputSuggest<Page> {
constructor(
public app: App,
public inputEl: HTMLInputElement,
private plugin: ExcaliBrain,
) {
super(app, inputEl);
}

getSuggestions(inputStr: string): Page[] {
const lowerInputStr = inputStr.toLowerCase();
const exactMatches = this.plugin.pages?.getPages().filter(p=>
(!p.file ||
(this.plugin.settings.showAttachments || p.file.extension === "md") &&
(!this.plugin.settings.excludeFilepaths.some(ep=>p.path.startsWith(ep)))
) &&
(p.file ||
(this.plugin.settings.showFolderNodes || !p.path.startsWith("folder:")) &&
(this.plugin.settings.showTagNodes || !p.path.startsWith("tag:"))
) &&
p.path.toLowerCase().contains(lowerInputStr)
)
if(exactMatches.length>30) {
return exactMatches;
}

const query = prepareFuzzySearch(inputStr);
return exactMatches.concat(this.plugin.pages?.getPages().filter(p=>
(!p.file ||
(this.plugin.settings.showAttachments || p.file.extension === "md") &&
(!this.plugin.settings.excludeFilepaths.some(ep=>p.path.startsWith(ep)))
) &&
(p.file ||
(this.plugin.settings.showFolderNodes || !p.path.startsWith("folder:")) &&
(this.plugin.settings.showTagNodes || !p.path.startsWith("tag:"))
) && !exactMatches.contains(p) && query(p.path)
))
}

renderSuggestion(page: Page, el: HTMLElement): void {
el.setText(page.path);
}

selectSuggestion(page: Page): void {
this.inputEl.value = page.path;
this.inputEl.trigger("input");
this.close();
}
}
4 changes: 4 additions & 0 deletions src/graph/Pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class Pages {
return this.pages.get(path);
}

public getPages(): Page[] {
return Array.from(this.pages.values());
}

public forEach = this.pages.forEach.bind(this.pages);
public get size():number {
return this.pages.size;
Expand Down
1 change: 1 addition & 0 deletions src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default {
SHOW_HIDE_VIRTUAL: "Show/Hide virtual nodes",
SHOW_HIDE_INFERRED: "Show/Hide inferred nodes",
SHOW_HIDE_ALIAS: "Show/Hide document alias",
SHOW_HIDE_SIBLINGS: "Show/Hide siblings",
SHOW_HIDE_FOLDER: "Show/Hide folder nodes",
SHOW_HIDE_TAG: "Show/Hide tag nodes",
SHOW_HIDE_PAGES: "Show/Hide page nodes (incl. defined, inferred, virtual and attachments)",
Expand Down
2 changes: 1 addition & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
padding-right: 5px;
margin-left: 5px !important;
margin-right: 0px !important;
width: 2em !important;
width: 2.4em !important;
}

.excalibrain-button span {
Expand Down

0 comments on commit 01bd071

Please sign in to comment.