diff --git a/manifest.json b/manifest.json index 9c7a3ef..df2598b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "excalibrain", "name": "ExcaliBrain", - "version": "0.1.1", + "version": "0.1.2", "minAppVersion": "0.15.3", "description": "A clean, intuitive and editable graph view for Obsidian", "author": "Zsolt Viczian", diff --git a/src/Scene.ts b/src/Scene.ts index 138d053..37d7d58 100644 --- a/src/Scene.ts +++ b/src/Scene.ts @@ -10,6 +10,7 @@ import { ToolsPanel } from "./Components/ToolsPanel"; import { Neighbour, RelationType, Role } from "./Types"; import { HistoryPanel } from "./Components/HistoryPanel"; import { WarningPrompt } from "./utils/Prompts"; +import { debug } from "./utils/utils"; export class Scene { ea: ExcalidrawAutomate; @@ -136,7 +137,7 @@ export class Scene { if(!this.centralLeaf || !app.workspace.getLeafById(this.centralLeaf.id)) { this.centralLeaf = this.ea.openFileInNewOrAdjacentLeaf(page.file); } else { - this.centralLeaf.openFile(page.file); + this.centralLeaf.openFile(page.file, {active: false}); } this.addToHistory(page.file.path); } else { @@ -276,6 +277,7 @@ export class Scene { return; } const node = new Node({ + ea: this.ea, page: n.page, isInferred: n.relationType === RelationType.INFERRED, isCentral: x.isCentral, @@ -291,6 +293,7 @@ export class Scene { if(this.historyPanel) { this.historyPanel.rerender() } + if(!this.centralPagePath) return; let centralPage = this.plugin.pages.get(this.centralPagePath); if(!centralPage) { //path case sensitivity issue @@ -423,6 +426,7 @@ export class Scene { this.layouts.push(lSiblings); const rootNode = new Node({ + ea: this.ea, page: centralPage, isInferred: false, isCentral: true, diff --git a/src/Settings.ts b/src/Settings.ts index dd416f5..aedb756 100644 --- a/src/Settings.ts +++ b/src/Settings.ts @@ -60,6 +60,8 @@ export interface ExcaliBrainSettings { ontologySuggesterChildTrigger: string; ontologySuggesterFriendTrigger: string; ontologySuggesterTrigger: string; + ontologySuggesterMidSentenceTrigger: string; + boldFields: boolean; } export const DEFAULT_SETTINGS: ExcaliBrainSettings = { @@ -140,6 +142,8 @@ export const DEFAULT_SETTINGS: ExcaliBrainSettings = { ontologySuggesterChildTrigger: "::c", ontologySuggesterFriendTrigger: "::f", ontologySuggesterTrigger: ":::", + ontologySuggesterMidSentenceTrigger: "(", + boldFields: false, }; const HIDE_DISABLED_STYLE = "excalibrain-hide-disabled"; @@ -234,6 +238,7 @@ export class ExcaliBrainSettingTab extends PluginSettingTab { } const demoNode = new Node({ + ea: this.ea, page, isInferred: false, isCentral: true, @@ -244,6 +249,7 @@ export class ExcaliBrainSettingTab extends PluginSettingTab { demoNode.setCenter({x:0,y:0}) const demoNode2 = new Node({ + ea: this.ea, page: page2, isInferred:false, isCentral: false, @@ -314,6 +320,10 @@ export class ExcaliBrainSettingTab extends PluginSettingTab { if(this.plugin.settings.ontologySuggesterTrigger === "") { this.plugin.settings.ontologySuggesterTrigger = ":::"; } + if(this.plugin.settings.ontologySuggesterMidSentenceTrigger === "") { + this.plugin.settings.ontologySuggesterMidSentenceTrigger = "("; + } + this.plugin.setHierarchyLinkStylesExtended(); this.plugin.settings.tagStyleList = Object.keys(this.plugin.settings.tagNodeStyles); this.plugin.loadCustomNodeLabelFunction(); @@ -1176,7 +1186,12 @@ export class ExcaliBrainSettingTab extends PluginSettingTab { if(!keys) return; let f; while(!(f = keys.next()).done) { - if(!f.value.contains(",")) fieldSet.add(f.value); + if( + !f.value.contains(",") && + !(f.value.startsWith("**") && f.value.endsWith("**")) + ) { + fieldSet.add(f.value); + } } }); const fieldNameMap = new Map(); @@ -1202,7 +1217,7 @@ export class ExcaliBrainSettingTab extends PluginSettingTab { } if(k!==v) fieldNameMap.delete(v); }); - return Array.from(fieldNameMap.keys()).join(", ") + return Array.from(fieldNameMap.keys()).sort((a,b)=>a.toLowerCase() { this.plugin.settings.allowOntologySuggester = value; - seq.setDisabled(!value); - pSeq.setDisabled(!value); - cSeq.setDisabled(!value); - fSeq.setDisabled(!value); + gSetting.setDisabled(!value); + pSetting.setDisabled(!value); + cSetting.setDisabled(!value); + fSetting.setDisabled(!value); + mSetting.setDisabled(!value); + bSetting.setDisabled(!value); this.dirty = true; }) ) - seq = new Setting(containerEl) + gSetting = new Setting(containerEl) .setName(t("ONTOLOGY_SUGGESTER_ALL_NAME")) .setDisabled(!this.plugin.settings.allowOntologySuggester) .addText(text=> @@ -1436,7 +1454,7 @@ export class ExcaliBrainSettingTab extends PluginSettingTab { }) ) - pSeq = new Setting(containerEl) + pSetting = new Setting(containerEl) .setName(t("ONTOLOGY_SUGGESTER_PARENT_NAME")) .setDisabled(!this.plugin.settings.allowOntologySuggester) .addText(text=> @@ -1449,7 +1467,7 @@ export class ExcaliBrainSettingTab extends PluginSettingTab { ) - cSeq = new Setting(containerEl) + cSetting = new Setting(containerEl) .setName(t("ONTOLOGY_SUGGESTER_CHILD_NAME")) .setDisabled(!this.plugin.settings.allowOntologySuggester) .addText(text=> @@ -1461,7 +1479,7 @@ export class ExcaliBrainSettingTab extends PluginSettingTab { }) ) - fSeq = new Setting(containerEl) + fSetting = new Setting(containerEl) .setName(t("ONTOLOGY_SUGGESTER_FRIEND_NAME")) .setDisabled(!this.plugin.settings.allowOntologySuggester) .addText(text=> @@ -1473,6 +1491,31 @@ export class ExcaliBrainSettingTab extends PluginSettingTab { }) ) + mSetting = new Setting(containerEl) + .setName(t("MID_SENTENCE_SUGGESTER_TRIGGER_NAME")) + .setDesc(fragWithHTML(t("MID_SENTENCE_SUGGESTER_TRIGGER_DESC"))) + .addDropdown(dropdown => { + dropdown + .addOption("(","(") + .addOption("[","[") + .setValue(this.plugin.settings.ontologySuggesterMidSentenceTrigger) + .onChange(value => { + this.plugin.settings.ontologySuggesterMidSentenceTrigger = value; + this.dirty = true; + }) + }) + + bSetting = new Setting(containerEl) + .setName(t("BOLD_FIELDS_NAME")) + .setDesc(fragWithHTML(t("BOLD_FIELDS_DESC"))) + .addToggle(toggle => + toggle + .setValue(this.plugin.settings.boldFields) + .onChange(value => { + this.plugin.settings.boldFields = value; + this.dirty = true; + })) + this.containerEl.createEl("h1", { cls: "excalibrain-settings-h1", text: t("DISPLAY_HEAD") diff --git a/src/Suggesters/OntologySuggester.ts b/src/Suggesters/OntologySuggester.ts index 4902f5a..f7f2b61 100644 --- a/src/Suggesters/OntologySuggester.ts +++ b/src/Suggesters/OntologySuggester.ts @@ -26,23 +26,40 @@ export class FieldSuggester extends EditorSuggest { const settings = this.plugin.settings; if (settings.allowOntologySuggester) { const sub = editor.getLine(cursor.line).substring(0, cursor.ch); - const allTrigger = new RegExp(`^${settings.ontologySuggesterTrigger}(.*)$`); - const parentTrigger = new RegExp(`^${settings.ontologySuggesterParentTrigger}(.*)$`); - const childTrigger = new RegExp(`^${settings.ontologySuggesterChildTrigger}(.*)$`); - const friendTrigger = new RegExp(`^${settings.ontologySuggesterFriendTrigger}(.*)$`); - const match = - sub.match(allTrigger)?.[1] ?? - sub.match(parentTrigger)?.[1] ?? - sub.match(childTrigger)?.[1] ?? - sub.match(friendTrigger)?.[1]; + + const triggerREG = new RegExp( + `(^${settings.ontologySuggesterTrigger}|\\${settings.ontologySuggesterMidSentenceTrigger+settings.ontologySuggesterTrigger + }|^${settings.ontologySuggesterParentTrigger}|\\${settings.ontologySuggesterMidSentenceTrigger+settings.ontologySuggesterParentTrigger + }|^${settings.ontologySuggesterChildTrigger}|\\${settings.ontologySuggesterMidSentenceTrigger+settings.ontologySuggesterChildTrigger + }|^${settings.ontologySuggesterFriendTrigger}|\\${settings.ontologySuggesterMidSentenceTrigger+settings.ontologySuggesterFriendTrigger + })([^\\s\\${settings.ontologySuggesterTrigger}]*)`,"g" + ); + + let match:string, trigger: string, v; + const r=sub.matchAll(triggerREG); + while(!(v=r.next()).done) { + trigger = v.value[1]; + match = v.value[2]; + } + if (match !== undefined) { - this.suggestType = sub.match(allTrigger) - ? "all" - : (sub.match(parentTrigger) - ? "parent" - : sub.match(childTrigger) - ? "child" - : "friend"); + switch(trigger) { + case settings.ontologySuggesterTrigger: + case settings.ontologySuggesterMidSentenceTrigger+settings.ontologySuggesterTrigger: + this.suggestType = "all"; + break; + case settings.ontologySuggesterParentTrigger: + case settings.ontologySuggesterMidSentenceTrigger+settings.ontologySuggesterParentTrigger: + this.suggestType = "parent"; + break; + case settings.ontologySuggesterChildTrigger: + case settings.ontologySuggesterMidSentenceTrigger+settings.ontologySuggesterChildTrigger: + this.suggestType = "child"; + break; + default: + this.suggestType = "friend"; + break; + } this.latestTriggerInfo = { end: cursor, @@ -95,7 +112,8 @@ export class FieldSuggester extends EditorSuggest { selectSuggestion(suggestion: string): void { const { context } = this; if (context) { - const replacement = `${suggestion}:: `; + const bold = this.plugin.settings.boldFields; + const replacement = `${(bold?"**":"") + suggestion + (bold?"**":"")}:: `; context.editor.replaceRange( replacement, this.latestTriggerInfo.start, diff --git a/src/graph/Node.ts b/src/graph/Node.ts index 8e84a9f..033f8e2 100644 --- a/src/graph/Node.ts +++ b/src/graph/Node.ts @@ -18,6 +18,7 @@ export class Node { public title: string; constructor(x:{ + ea: ExcalidrawAutomate, page:Page, isInferred: boolean, isCentral: boolean, @@ -26,7 +27,7 @@ export class Node { }) { this.page = x.page; this.settings = x.page.plugin.settings; - this.ea = x.page.plugin.EA; + this.ea = x.ea; if(this.page.isFolder) { this.style = { ...this.settings.baseNodeStyle, diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index 73a71a5..a53c167 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -28,13 +28,21 @@ export default { EXCLUSIONS_DESC: "Dataview or YAML fields that are never used for ontology", UNASSIGNED_NAME: "Unassigned", UNASSIGNED_DESC: "Fields in your Vault that are neither excluded nor part of the defined ontology.", - ONTOLOGY_SUGGESTER_NAME: "Ongology Suggester", + ONTOLOGY_SUGGESTER_NAME: "Ontology Suggester", ONTOLOGY_SUGGESTER_DESC: "Activate ontology suggester in the markdown editor. If enabled then typing the trigger sequence at the beginning of a paragraph "+ "will activate the suggester listing your ontology fields defined above.", ONTOLOGY_SUGGESTER_ALL_NAME: "Character sequence to trigger generic suggester. The Generic suggester will include all the ontology fields regardless of their direction.", ONTOLOGY_SUGGESTER_PARENT_NAME: "Character sequence to trigger parent suggester", ONTOLOGY_SUGGESTER_CHILD_NAME: "Character sequence to trigger child suggester", ONTOLOGY_SUGGESTER_FRIEND_NAME: "Character sequence to trigger friend suggester", + MID_SENTENCE_SUGGESTER_TRIGGER_NAME: "Mid-sentence dataview field suggester trigger", + MID_SENTENCE_SUGGESTER_TRIGGER_DESC: "You may add fields mid-way in sentences following one of these two formats:
" + + "We met at [location:: [[XYZ restaurant]]] with [candidate:: [[John Doe]]]
" + + "We met at (location:: [[XYZ restaurant]]) with (candidate:: [[John Doe]])
" + + "If you set this trigger to e.g. ( then typing (::: anywhere in the sentence will activate the suggester (assuming you are using the default generic suggester trigger commbination of ::: - see setting above).
" + + "More info on inline fields: [DataView Help](https://blacksmithgu.github.io/obsidian-dataview/data-annotation/)", + BOLD_FIELDS_NAME: "Add selected field with BOLD", + BOLD_FIELDS_DESC: "Add selected field to text with bold typeface, i.e. (**field name**:: ) resulting in (field name:: )", DISPLAY_HEAD: "Display", EXCLUDE_PATHLIST_NAME: "Filepaths to exclude", EXCLUDE_PATHLIST_DESC: "Enter comma-separated list of filepaths to exclude from the index.", diff --git a/src/main.ts b/src/main.ts index 31c0f4d..1d11788 100644 --- a/src/main.ts +++ b/src/main.ts @@ -219,7 +219,7 @@ export default class ExcaliBrain extends Plugin { new Notice("ExcaliBrain: Please start Excalidraw and try again.",4000); return false; } - if(!this.EA) { + if(!this.EA !== ea) { this.EA = ea; this.registerExcalidrawAutomateHooks() } diff --git a/versions.json b/versions.json index 25318d9..9430b97 100644 --- a/versions.json +++ b/versions.json @@ -1,5 +1,5 @@ { - "0.1.1": "0.15.3", + "0.1.2": "0.15.3", "0.1.0": "0.15.2", "0.0.22": "0.14.0" }