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
client/text editor/content embed widget: fix some issues
Adorian Doran18a5f2aa0890
diff --git a/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.spec.ts b/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.spec.tsindex 5fea5cc561..48f0e504fe 100644--- a/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.spec.ts+++ b/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.spec.ts@@ -271,7 +271,7 @@ describe("ResizableWidgets", () => {expect(getSize()).toBe("<testBox customWidth=\"30em\"></testBox>");});- it("cancels on Escape or a pointercancel, and ignores other pointers", async () => {+ it("cancels on Escape, pointercancel or lost capture, and ignores other pointers", async () => {await createEditor();editor.setData(RESIZED);const box = getBox();@@ -297,6 +297,36 @@ describe("ResizableWidgets", () => {release();expect(box.style.getPropertyValue("--test-width")).toBe("30em");expect(editor.getData()).toBe(RESIZED);++ // The handle loses the pointer when it leaves the page, as when the editor closes.+ const handle = getHandle("width");+ const loseCapture = (pointerId: number) => handle.dispatchEvent(+ new PointerEvent("lostpointercapture", { bubbles: true, pointerId })+ );+ press(handle);+ move(150, 300);+ loseCapture(2);+ expect(box.style.getPropertyValue("--test-width")).toBe("35em");+ loseCapture(1);+ expect(box.style.getPropertyValue("--test-width")).toBe("30em");+ release();+ expect(editor.getData()).toBe(RESIZED);+ });++ it("stops resizing once the editor is destroyed", async () => {+ await createEditor();+ editor.setData("<div class=\"test-box\"></div>");+ press(getHandle("corner"));+ move(150, 350);+ await nextFrame();++ const { editing, model } = editor;+ await editor.destroy();+ const changes = [ vi.spyOn(editing.view, "change"), vi.spyOn(model, "change") ];+ move(200, 400);+ await nextFrame();+ release();+ expect(changes.map((change) => change.mock.calls.length)).toEqual([ 0, 0 ]);});it("resets the size of a handle on a double tap", async () => {diff --git a/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.ts b/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.tsindex 30fd046db0..88dd9f0e39 100644--- a/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.ts+++ b/packages/ckeditor5/src/plugins/resizable_widgets/resizable_widgets.ts@@ -61,6 +61,8 @@ const EM_PATTERN = /^\d+(\.\d+)?em$/;export default class ResizableWidgets extends Plugin {private lastTap: { handle: Element; time: number } | null = null;+ /** Ends the resize under way, if any, without a change. */+ private stopResize: (() => void) | null = null;static get pluginName() {return "ResizableWidgets" as const;@@ -122,6 +124,11 @@ export default class ResizableWidgets extends Plugin {});}+ override destroy() {+ this.stopResize?.();+ super.destroy();+ }+private createHandles(writer: ViewDowncastWriter, subject: ResizeSubject, axes: Axis[]) {const names = axes.length === 2 ? Object.keys(HANDLES) : axes;const startResize = (event: PointerEvent, handle: HTMLElement, name: string) => {@@ -180,7 +187,7 @@ export default class ResizableWidgets extends Plugin {this.showSize(viewElement, getSavedSize(element, config), config, false);};- startResizeGesture(event, {+ this.stopResize = startResizeGesture(event, {handle,axes,widthTarget: targets.width,diff --git a/packages/ckeditor5/src/plugins/resizable_widgets/resize_gesture.ts b/packages/ckeditor5/src/plugins/resizable_widgets/resize_gesture.tsindex 443230de11..8d4c05b72d 100644--- a/packages/ckeditor5/src/plugins/resizable_widgets/resize_gesture.ts+++ b/packages/ckeditor5/src/plugins/resizable_widgets/resize_gesture.ts@@ -28,7 +28,7 @@ export interface ResizeGestureOptions {onPreview: (size: ResizeSize) => void;/** Saves the size at which the pointer is released. */onCommit: (size: ResizeSize) => void;- /** Ends the gesture without a change, on Escape or a `pointercancel`. */+ /** Ends the gesture without a change, on Escape, a `pointercancel` or a lost capture. */onCancel: () => void;/** Ends the gesture when the pointer is released without moving. */onTap: () => void;@@ -46,7 +46,7 @@ const AUTO_SCROLL_STEP = 16;/*** Resizes until the pointer pressed in `event` is released. The width grows towards the inline* end, or on both sides when centered, the height towards the bottom, and the scroll container- * scrolls near its edges.+ * scrolls near its edges. Returns a function that ends the gesture without calling back.*/export function startResizeGesture(event: PointerEvent, options: ResizeGestureOptions) {const { axes, widthTarget, heightTarget } = options;@@ -136,16 +136,21 @@ export function startResizeGesture(event: PointerEvent, options: ResizeGestureOpwindow.removeEventListener("pointermove", onPointerMove, true);window.removeEventListener("pointerup", onPointerUp, true);window.removeEventListener("pointercancel", onPointerCancel, true);+ window.removeEventListener("lostpointercapture", onPointerCancel, true);window.removeEventListener("keydown", onKeyDown, true);};window.addEventListener("pointermove", onPointerMove, true);window.addEventListener("pointerup", onPointerUp, true);window.addEventListener("pointercancel", onPointerCancel, true);+ // The handle loses the pointer when it leaves the page, as when its editor closes.+ window.addEventListener("lostpointercapture", onPointerCancel, true);window.addEventListener("keydown", onKeyDown, true);if (axes.height) {frame = requestAnimationFrame(scrollStep);}++ return stop;}/** The width inside the padding of the parent of `element`. */