Skip to content

Commit

Permalink
fix(Canvas): Holding down Shift to select multiple shapes unexpectedl…
Browse files Browse the repository at this point in the history
…y triggers the text exit event (#10229)
  • Loading branch information
zhe-he authored Nov 13, 2024
1 parent 5c1240d commit 0be721d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
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

0 comments on commit 0be721d

Please sign in to comment.