fix inserting link

This commit is contained in:
zadam 2020-02-02 11:14:44 +01:00
parent b946599320
commit 34150e7177
2 changed files with 10 additions and 3 deletions

View File

@ -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;

View File

@ -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();
}