mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	fix: 🐛 fix add external link
fix can't add external link from add link dialog
This commit is contained in:
		
							parent
							
								
									5543650166
								
							
						
					
					
						commit
						f1f55fd4f8
					
				@ -322,9 +322,7 @@ function init() {
 | 
			
		||||
 | 
			
		||||
    $.fn.setSelectedNotePath = function (notePath) {
 | 
			
		||||
        notePath = notePath || "";
 | 
			
		||||
 | 
			
		||||
        $(this).attr(SELECTED_NOTE_PATH_KEY, notePath);
 | 
			
		||||
 | 
			
		||||
        $(this).closest(".input-group").find(".go-to-selected-note-button").toggleClass("disabled", !notePath.trim()).attr("href", `#${notePath}`); // we also set href here so tooltip can be displayed
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
@ -336,11 +334,9 @@ function init() {
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    $.fn.setSelectedExternalLink = function (externalLink) {
 | 
			
		||||
        if (externalLink) {
 | 
			
		||||
            // TODO: This doesn't seem to do anything with the external link, is it normal?
 | 
			
		||||
    $.fn.setSelectedExternalLink = function (externalLink: string | null) {
 | 
			
		||||
        $(this).attr(SELECTED_EXTERNAL_LINK_KEY, externalLink);
 | 
			
		||||
        $(this).closest(".input-group").find(".go-to-selected-note-button").toggleClass("disabled", true);
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    $.fn.setNote = async function (noteId) {
 | 
			
		||||
 | 
			
		||||
@ -88,13 +88,13 @@ export default class AddLinkDialog extends BasicWidget {
 | 
			
		||||
            if (this.$autoComplete.getSelectedNotePath()) {
 | 
			
		||||
                this.$widget.modal("hide");
 | 
			
		||||
 | 
			
		||||
                const linkTitle = this.getLinkType() === "reference-link" ? null : this.$linkTitle.val() as string;
 | 
			
		||||
                const linkTitle = this.getLinkType() === "reference-link" ? null : this.$linkTitle.val();
 | 
			
		||||
 | 
			
		||||
                this.textTypeWidget?.addLink(this.$autoComplete.getSelectedNotePath()!, linkTitle);
 | 
			
		||||
            } else if (this.$autoComplete.getSelectedExternalLink()) {
 | 
			
		||||
                this.$widget.modal("hide");
 | 
			
		||||
 | 
			
		||||
                this.textTypeWidget?.addLink(this.$autoComplete.getSelectedExternalLink()!, this.$linkTitle.val() as string);
 | 
			
		||||
                this.textTypeWidget?.addLink(this.$autoComplete.getSelectedExternalLink()!, this.$linkTitle.val(), true);
 | 
			
		||||
            } else {
 | 
			
		||||
                logError("No link to add.");
 | 
			
		||||
            }
 | 
			
		||||
@ -149,7 +149,6 @@ export default class AddLinkDialog extends BasicWidget {
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        this.$autoComplete.on("autocomplete:externallinkselected", (event: JQuery.Event, suggestion: Suggestion) => {
 | 
			
		||||
            console.log("autocomplete:externallinkselected", event, suggestion);
 | 
			
		||||
            if (!suggestion.externalLink) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@ -290,7 +290,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
 | 
			
		||||
        this.watchdog?.editor.editing.view.focus();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    show() {}
 | 
			
		||||
    show() { }
 | 
			
		||||
 | 
			
		||||
    getEditor() {
 | 
			
		||||
        return this.watchdog?.editor;
 | 
			
		||||
@ -337,14 +337,14 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
 | 
			
		||||
        this.addTextToEditor(text);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async addLink(notePath, linkTitle) {
 | 
			
		||||
    async addLink(notePath, linkTitle, externalLink = false) {
 | 
			
		||||
        await this.initialized;
 | 
			
		||||
 | 
			
		||||
        if (linkTitle) {
 | 
			
		||||
            if (this.hasSelection()) {
 | 
			
		||||
                this.watchdog.editor.execute("link", `#${notePath}`);
 | 
			
		||||
                this.watchdog.editor.execute("link", externalLink ? `${notePath}` : `#${notePath}`);
 | 
			
		||||
            } else {
 | 
			
		||||
                await this.addLinkToEditor(`#${notePath}`, linkTitle);
 | 
			
		||||
                await this.addLinkToEditor(externalLink ? `${notePath}` : `#${notePath}`, linkTitle);
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            this.watchdog.editor.execute("referenceLink", { href: "#" + notePath });
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user