mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 02:02:29 +08:00
feat(admonitions): indicate with a checkmark the active type
This commit is contained in:
parent
a3354d4d10
commit
5c9fe3adcd
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user