Skip to content

Build your personal knowledge base with Trilium Notes

feat(text): let an icon take the size of the text it sits in

Elian Doran4110b3d6ad23
diff --git a/packages/ckeditor5/src/plugins/inline_icon/inline_icon.spec.ts b/packages/ckeditor5/src/plugins/inline_icon/inline_icon.spec.ts
index b9466fdb57..35b414f6c3 100644
--- a/packages/ckeditor5/src/plugins/inline_icon/inline_icon.spec.ts
+++ b/packages/ckeditor5/src/plugins/inline_icon/inline_icon.spec.ts
@@ -1,7 +1,7 @@
import {
_getModelData as getModelData, _getViewData as getViewData, _setModelData as setModelData,
type ButtonView, type ClassicEditor, ContextualBalloon, FontBackgroundColor, FontColor,
- GeneralHtmlSupport, Link, Paragraph
+ FontSize, GeneralHtmlSupport, Link, Paragraph
} from "ckeditor5";
import editorStylesheetUrl from "ckeditor5/ckeditor5.css?url";
import { beforeAll, beforeEach, describe, expect, it, type Mock, vi } from "vitest";
@@ -143,6 +143,49 @@ describe("an icon's colour", () => {
});
});
+describe("an icon's size", () => {
+ let editor: ClassicEditor;
+
+ beforeEach(async () => {
+ editor = await createTestEditor([ Paragraph, InlineIcon, FontSize ]);
+ });
+
+ it("is the toolbar's to set, and leaves the run around it whole", () => {
+ editor.setData(`<p>a<span class="tn-icon bx bx-cog"></span>b</p>`);
+ selectTheIcon(editor);
+
+ expect(editor.commands.get("fontSize")?.isEnabled).toBe(true);
+
+ editor.execute("fontSize", { value: "big" });
+ expect(editor.getData())
+ .toBe(`<p>a<span class="text-big"><span class="tn-icon bx bx-cog"></span></span>b</p>`);
+
+ // A line sized as a whole stays one run. An icon the size cannot be put on splits it in
+ // two and is stranded between the halves at the size it started at.
+ editor.setData(`<p>a<span class="tn-icon bx bx-cog"></span>b</p>`);
+ editor.model.change((writer) => {
+ const root = editor.model.document.getRoot();
+ if (root) {
+ writer.setSelection(writer.createRangeIn(root), "in");
+ }
+ });
+
+ editor.execute("fontSize", { value: "big" });
+ expect(editor.getData())
+ .toBe(`<p><span class="text-big">a<span class="tn-icon bx bx-cog"></span>b</span></p>`);
+ });
+
+ it("is the size of the text it is put into, where that text has one", () => {
+ editor.setData(`<p><span class="text-big">big</span></p>`);
+ putCaretAtTheEnd(editor);
+
+ editor.execute("insertIcon", { iconClass: "bx bx-cog" });
+
+ expect(editor.getData()).toBe(`<p><span class="text-big">big`
+ + `<span class="tn-icon bx bx-cog"></span></span></p>`);
+ });
+});
+
describe("the balloon InlineIcon picks in", () => {
let editor: ClassicEditor;
let showIconPicker: Mock<(request: IconPickerRequest) => (() => void) | null>;
diff --git a/packages/ckeditor5/src/plugins/inline_icon/inline_icon_editing.ts b/packages/ckeditor5/src/plugins/inline_icon/inline_icon_editing.ts
index 1627dbbcd5..4aecf9d8c8 100644
--- a/packages/ckeditor5/src/plugins/inline_icon/inline_icon_editing.ts
+++ b/packages/ckeditor5/src/plugins/inline_icon/inline_icon_editing.ts
@@ -39,7 +39,7 @@ export default class InlineIconEditing extends Plugin {
// Self-contained: the caret cannot be put inside it, and it is selected as a unit.
isObject: true,
// Colouring needs no converter of ours; CKEditor's own carry these two.
- allowAttributes: [ ICON_CLASS, "fontColor", "fontBackgroundColor" ]
+ allowAttributes: [ ICON_CLASS, "fontColor", "fontBackgroundColor", "fontSize" ]
});
editor.conversion.for("upcast").elementToElement({