Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Canvas): Holding down Shift to select multiple shapes unexpectedly triggers the text exit event #10229

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- fix(): mousedown restore after touch end on dospose [#10250](https://github.com/fabricjs/fabric.js/pull/10250)
- 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)
Expand Down
29 changes: 29 additions & 0 deletions src/canvas/Canvas.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Canvas } from './Canvas';
import { Rect } from '../shapes/Rect';
import { IText } from '../shapes/IText/IText';
import '../shapes/ActiveSelection';

describe('Canvas', () => {
describe('touchStart', () => {
Expand Down Expand Up @@ -139,4 +141,31 @@ describe('Canvas', () => {
);
});
});

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);
});
});
});
2 changes: 1 addition & 1 deletion src/canvas/Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,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 =
Expand Down
Loading