Skip to content

Build your personal knowledge base with Trilium Notes

client/text editor/content embed: tweak resizing

Adorian Doran3d0891737ed9
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Include Note.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Include Note.html
index 9c38869dfc..5fd9baf596 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Include Note.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Include Note.html
@@ -45,21 +45,21 @@
to any width and height. A <em>Tiny</em> or <em>Full</em> include always fits
its content.</p>
<ul>
- <li>To resize an include, select it and drag one of its handles: the handle
- on its right edge changes the width, the handle on its bottom edge changes
- the height, and the handle in its bottom-right corner changes both. In
- right-to-left text, the width handle is on the left edge. With a mouse,
- the handles also show while the pointer is over the include.</li>
- <li>The handles work with a mouse, a pen or a finger. On a touch screen, tap
- the include first to show them.</li>
+ <li>To resize an include, select it and drag the handle in its bottom-right
+ corner. To change only the width or only the height, drag the middle of
+ its right or bottom edge instead, where a touch screen shows a handle too.
+ In right-to-left text, the handle is in the bottom-left corner and the
+ width changes from the left edge.</li>
+ <li>Resizing works with a mouse, a pen or a finger.</li>
<li>While the height changes, moving the handle near the top or the bottom
of the note scrolls the note.</li>
<li>An include narrower than the note is centered, so changing its width moves
both of its sides. Making it as wide as the note returns it to the full
width.</li>
<li>To cancel a resize, press <kbd>Esc</kbd> before releasing the handle.</li>
- <li>To reset the size, double-click a handle, or double-tap it on a touch
- screen. The corner handle resets both the width and the height.</li>
+ <li>To reset the size, double-click the corner handle, or double-tap it on
+ a touch screen. Double-clicking the right or bottom edge resets only the
+ width or the height.</li>
<li>Choosing a box size resets the height. Choosing <em>Tiny</em> or <em>Full</em> resets
the width too.</li>
<li>While an <em>Expandable</em> include is collapsed, only its width can be
diff --git a/docs/User Guide/User Guide/Note Types/Text/Include Note.md b/docs/User Guide/User Guide/Note Types/Text/Include Note.md
index 6f2ce9aa9e..c101190f8b 100644
--- a/docs/User Guide/User Guide/Note Types/Text/Include Note.md
+++ b/docs/User Guide/User Guide/Note Types/Text/Include Note.md
@@ -33,12 +33,12 @@ The dialog that includes a note selects that size once the note is picked, and y
A _Small_, _Medium_ or _Expandable_ include can be resized to any width and height. A _Tiny_ or _Full_ include always fits its content.
-* To resize an include, select it and drag one of its handles: the handle on its right edge changes the width, the handle on its bottom edge changes the height, and the handle in its bottom-right corner changes both. In right-to-left text, the width handle is on the left edge. With a mouse, the handles also show while the pointer is over the include.
-* The handles work with a mouse, a pen or a finger. On a touch screen, tap the include first to show them.
+* To resize an include, select it and drag the handle in its bottom-right corner. To change only the width or only the height, drag the middle of its right or bottom edge instead, where a touch screen shows a handle too. In right-to-left text, the handle is in the bottom-left corner and the width changes from the left edge.
+* Resizing works with a mouse, a pen or a finger.
* While the height changes, moving the handle near the top or the bottom of the note scrolls the note.
* An include narrower than the note is centered, so changing its width moves both of its sides. Making it as wide as the note returns it to the full width.
* To cancel a resize, press <kbd>Esc</kbd> before releasing the handle.
-* To reset the size, double-click a handle, or double-tap it on a touch screen. The corner handle resets both the width and the height.
+* To reset the size, double-click the corner handle, or double-tap it on a touch screen. Double-clicking the right or bottom edge resets only the width or the height.
* Choosing a box size resets the height. Choosing _Tiny_ or _Full_ resets the width too.
* While an _Expandable_ include is collapsed, only its width can be changed.
diff --git a/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.spec.ts b/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.spec.ts
index 459129d2cb..5fea5cc561 100644
--- a/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.spec.ts
+++ b/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.spec.ts
@@ -8,6 +8,7 @@ import {
WidgetToolbarRepository
} from "ckeditor5";
import { beforeEach, describe, expect, it, vi } from "vitest";
+import { cdp, userEvent } from "vitest/browser";
import { createTestEditor } from "../../../test/editor-kit.js";
import { TestBoxPlugin } from "../../../test/fixture-plugins.js";
@@ -132,6 +133,51 @@ describe("ResizableWidgets", () => {
expect(getBox().classList.contains("ck-widget_resizable")).toBe(true);
});
+ it("shows the handles of a selected widget in a focused editor only", async () => {
+ await createEditor();
+ editor.setData("<p>text</p><div class=\"test-box\"></div>");
+ const handles = getBox().querySelector(".ck-widget__resize-handles");
+ const box = editor.model.document.getRoot()?.getChild(1);
+ if (!handles || !box) {
+ throw new Error("Expected the handles of a box.");
+ }
+ const getDisplay = () => getComputedStyle(handles).display;
+ const getGrip = (name: string) => getComputedStyle(getHandle(name), "::after").content;
+
+ await userEvent.hover(getBox());
+ expect(getDisplay()).toBe("none");
+
+ editor.model.change((writer) => writer.setSelection(box, "on"));
+ expect(getBox().classList.contains("ck-widget_selected")).toBe(true);
+ expect(getDisplay()).toBe("none");
+
+ editor.editing.view.focus();
+ await expect.poll(getDisplay).toBe("block");
+ expect([ getGrip("width"), getGrip("height"), getGrip("corner") ])
+ .toEqual([ "none", "none", "\"\"" ]);
+
+ if (document.activeElement instanceof HTMLElement) {
+ document.activeElement.blur();
+ }
+ await expect.poll(getDisplay).toBe("none");
+ });
+
+ it("shows grips on the edges too on a touch screen", async () => {
+ const session = cdp() as { send(method: string, params: object): Promise<unknown> };
+ await session.send("Emulation.setTouchEmulationEnabled", { enabled: true });
+ registerTestCleanup(async () => {
+ await session.send("Emulation.setTouchEmulationEnabled", { enabled: false });
+ });
+ expect(matchMedia("(pointer: coarse)").matches).toBe(true);
+
+ await createEditor();
+ editor.setData("<div class=\"test-box\"></div>");
+ const getGrip = (name: string) => getComputedStyle(getHandle(name), "::after").content;
+
+ expect([ getGrip("width"), getGrip("height"), getGrip("corner") ])
+ .toEqual([ "\"\"", "\"\"", "\"\"" ]);
+ });
+
it("marks a widget resizable while isResizable allows it", async () => {
await createEditor({ isResizable: (element) => element.getAttribute("kind") !== "fixed" });
editor.setData("<div class=\"test-box\"></div><p>text</p>");
diff --git a/packages/ckeditor5/src/theme/resizable_widgets.css b/packages/ckeditor5/src/theme/resizable_widgets.css
index f04fe5d6b7..27a59f31a3 100644
--- a/packages/ckeditor5/src/theme/resizable_widgets.css
+++ b/packages/ckeditor5/src/theme/resizable_widgets.css
@@ -1,8 +1,9 @@
:where(:root) {
--ck-resize-handle-color: var(--ck-color-focus-border);
--ck-resize-handle-hit-size: 12px;
- --ck-resize-handle-length: 32px;
- --ck-resize-handle-thickness: 4px;
+ --ck-resize-handle-grip-size: 8px;
+ --ck-resize-handle-grip-length: 32px;
+ --ck-resize-handle-grip-thickness: 4px;
}
@media (pointer: coarse) {
@@ -18,12 +19,10 @@
pointer-events: none;
}
-.ck .ck-widget_resizable:is(.ck-widget_selected, .ck-widget_resizing) > .ck-widget__resize-handles {
- display: block;
-}
-
-@media (hover: hover) {
- .ck .ck-widget_resizable:hover > .ck-widget__resize-handles {
+/* A widget stays selected while the editor is blurred. */
+.ck.ck-editor__editable.ck-focused .ck-widget_resizable.ck-widget_selected,
+.ck .ck-widget_resizable.ck-widget_resizing {
+ > .ck-widget__resize-handles {
display: block;
}
}
@@ -40,14 +39,20 @@
touch-action: none;
&::after {
- content: "";
position: absolute;
inset: 50% auto auto 50%;
- border-radius: var(--ck-resize-handle-thickness);
+ border-radius: var(--ck-resize-handle-grip-thickness);
background-color: var(--ck-resize-handle-color);
translate: -50% -50%;
}
+ /* The edges show a grip on a touch screen only. */
+ @media (pointer: coarse) {
+ &::after {
+ content: "";
+ }
+ }
+
/* Edge handles cover the middle half of the edge, away from the type-around buttons. */
&.ck-widget__resize-handle_width {
inset-block: 25%;
@@ -56,8 +61,8 @@
cursor: ew-resize;
&::after {
- width: var(--ck-resize-handle-thickness);
- height: min(var(--ck-resize-handle-length), 100%);
+ width: var(--ck-resize-handle-grip-thickness);
+ height: min(var(--ck-resize-handle-grip-length), 100%);
}
}
@@ -68,8 +73,8 @@
cursor: ns-resize;
&::after {
- width: min(var(--ck-resize-handle-length), 100%);
- height: var(--ck-resize-handle-thickness);
+ width: min(var(--ck-resize-handle-grip-length), 100%);
+ height: var(--ck-resize-handle-grip-thickness);
}
}
@@ -85,8 +90,10 @@
}
&::after {
- width: calc(var(--ck-resize-handle-thickness) * 2);
- height: calc(var(--ck-resize-handle-thickness) * 2);
+ content: "";
+ border-radius: 50%;
+ width: var(--ck-resize-handle-grip-size);
+ height: var(--ck-resize-handle-grip-size);
}
}
}