Skip to content

Build your personal knowledge base with Trilium Notes

fix inserting link

zadam34150e71777c
diff --git a/src/public/javascripts/dialogs/add_link.js b/src/public/javascripts/dialogs/add_link.js
index de388063d5..1af88acf52 100644
--- a/src/public/javascripts/dialogs/add_link.js
+++ b/src/public/javascripts/dialogs/add_link.js
@@ -1,6 +1,7 @@
import treeService from '../services/tree.js';
import noteAutocompleteService from "../services/note_autocomplete.js";
import utils from "../services/utils.js";
+import appContext from "../services/app_context.js";
const $dialog = $("#add-link-dialog");
const $form = $("#add-link-form");
@@ -11,7 +12,13 @@ const $addLinkTitleFormGroup = $("#add-link-title-form-group");
export async function showDialog() {
utils.closeActiveDialog();
- $addLinkTitleFormGroup.toggle(!hasSelection());
+ appContext.trigger('executeInActiveEditor', {
+ callback: textEditor => {
+ const hasSelection = !textEditor.model.document.selection.isCollapsed;
+
+ $addLinkTitleFormGroup.toggle(!hasSelection);
+ }
+ });
glob.activeDialog = $dialog;
diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js
index c1f2b7d0a7..21004d67d4 100644
--- a/src/public/javascripts/services/tree.js
+++ b/src/public/javascripts/services/tree.js
@@ -322,7 +322,7 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) {
extraOptions.saveSelection = false;
}
- if (extraOptions.saveSelection) {
+ if (extraOptions.saveSelection && utils.isCKEditorInitialized()) {
[extraOptions.title, extraOptions.content] = parseSelectedHtml(window.cutToNote.getSelectedHtml());
}
@@ -335,7 +335,7 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) {
type: extraOptions.type
});
- if (extraOptions.saveSelection) {
+ if (extraOptions.saveSelection && utils.isCKEditorInitialized()) {
// we remove the selection only after it was saved to server to make sure we don't lose anything
window.cutToNote.removeSelection();
}