Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
basic implementation of reference link functionality
zadam9b17e9976e98
diff --git a/src/public/javascripts/dialogs/add_link.js b/src/public/javascripts/dialogs/add_link.jsindex 159a31cbde..a866f4b1f6 100644--- a/src/public/javascripts/dialogs/add_link.js+++ b/src/public/javascripts/dialogs/add_link.js@@ -56,7 +56,7 @@ $form.on('submit', () => {if (notePath) {$dialog.modal('hide');- textTypeWidget.addLink($linkTitle.val(), '#' + notePath);+ textTypeWidget.addLink(notePath, $linkTitle.val());}else {console.error("No path to add link.");diff --git a/src/public/javascripts/services/app_context.js b/src/public/javascripts/services/app_context.jsindex c9560b6561..f0fe67257c 100644--- a/src/public/javascripts/services/app_context.js+++ b/src/public/javascripts/services/app_context.js@@ -117,6 +117,11 @@ $(window).on('hashchange', function() {if (isNotePathInAddress()) {const [notePath, tabId] = treeService.getHashValueFromAddress();+ if (!notePath) {+ console.log(`Invalid hash value "${document.location.hash}", ignoring.`);+ return;+ }+appContext.tabManager.switchToTab(tabId, notePath);}});diff --git a/src/public/javascripts/services/glob.js b/src/public/javascripts/services/glob.jsindex 0730a41318..6bbe8af8a5 100644--- a/src/public/javascripts/services/glob.js+++ b/src/public/javascripts/services/glob.js@@ -4,6 +4,7 @@ import server from "./server.js";import libraryLoader from "./library_loader.js";import ws from "./ws.js";import protectedSessionHolder from "./protected_session_holder.js";+import treeCache from "./tree_cache.js";window.glob.PROFILING_LOG = false;@@ -18,6 +19,7 @@ window.glob.getActiveTabNote = () => appContext.tabManager.getActiveTabNote();window.glob.requireLibrary = libraryLoader.requireLibrary;window.glob.ESLINT = libraryLoader.ESLINT;window.glob.appContext = appContext; // for debugging+window.glob.treeCache = treeCache;// for CKEditor integration (button on block toolbar)window.glob.importMarkdownInline = async () => {diff --git a/src/public/javascripts/widgets/type_widgets/text.js b/src/public/javascripts/widgets/type_widgets/text.jsindex 6d40cdd906..45df34736c 100644--- a/src/public/javascripts/widgets/type_widgets/text.js+++ b/src/public/javascripts/widgets/type_widgets/text.js@@ -9,7 +9,7 @@ import treeCache from "../../services/tree_cache.js";import linkService from "../../services/link.js";import noteContentRenderer from "../../services/note_content_renderer.js";-const ENABLE_INSPECTOR = false;+const ENABLE_INSPECTOR = true;const mentionSetup = {feeds: [@@ -135,7 +135,7 @@ export default class TextTypeWidget extends TypeWidget {this.textEditor.model.document.on('change:data', () => this.spacedUpdate.scheduleUpdate());if (glob.isDev && ENABLE_INSPECTOR) {- await import('../../libraries/ckeditor/inspector.js');+ await import('../../../libraries/ckeditor/inspector.js');CKEditorInspector.attach(this.textEditor);}}@@ -191,7 +191,7 @@ export default class TextTypeWidget extends TypeWidget {this.addTextToEditor(dateString);}- async addLinkToEditor(linkTitle, linkHref) {+ async addLinkToEditor(linkHref, linkTitle) {await this.initialized;this.textEditor.model.change(writer => {@@ -217,14 +217,18 @@ export default class TextTypeWidget extends TypeWidget {this.addTextToEditor(text);}- async addLink(linkTitle, linkHref) {+ async addLink(notePath, linkTitle) {await this.initialized;- if (this.hasSelection()) {- this.textEditor.execute('link', linkHref);+ if (linkTitle && false) {+ if (this.hasSelection()) {+ this.textEditor.execute('link', '#' + notePath);+ } else {+ await this.addLinkToEditor('#' + notePath, linkTitle);+ }}else {- await this.addLinkToEditor(linkTitle, linkHref);+ this.textEditor.execute('referenceLink', { notePath: notePath });}this.textEditor.editing.view.focus();