24 lines
721 B
TypeScript
Raw Normal View History

2022-03-04 13:39:39 +01:00
/**
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
import { Editor } from "ckeditor5";
2022-03-04 13:39:39 +01:00
/**
* Helper function for setting the `isOn` state of buttons.
*
* @private
* @param commandName Short name of the command.
2022-03-04 13:39:39 +01:00
*/
export function checkIsOn( editor: Editor, commandName: string ) {
2022-03-04 13:39:39 +01:00
const selection = editor.model.document.selection;
const mermaidItem = selection.getSelectedElement() || selection.getLastPosition()?.parent;
2022-03-04 13:39:39 +01:00
if ( mermaidItem && mermaidItem.is( 'element', 'mermaid' ) && mermaidItem.getAttribute( 'displayMode' ) === commandName ) {
return true;
}
return false;
}