mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
fix access to editor instance if active note is not text
This commit is contained in:
parent
8c46e96397
commit
722380e7b8
@ -93,7 +93,7 @@ $form.submit(() => {
|
||||
$dialog.modal('hide');
|
||||
|
||||
const linkHref = '#' + notePath;
|
||||
const editor = noteDetailService.getActiveComponent().getEditor();
|
||||
const editor = noteDetailService.getActiveEditor();
|
||||
|
||||
if (hasSelection()) {
|
||||
editor.execute('link', linkHref);
|
||||
@ -128,7 +128,7 @@ $form.submit(() => {
|
||||
|
||||
// returns true if user selected some text, false if there's no selection
|
||||
function hasSelection() {
|
||||
const model = noteDetailService.getActiveComponent().getEditor().model;
|
||||
const model = noteDetailService.getActiveEditor().model;
|
||||
const selection = model.document.selection;
|
||||
|
||||
return !selection.isCollapsed;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import libraryLoader from "../services/library_loader.js";
|
||||
import infoService from "../services/info.js";
|
||||
import utils from "../services/utils.js";
|
||||
import noteDetailTextService from "../services/note_detail_text.js";
|
||||
import noteDetailService from "../services/note_detail.js";
|
||||
|
||||
const $dialog = $('#markdown-import-dialog');
|
||||
const $importTextarea = $('#markdown-import-textarea');
|
||||
@ -16,7 +16,7 @@ async function convertMarkdownToHtml(text) {
|
||||
|
||||
const result = writer.render(parsed);
|
||||
|
||||
const textEditor = noteDetailTextService.getEditor();
|
||||
const textEditor = noteDetailService.getActiveEditor();
|
||||
const viewFragment = textEditor.data.processor.toView(result);
|
||||
const modelFragment = textEditor.data.toModel(viewFragment);
|
||||
|
||||
|
@ -73,21 +73,25 @@ function goToLink(e) {
|
||||
}
|
||||
|
||||
function addLinkToEditor(linkTitle, linkHref) {
|
||||
const editor = noteDetailService.getActiveComponent().getEditor();
|
||||
const editor = noteDetailService.getActiveEditor();
|
||||
|
||||
editor.model.change( writer => {
|
||||
const insertPosition = editor.model.document.selection.getFirstPosition();
|
||||
writer.insertText(linkTitle, { linkHref: linkHref }, insertPosition);
|
||||
});
|
||||
if (editor) {
|
||||
editor.model.change(writer => {
|
||||
const insertPosition = editor.model.document.selection.getFirstPosition();
|
||||
writer.insertText(linkTitle, {linkHref: linkHref}, insertPosition);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function addTextToEditor(text) {
|
||||
const editor = noteDetailService.getActiveComponent().getEditor();
|
||||
const editor = noteDetailService.getActiveEditor();
|
||||
|
||||
editor.model.change(writer => {
|
||||
const insertPosition = editor.model.document.selection.getFirstPosition();
|
||||
writer.insertText(text, insertPosition);
|
||||
});
|
||||
if (editor) {
|
||||
editor.model.change(writer => {
|
||||
const insertPosition = editor.model.document.selection.getFirstPosition();
|
||||
writer.insertText(text, insertPosition);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
@ -85,6 +85,17 @@ function getActiveComponent() {
|
||||
return getActiveTabContext().getComponent();
|
||||
}
|
||||
|
||||
function getActiveEditor() {
|
||||
const activeTabContext = getActiveTabContext();
|
||||
|
||||
if (activeTabContext && activeTabContext.note && activeTabContext.note.type === 'text') {
|
||||
return activeTabContext.getComponent().getEditor();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function getTabContexts() {
|
||||
return tabContexts;
|
||||
}
|
||||
@ -482,6 +493,7 @@ export default {
|
||||
getTabContext,
|
||||
getTabContexts,
|
||||
getActiveTabContext,
|
||||
getActiveEditor,
|
||||
isActive,
|
||||
activateTabContext,
|
||||
getActiveComponent,
|
||||
|
Loading…
x
Reference in New Issue
Block a user