From 2f5d16da35245caabdc14d938599b85638eb327d Mon Sep 17 00:00:00 2001 From: zhe-he Date: Fri, 18 Oct 2024 17:32:32 +0800 Subject: [PATCH 1/3] fix(Canvas): Holding down Shift to select multiple shapes unexpectedly triggers the text exit event --- CHANGELOG.md | 1 + src/canvas/Canvas.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7e299f9594..5f352d51463 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [next] +- fix(Canvas): Holding down Shift to select multiple shapes unexpectedly triggers the text exit event. [#10228](https://github.com/fabricjs/fabric.js/issues/10228) - feat(IText): expose getCursorRenderingData() function. [#10204](https://github.com/fabricjs/fabric.js/pull/10204) - fix(Canvas): allowTouchScrolling interactions [#10078](https://github.com/fabricjs/fabric.js/pull/10078) - update(IText): Add method enterEditingImpl/exitEditingImpl that executes the logic of enterEditing/exitEditing without events [#10187](https://github.com/fabricjs/fabric.js/issues/10187) diff --git a/src/canvas/Canvas.ts b/src/canvas/Canvas.ts index 108f8d39bb1..e10f82ea795 100644 --- a/src/canvas/Canvas.ts +++ b/src/canvas/Canvas.ts @@ -1445,7 +1445,7 @@ export class Canvas extends SelectableCanvas implements CanvasOptions { } this._fireSelectionEvents(prevActiveObjects, e); } else { - (activeObject as IText).exitEditing && + (activeObject as IText).isEditing && (activeObject as IText).exitEditing(); // add the active object and the target to the active selection and set it as the active object const klass = From a4ba5a492dcd94d7df2874d1870d4727968b9b6f Mon Sep 17 00:00:00 2001 From: zhe-he Date: Mon, 21 Oct 2024 10:45:09 +0800 Subject: [PATCH 2/3] update(canvas): add jest --- src/canvas/Canvas.spec.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/canvas/Canvas.spec.ts b/src/canvas/Canvas.spec.ts index abd4c2da767..6f32c8dda02 100644 --- a/src/canvas/Canvas.spec.ts +++ b/src/canvas/Canvas.spec.ts @@ -1,5 +1,6 @@ import { Canvas } from './Canvas'; import { Rect } from '../shapes/Rect'; +import { IText } from '../shapes/IText/IText'; describe('Canvas', () => { describe('touchStart', () => { @@ -111,4 +112,32 @@ describe('Canvas', () => { expect(evt.preventDefault).not.toHaveBeenCalled(); }); }); + + describe("handleMultiSelection", () => { + const canvas = new Canvas(); + const rect = new Rect({ left: 100, width: 100, height: 100 }); + const iText = new IText("itext"); + canvas.add(rect, iText); + test("Selecting shapes containing text does not trigger the exit event", () => { + const exitMock = jest.fn(); + iText.on('editing:exited', exitMock); + + const firstClick = new MouseEvent('click', { + clientX: 0, + clientY: 0 + }); + canvas._onMouseDown(firstClick); + canvas._onMouseUp(firstClick); + const secondClick = new MouseEvent("click", { + shiftKey: true, + clientX: 100, + clientY: 0, + }); + canvas._onMouseDown(secondClick); + canvas._onMouseUp(secondClick); + + expect(exitMock).toHaveBeenCalledTimes(0); + }) + }); + }); From e0f0797d6a324ca03c56358c0e4f10638dc9395f Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Wed, 13 Nov 2024 11:35:19 +0100 Subject: [PATCH 3/3] fix test --- src/canvas/Canvas.spec.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/canvas/Canvas.spec.ts b/src/canvas/Canvas.spec.ts index bdb6620f297..e3921ea0539 100644 --- a/src/canvas/Canvas.spec.ts +++ b/src/canvas/Canvas.spec.ts @@ -1,6 +1,7 @@ import { Canvas } from './Canvas'; import { Rect } from '../shapes/Rect'; import { IText } from '../shapes/IText/IText'; +import '../shapes/ActiveSelection'; describe('Canvas', () => { describe('touchStart', () => { @@ -141,22 +142,22 @@ describe('Canvas', () => { }); }); - describe("handleMultiSelection", () => { + describe('handleMultiSelection', () => { const canvas = new Canvas(); const rect = new Rect({ left: 100, width: 100, height: 100 }); - const iText = new IText("itext"); + const iText = new IText('itext'); canvas.add(rect, iText); - test("Selecting shapes containing text does not trigger the exit event", () => { + test('Selecting shapes containing text does not trigger the exit event', () => { const exitMock = jest.fn(); iText.on('editing:exited', exitMock); const firstClick = new MouseEvent('click', { clientX: 0, - clientY: 0 + clientY: 0, }); canvas._onMouseDown(firstClick); canvas._onMouseUp(firstClick); - const secondClick = new MouseEvent("click", { + const secondClick = new MouseEvent('click', { shiftKey: true, clientX: 100, clientY: 0, @@ -165,7 +166,6 @@ describe('Canvas', () => { canvas._onMouseUp(secondClick); expect(exitMock).toHaveBeenCalledTimes(0); - }) + }); }); - });