mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 21:19:01 +01: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');
 | 
					            $dialog.modal('hide');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const linkHref = '#' + notePath;
 | 
					            const linkHref = '#' + notePath;
 | 
				
			||||||
            const editor = noteDetailService.getActiveComponent().getEditor();
 | 
					            const editor = noteDetailService.getActiveEditor();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (hasSelection()) {
 | 
					            if (hasSelection()) {
 | 
				
			||||||
                editor.execute('link', linkHref);
 | 
					                editor.execute('link', linkHref);
 | 
				
			||||||
@ -128,7 +128,7 @@ $form.submit(() => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// returns true if user selected some text, false if there's no selection
 | 
					// returns true if user selected some text, false if there's no selection
 | 
				
			||||||
function hasSelection() {
 | 
					function hasSelection() {
 | 
				
			||||||
    const model = noteDetailService.getActiveComponent().getEditor().model;
 | 
					    const model = noteDetailService.getActiveEditor().model;
 | 
				
			||||||
    const selection = model.document.selection;
 | 
					    const selection = model.document.selection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return !selection.isCollapsed;
 | 
					    return !selection.isCollapsed;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
import libraryLoader from "../services/library_loader.js";
 | 
					import libraryLoader from "../services/library_loader.js";
 | 
				
			||||||
import infoService from "../services/info.js";
 | 
					import infoService from "../services/info.js";
 | 
				
			||||||
import utils from "../services/utils.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 $dialog = $('#markdown-import-dialog');
 | 
				
			||||||
const $importTextarea = $('#markdown-import-textarea');
 | 
					const $importTextarea = $('#markdown-import-textarea');
 | 
				
			||||||
@ -16,7 +16,7 @@ async function convertMarkdownToHtml(text) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const result = writer.render(parsed);
 | 
					    const result = writer.render(parsed);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const textEditor = noteDetailTextService.getEditor();
 | 
					    const textEditor = noteDetailService.getActiveEditor();
 | 
				
			||||||
    const viewFragment = textEditor.data.processor.toView(result);
 | 
					    const viewFragment = textEditor.data.processor.toView(result);
 | 
				
			||||||
    const modelFragment = textEditor.data.toModel(viewFragment);
 | 
					    const modelFragment = textEditor.data.toModel(viewFragment);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -73,21 +73,25 @@ function goToLink(e) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function addLinkToEditor(linkTitle, linkHref) {
 | 
					function addLinkToEditor(linkTitle, linkHref) {
 | 
				
			||||||
    const editor = noteDetailService.getActiveComponent().getEditor();
 | 
					    const editor = noteDetailService.getActiveEditor();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    editor.model.change( writer => {
 | 
					    if (editor) {
 | 
				
			||||||
        const insertPosition = editor.model.document.selection.getFirstPosition();
 | 
					        editor.model.change(writer => {
 | 
				
			||||||
        writer.insertText(linkTitle, { linkHref: linkHref }, insertPosition);
 | 
					            const insertPosition = editor.model.document.selection.getFirstPosition();
 | 
				
			||||||
    });
 | 
					            writer.insertText(linkTitle, {linkHref: linkHref}, insertPosition);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function addTextToEditor(text) {
 | 
					function addTextToEditor(text) {
 | 
				
			||||||
    const editor = noteDetailService.getActiveComponent().getEditor();
 | 
					    const editor = noteDetailService.getActiveEditor();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    editor.model.change(writer => {
 | 
					    if (editor) {
 | 
				
			||||||
        const insertPosition = editor.model.document.selection.getFirstPosition();
 | 
					        editor.model.change(writer => {
 | 
				
			||||||
        writer.insertText(text, insertPosition);
 | 
					            const insertPosition = editor.model.document.selection.getFirstPosition();
 | 
				
			||||||
    });
 | 
					            writer.insertText(text, insertPosition);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function init() {
 | 
					function init() {
 | 
				
			||||||
 | 
				
			|||||||
@ -85,6 +85,17 @@ function getActiveComponent() {
 | 
				
			|||||||
    return getActiveTabContext().getComponent();
 | 
					    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() {
 | 
					function getTabContexts() {
 | 
				
			||||||
    return tabContexts;
 | 
					    return tabContexts;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -482,6 +493,7 @@ export default {
 | 
				
			|||||||
    getTabContext,
 | 
					    getTabContext,
 | 
				
			||||||
    getTabContexts,
 | 
					    getTabContexts,
 | 
				
			||||||
    getActiveTabContext,
 | 
					    getActiveTabContext,
 | 
				
			||||||
 | 
					    getActiveEditor,
 | 
				
			||||||
    isActive,
 | 
					    isActive,
 | 
				
			||||||
    activateTabContext,
 | 
					    activateTabContext,
 | 
				
			||||||
    getActiveComponent,
 | 
					    getActiveComponent,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user