diff --git a/package-lock.json b/package-lock.json index 87fd68a1d..a02db234f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "trilium", - "version": "0.36.2", + "version": "0.36.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/public/javascripts/dialogs/add_link.js b/src/public/javascripts/dialogs/add_link.js index 8a5ba65cd..b99608ce9 100644 --- a/src/public/javascripts/dialogs/add_link.js +++ b/src/public/javascripts/dialogs/add_link.js @@ -1,4 +1,3 @@ -import cloningService from '../services/cloning.js'; import linkService from '../services/link.js'; import noteDetailService from '../services/note_detail.js'; import treeUtils from '../services/tree_utils.js'; @@ -9,49 +8,18 @@ const $dialog = $("#add-link-dialog"); const $form = $("#add-link-form"); const $autoComplete = $("#note-autocomplete"); const $linkTitle = $("#link-title"); -const $clonePrefix = $("#clone-prefix"); -const $linkTitleFormGroup = $("#add-link-title-form-group"); -const $prefixFormGroup = $("#add-link-prefix-form-group"); -const $linkTypeDiv = $("#add-link-type-div"); -const $linkTypes = $("input[name='add-link-type']"); -const $linkTypeHtml = $linkTypes.filter('input[value="html"]'); +const $addLinkTitleFormGroup = $("#add-link-title-form-group"); -function setLinkType(linkType) { - $linkTypes.each(function () { - $(this).prop('checked', $(this).val() === linkType); - }); - - linkTypeChanged(); -} - -export async function showDialogForClone() { - showDialog('selected-to-active'); -} - -export async function showDialog(linkType) { +export async function showDialog() { utils.closeActiveDialog(); + $addLinkTitleFormGroup.toggle(!hasSelection()); + glob.activeDialog = $dialog; - if (noteDetailService.getActiveTabNoteType() === 'text') { - $linkTypeHtml.prop('disabled', false); - - setLinkType('html'); - } - else { - $linkTypeHtml.prop('disabled', true); - - setLinkType('selected-to-active'); - } - - if (linkType === 'selected-to-active') { - setLinkType(linkType); - } - $dialog.modal(); $autoComplete.val('').focus(); - $clonePrefix.val(''); $linkTitle.val(''); async function setDefaultLinkTitle(noteId) { @@ -85,42 +53,23 @@ export async function showDialog(linkType) { $form.submit(() => { const notePath = $autoComplete.getSelectedPath(); - const noteId = treeUtils.getNoteIdFromNotePath(notePath); if (notePath) { - const linkType = $("input[name='add-link-type']:checked").val(); + const linkTitle = $linkTitle.val(); - if (linkType === 'html') { - const linkTitle = $linkTitle.val(); + $dialog.modal('hide'); - $dialog.modal('hide'); + const linkHref = '#' + notePath; + const editor = noteDetailService.getActiveEditor(); - const linkHref = '#' + notePath; - const editor = noteDetailService.getActiveEditor(); - - if (hasSelection()) { - editor.execute('link', linkHref); - } - else { - linkService.addLinkToEditor(linkTitle, linkHref); - } - - editor.editing.view.focus(); + if (hasSelection()) { + editor.execute('link', linkHref); } - else if (linkType === 'selected-to-active') { - const prefix = $clonePrefix.val(); - - cloningService.cloneNoteTo(noteId, noteDetailService.getActiveTabNoteId(), prefix); - - $dialog.modal('hide'); + else { + linkService.addLinkToEditor(linkTitle, linkHref); } - else if (linkType === 'active-to-selected') { - const prefix = $clonePrefix.val(); - cloningService.cloneNoteTo(noteDetailService.getActiveTabNoteId(), noteId, prefix); - - $dialog.modal('hide'); - } + editor.editing.view.focus(); } else { console.error("No path to add link."); @@ -135,15 +84,4 @@ function hasSelection() { const selection = model.document.selection; return !selection.isCollapsed; -} - -function linkTypeChanged() { - const value = $linkTypes.filter(":checked").val(); - - $linkTitleFormGroup.toggle(!hasSelection() && value === 'html'); - $prefixFormGroup.toggle(!hasSelection() && value !== 'html'); - - $linkTypeDiv.toggle(!hasSelection()); -} - -$linkTypes.change(linkTypeChanged); +} \ No newline at end of file diff --git a/src/views/dialogs/add_link.ejs b/src/views/dialogs/add_link.ejs index 6cdc1493a..95dafb0b1 100644 --- a/src/views/dialogs/add_link.ejs +++ b/src/views/dialogs/add_link.ejs @@ -12,20 +12,6 @@