Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(text): offer the embed menu on an inline diagram, and no caption toggle
Elian Doranb81ed1afee9c
diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed.tsindex 071384b06b..7ab77a46ce 100644--- a/packages/ckeditor5/src/plugins/content_embed/content_embed.ts+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed.ts@@ -139,6 +139,8 @@ export function getDisplayModeLabel( t: ( message: string ) => string, mode: Disexport default class ContentEmbed extends Plugin {/** The buttons that the content of the selected embed adds to its toolbar, or `null`. */declare public selectedEmbedTools: ContentEmbedToolProvider | null;+ /** Whether the selected embed keeps its source in the note, and so has no title or caption. */+ declare public isSelectedEmbedInline: boolean;static get requires() {return [ ContentEmbedEditing, ContentEmbedUI, ContentEmbedInlineSource ];@@ -152,12 +154,15 @@ export default class ContentEmbed extends Plugin {super( editor );// Set before `init()` of the plugins it requires, whose toolbar items bind to it.this.set( 'selectedEmbedTools', null );+ this.set( 'isSelectedEmbedInline', false );}init() {// Runs before `WidgetToolbarRepository` positions the toolbar from its width.this.listenTo( this.editor.ui, 'update', () => {this.selectedEmbedTools = getSelectedEmbedTools( this.editor );+ const embed = getSelectedContentEmbed( this.editor );+ this.isSelectedEmbedInline = !!embed && isInlineSourceEmbed( embed );}, { priority: 'high' } );}@@ -289,6 +294,8 @@ class ContentEmbedUI extends Plugin {buttonView.bind( 'label' ).to( command, 'value', value =>value ? t( 'Toggle caption off' ) : t( 'Toggle caption on' ) );}+ buttonView.bind( 'isVisible' ).to( editor.plugins.get( ContentEmbed ),+ 'isSelectedEmbedInline', isInline => !isInline );this.listenTo( buttonView, 'execute', () => {editor.execute( TOGGLE_CAPTION_COMMAND_NAME, { focusCaptionOnShow: true } );@@ -385,11 +392,17 @@ class ContentEmbedUI extends Plugin {tooltip: true} );- // Replaces the menu button of the title row while the title is hidden.+ // Replaces the menu button of the title row while the title is hidden, and stands in+ // for it on an embed without one.if ( command ) {- buttonView.bind( 'isEnabled' ).to( command );+ const plugin = editor.plugins.get( ContentEmbed );+ buttonView.bind( 'isEnabled' ).to(+ command, 'isEnabled', plugin, 'isSelectedEmbedInline',+ ( isEnabled, isInline ) => isEnabled || isInline );buttonView.bind( 'isVisible' ).to( command, 'isEnabled', command, 'value',- ( isEnabled, isTitleShown ) => isEnabled && !isTitleShown );+ plugin, 'isSelectedEmbedInline',+ ( isEnabled, isTitleShown, isInline ) =>+ isInline || ( isEnabled && !isTitleShown ) );}this.listenTo( buttonView, 'execute', () => {diff --git a/packages/ckeditor5/src/plugins/content_embed/inline_source.spec.ts b/packages/ckeditor5/src/plugins/content_embed/inline_source.spec.tsindex 94234375ff..76764886dd 100644--- a/packages/ckeditor5/src/plugins/content_embed/inline_source.spec.ts+++ b/packages/ckeditor5/src/plugins/content_embed/inline_source.spec.ts@@ -1,6 +1,7 @@import {_getModelData as getModelData,_setModelData as setModelData,+ ButtonView,ClassicEditor,Essentials,type ModelElement,@@ -14,6 +15,7 @@ import { createTestEditor } from "../../../test/editor-kit.js";import { installGlobMock } from "../../../test/globals-test-kit.js";import { SIZE_ATTRIBUTES } from "../resizable_widgets/resizable_widgets.js";import ContentEmbed, {+ CONTENT_EMBED_MENU,CONVERT_EMBED_TO_LINK_COMMAND,TOGGLE_CAPTION_COMMAND_NAME,TOGGLE_TITLE_COMMAND_NAME@@ -27,7 +29,9 @@ describe("ContentEmbedInlineSource", () => {beforeEach(async () => {loadInlineEmbed = vi.fn();installGlobMock({- getComponentByEl: () => ({ triggerCommand: vi.fn(), loadInlineEmbed })+ getComponentByEl: () => ({+ triggerCommand: vi.fn(), loadEmbeddedNote: vi.fn(), loadInlineEmbed+ })});editor = await createTestEditor([ Essentials, Paragraph, Undo, Widget, ContentEmbed ], {@@ -163,6 +167,23 @@ describe("ContentEmbedInlineSource", () => {expect(loadInlineEmbed.mock.calls[0][3]).toEqual({ isFocused: true });});+ it("offers the menu button in the toolbar, and no caption button", () => {+ const menu = editor.ui.componentFactory.create(CONTENT_EMBED_MENU);+ const caption = editor.ui.componentFactory.create(TOGGLE_CAPTION_COMMAND_NAME);+ if (!(menu instanceof ButtonView) || !(caption instanceof ButtonView)) {+ throw new Error("Expected two buttons.");+ }++ editor.setData(`<pre><code class="language-mermaid">a</code></pre>`);+ editor.model.change((writer) => writer.setSelection(getEmbed(), "on"));+ expect([ menu.isVisible, caption.isVisible ]).toEqual([ true, false ]);++ editor.setData(`<figure class="include-note" data-note-id="n1" data-box-size="medium">`+ + `</figure>`);+ editor.model.change((writer) => writer.setSelection(getEmbed(), "on"));+ expect([ menu.isVisible, caption.isVisible ]).toEqual([ false, true ]);+ });+it("offers no title, caption or link for an embed that shows no note", () => {editor.setData(`<pre><code class="language-mermaid">a</code></pre>`);editor.model.change((writer) => writer.setSelection(getEmbed(), "on"));