mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	basic implementation of reference link functionality
This commit is contained in:
		| @@ -56,7 +56,7 @@ $form.on('submit', () => { | |||||||
|     if (notePath) { |     if (notePath) { | ||||||
|         $dialog.modal('hide'); |         $dialog.modal('hide'); | ||||||
|  |  | ||||||
|         textTypeWidget.addLink($linkTitle.val(), '#' + notePath); |         textTypeWidget.addLink(notePath, $linkTitle.val()); | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
|         console.error("No path to add link."); |         console.error("No path to add link."); | ||||||
|   | |||||||
| @@ -117,6 +117,11 @@ $(window).on('hashchange', function() { | |||||||
|     if (isNotePathInAddress()) { |     if (isNotePathInAddress()) { | ||||||
|         const [notePath, tabId] = treeService.getHashValueFromAddress(); |         const [notePath, tabId] = treeService.getHashValueFromAddress(); | ||||||
|  |  | ||||||
|  |         if (!notePath) { | ||||||
|  |             console.log(`Invalid hash value "${document.location.hash}", ignoring.`); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         appContext.tabManager.switchToTab(tabId, notePath); |         appContext.tabManager.switchToTab(tabId, notePath); | ||||||
|     } |     } | ||||||
| }); | }); | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ import server from "./server.js"; | |||||||
| import libraryLoader from "./library_loader.js"; | import libraryLoader from "./library_loader.js"; | ||||||
| import ws from "./ws.js"; | import ws from "./ws.js"; | ||||||
| import protectedSessionHolder from "./protected_session_holder.js"; | import protectedSessionHolder from "./protected_session_holder.js"; | ||||||
|  | import treeCache from "./tree_cache.js"; | ||||||
|  |  | ||||||
| window.glob.PROFILING_LOG = false; | window.glob.PROFILING_LOG = false; | ||||||
|  |  | ||||||
| @@ -18,6 +19,7 @@ window.glob.getActiveTabNote = () => appContext.tabManager.getActiveTabNote(); | |||||||
| window.glob.requireLibrary = libraryLoader.requireLibrary; | window.glob.requireLibrary = libraryLoader.requireLibrary; | ||||||
| window.glob.ESLINT = libraryLoader.ESLINT; | window.glob.ESLINT = libraryLoader.ESLINT; | ||||||
| window.glob.appContext = appContext; // for debugging | window.glob.appContext = appContext; // for debugging | ||||||
|  | window.glob.treeCache = treeCache; | ||||||
|  |  | ||||||
| // for CKEditor integration (button on block toolbar) | // for CKEditor integration (button on block toolbar) | ||||||
| window.glob.importMarkdownInline = async () => { | window.glob.importMarkdownInline = async () => { | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ import treeCache from "../../services/tree_cache.js"; | |||||||
| import linkService from "../../services/link.js"; | import linkService from "../../services/link.js"; | ||||||
| import noteContentRenderer from "../../services/note_content_renderer.js"; | import noteContentRenderer from "../../services/note_content_renderer.js"; | ||||||
|  |  | ||||||
| const ENABLE_INSPECTOR = false; | const ENABLE_INSPECTOR = true; | ||||||
|  |  | ||||||
| const mentionSetup = { | const mentionSetup = { | ||||||
|     feeds: [ |     feeds: [ | ||||||
| @@ -135,7 +135,7 @@ export default class TextTypeWidget extends TypeWidget { | |||||||
|         this.textEditor.model.document.on('change:data', () => this.spacedUpdate.scheduleUpdate()); |         this.textEditor.model.document.on('change:data', () => this.spacedUpdate.scheduleUpdate()); | ||||||
|  |  | ||||||
|         if (glob.isDev && ENABLE_INSPECTOR) { |         if (glob.isDev && ENABLE_INSPECTOR) { | ||||||
|             await import('../../libraries/ckeditor/inspector.js'); |             await import('../../../libraries/ckeditor/inspector.js'); | ||||||
|             CKEditorInspector.attach(this.textEditor); |             CKEditorInspector.attach(this.textEditor); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -191,7 +191,7 @@ export default class TextTypeWidget extends TypeWidget { | |||||||
|         this.addTextToEditor(dateString); |         this.addTextToEditor(dateString); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async addLinkToEditor(linkTitle, linkHref) { |     async addLinkToEditor(linkHref, linkTitle) { | ||||||
|         await this.initialized; |         await this.initialized; | ||||||
|  |  | ||||||
|         this.textEditor.model.change(writer => { |         this.textEditor.model.change(writer => { | ||||||
| @@ -217,14 +217,18 @@ export default class TextTypeWidget extends TypeWidget { | |||||||
|         this.addTextToEditor(text); |         this.addTextToEditor(text); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async addLink(linkTitle, linkHref) { |     async addLink(notePath, linkTitle) { | ||||||
|         await this.initialized; |         await this.initialized; | ||||||
|  |  | ||||||
|  |         if (linkTitle && false) { | ||||||
|             if (this.hasSelection()) { |             if (this.hasSelection()) { | ||||||
|             this.textEditor.execute('link', linkHref); |                 this.textEditor.execute('link', '#' + notePath); | ||||||
|  |             } else { | ||||||
|  |                 await this.addLinkToEditor('#' + notePath, linkTitle); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|         else { |         else { | ||||||
|             await this.addLinkToEditor(linkTitle, linkHref); |             this.textEditor.execute('referenceLink', { notePath: notePath }); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         this.textEditor.editing.view.focus(); |         this.textEditor.editing.view.focus(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user