From 34150e71777c81b75084b990aee3eede4f47c08a Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 2 Feb 2020 11:14:44 +0100 Subject: [PATCH] fix inserting link --- src/public/javascripts/dialogs/add_link.js | 9 ++++++++- src/public/javascripts/services/tree.js | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/public/javascripts/dialogs/add_link.js b/src/public/javascripts/dialogs/add_link.js index de388063d..1af88acf5 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 c1f2b7d0a..21004d67d 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(); }