mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-05-12 23:28:27 -05:00
fix access to editor instance if active note is not text
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user