mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-11 19:13:55 +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 {
|
private _getValue(): AdmonitionType | false {
|
||||||
const selection = this.editor.model.document.selection;
|
const selection = this.editor.model.document.selection;
|
||||||
|
|
||||||
const firstBlock = first( selection.getSelectedBlocks() );
|
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.
|
// In the current implementation, the admonition must be an immediate parent of a block element.
|
||||||
// TODO: Read correct quote.
|
const firstQuote = findQuote( firstBlock );
|
||||||
const result = !!( firstBlock && findQuote( firstBlock ) );
|
if (firstQuote?.is("element")) {
|
||||||
return result ? "note" : false;
|
return firstQuote.getAttribute("type") as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,6 +13,7 @@ import { addListToDropdown, createDropdown, ListDropdownButtonDefinition, ViewMo
|
|||||||
import '../theme/blockquote.css';
|
import '../theme/blockquote.css';
|
||||||
import admonitionIcon from '../theme/icons/admonition.svg';
|
import admonitionIcon from '../theme/icons/admonition.svg';
|
||||||
import { Collection } from '@ckeditor/ckeditor5-utils';
|
import { Collection } from '@ckeditor/ckeditor5-utils';
|
||||||
|
import AdmonitionCommand from './admonitioncommand';
|
||||||
|
|
||||||
interface AdmonitionDefinition {
|
interface AdmonitionDefinition {
|
||||||
title: string;
|
title: string;
|
||||||
@ -97,6 +98,7 @@ export default class AdmonitionUI extends Plugin {
|
|||||||
|
|
||||||
private _getDropdownItems() {
|
private _getDropdownItems() {
|
||||||
const itemDefinitions = new Collection<ListDropdownButtonDefinition>();
|
const itemDefinitions = new Collection<ListDropdownButtonDefinition>();
|
||||||
|
const command = this.editor.commands.get("admonition") as AdmonitionCommand
|
||||||
|
|
||||||
for (const [ type, admonition ] of Object.entries(ADMONITION_TYPES)) {
|
for (const [ type, admonition ] of Object.entries(ADMONITION_TYPES)) {
|
||||||
const definition: ListDropdownButtonDefinition = {
|
const definition: ListDropdownButtonDefinition = {
|
||||||
@ -104,10 +106,12 @@ export default class AdmonitionUI extends Plugin {
|
|||||||
model: new ViewModel({
|
model: new ViewModel({
|
||||||
commandParam: type,
|
commandParam: type,
|
||||||
label: admonition.title,
|
label: admonition.title,
|
||||||
|
role: 'menuitemradio',
|
||||||
withText: true
|
withText: true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
definition.model.bind("isOn").to(command, "value", currentType => currentType === type);
|
||||||
itemDefinitions.add(definition);
|
itemDefinitions.add(definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user