feat(admonitions): indicate with a checkmark the active type

This commit is contained in:
Elian Doran 2025-03-13 22:47:21 +02:00
parent a3354d4d10
commit 5c9fe3adcd
2 changed files with 14 additions and 5 deletions

View File

@ -78,13 +78,18 @@ export default class AdmonitionCommand extends Command {
*/
private _getValue(): AdmonitionType | false {
const selection = this.editor.model.document.selection;
const firstBlock = first( selection.getSelectedBlocks() );
if (!firstBlock) {
return false;
}
// In the current implementation, the block quote must be an immediate parent of a block element.
// TODO: Read correct quote.
const result = !!( firstBlock && findQuote( firstBlock ) );
return result ? "note" : false;
// In the current implementation, the admonition must be an immediate parent of a block element.
const firstQuote = findQuote( firstBlock );
if (firstQuote?.is("element")) {
return firstQuote.getAttribute("type") as string;
}
return false;
}
/**

View File

@ -13,6 +13,7 @@ import { addListToDropdown, createDropdown, ListDropdownButtonDefinition, ViewMo
import '../theme/blockquote.css';
import admonitionIcon from '../theme/icons/admonition.svg';
import { Collection } from '@ckeditor/ckeditor5-utils';
import AdmonitionCommand from './admonitioncommand';
interface AdmonitionDefinition {
title: string;
@ -97,6 +98,7 @@ export default class AdmonitionUI extends Plugin {
private _getDropdownItems() {
const itemDefinitions = new Collection<ListDropdownButtonDefinition>();
const command = this.editor.commands.get("admonition") as AdmonitionCommand
for (const [ type, admonition ] of Object.entries(ADMONITION_TYPES)) {
const definition: ListDropdownButtonDefinition = {
@ -104,10 +106,12 @@ export default class AdmonitionUI extends Plugin {
model: new ViewModel({
commandParam: type,
label: admonition.title,
role: 'menuitemradio',
withText: true
})
}
definition.model.bind("isOn").to(command, "value", currentType => currentType === type);
itemDefinitions.add(definition);
}