mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-01 12:27:41 +08:00
Updated insert command & UI.
This commit is contained in:
parent
4b338fe851
commit
ea1b4d73af
@ -36,16 +36,17 @@ export default class InsertMermaidCommand extends Command {
|
|||||||
execute() {
|
execute() {
|
||||||
const editor = this.editor;
|
const editor = this.editor;
|
||||||
const model = editor.model;
|
const model = editor.model;
|
||||||
|
let mermaidItem;
|
||||||
|
|
||||||
model.change( writer => {
|
model.change( writer => {
|
||||||
const item = writer.createElement( 'mermaid', {
|
mermaidItem = writer.createElement( 'mermaid', {
|
||||||
displayMode: 'split',
|
displayMode: 'split',
|
||||||
source: MOCK_MERMAID_MARKUP
|
source: MOCK_MERMAID_MARKUP
|
||||||
} );
|
} );
|
||||||
|
|
||||||
model.insertContent( item );
|
model.insertContent( mermaidItem );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
editor.editing.view.focus();
|
return mermaidItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import splitModeIcon from '../theme/icons/split-mode.svg';
|
|||||||
import sourceModeIcon from '../theme/icons/source-mode.svg';
|
import sourceModeIcon from '../theme/icons/source-mode.svg';
|
||||||
import infoIcon from '../theme/icons/info.svg';
|
import infoIcon from '../theme/icons/info.svg';
|
||||||
|
|
||||||
/* global window */
|
/* global window, document */
|
||||||
|
|
||||||
export default class MermaidUI extends Plugin {
|
export default class MermaidUI extends Plugin {
|
||||||
/**
|
/**
|
||||||
@ -51,6 +51,7 @@ export default class MermaidUI extends Plugin {
|
|||||||
_addInsertMermaidButton() {
|
_addInsertMermaidButton() {
|
||||||
const editor = this.editor;
|
const editor = this.editor;
|
||||||
const t = editor.t;
|
const t = editor.t;
|
||||||
|
const view = editor.editing.view;
|
||||||
|
|
||||||
editor.ui.componentFactory.add( 'mermaid', locale => {
|
editor.ui.componentFactory.add( 'mermaid', locale => {
|
||||||
const buttonView = new ButtonView( locale );
|
const buttonView = new ButtonView( locale );
|
||||||
@ -66,9 +67,16 @@ export default class MermaidUI extends Plugin {
|
|||||||
|
|
||||||
// Execute the command when the button is clicked.
|
// Execute the command when the button is clicked.
|
||||||
command.listenTo( buttonView, 'execute', () => {
|
command.listenTo( buttonView, 'execute', () => {
|
||||||
editor.execute( 'insertMermaidCommand' );
|
const mermaidItem = editor.execute( 'insertMermaidCommand' );
|
||||||
editor.editing.view.scrollToTheSelection();
|
const mermaidItemViewElement = editor.editing.mapper.toViewElement( mermaidItem );
|
||||||
editor.editing.view.focus();
|
const mermaidItemDomElement = view.domConverter.viewToDom( mermaidItemViewElement, document );
|
||||||
|
|
||||||
|
view.scrollToTheSelection();
|
||||||
|
view.focus();
|
||||||
|
|
||||||
|
if ( mermaidItemDomElement ) {
|
||||||
|
mermaidItemDomElement.querySelector( '.ck-mermaid__editing-view' ).focus();
|
||||||
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
return buttonView;
|
return buttonView;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user