mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-11-30 17:34:23 +03:00
fix(editor): do not open the icon picker on every click in a callout without icon (#15906)
After the icon of a callout was removed, any click inside the callout, including clicks meant to place the caret in its text, opened the icon picker. The icon can still be added back from the callout toolbar. fix #15292 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Clicking the text area of a callout without an icon no longer opens the icon picker. Clicking an existing icon continues to open the picker, while clicks on the icon’s emoji area remain unaffected. * **Tests** * Added coverage for icon-picker behavior when clicking callout icons and text areas, with and without an icon. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: DarkSky <darksky2048@gmail.com>
This commit is contained in:
1 parent
bb996d298f
commit
a5cbb306c4
2 files changed
+39
-7
No files matched your search
@@ -166,13 +166,6 @@ export class CalloutBlockComponent extends CaptionedBlockComponent<CalloutBlockM
|
||||
return;
|
||||
}
|
||||
|
||||
// If there's no icon, open icon picker on click
|
||||
const icon = this.model.props.icon$.value;
|
||||
if (!icon) {
|
||||
this._toggleIconPicker(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// Only handle clicks when there are no children
|
||||
if (this.model.children.length > 0) {
|
||||
return;
|
||||
|
||||
@@ -15,6 +15,10 @@ import type {
|
||||
} from '@blocksuite/affine-model';
|
||||
import { insertContent } from '@blocksuite/affine-rich-text';
|
||||
import { REFERENCE_NODE } from '@blocksuite/affine-shared/consts';
|
||||
import {
|
||||
IconPickerServiceIdentifier,
|
||||
IconType,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||
import { createDefaultDoc } from '@blocksuite/affine-shared/utils';
|
||||
import type { SingleViewBase } from '@blocksuite/data-view';
|
||||
@@ -270,6 +274,41 @@ test('typing into a sorted database title keeps editing the same row', async ()
|
||||
expect(titleCells[0].dataset.editing).toBe('true');
|
||||
});
|
||||
|
||||
test.each([
|
||||
{ hasIcon: true, target: '[data-testid="callout-emoji"]', opened: true },
|
||||
{ hasIcon: true, target: 'rich-text', opened: false },
|
||||
{ hasIcon: false, target: 'rich-text', opened: false },
|
||||
])(
|
||||
'clicking $target in a callout (icon: $hasIcon) opens the icon picker: $opened',
|
||||
async ({ hasIcon, target, opened }) => {
|
||||
await setupEditor('page', [
|
||||
{
|
||||
setup: di => {
|
||||
di.override(IconPickerServiceIdentifier, () => ({
|
||||
iconPickerComponent: () => ({ update() {}, unmount() {} }),
|
||||
}));
|
||||
},
|
||||
},
|
||||
]);
|
||||
const noteId = addNote(doc);
|
||||
const calloutId = doc.addBlock(
|
||||
'affine:callout',
|
||||
{ icon: hasIcon ? { type: IconType.Emoji, unicode: '💡' } : undefined },
|
||||
noteId
|
||||
);
|
||||
doc.addBlock('affine:paragraph', { text: new Text('text') }, calloutId);
|
||||
await wait();
|
||||
editor
|
||||
.host!.view.getBlock(calloutId)!
|
||||
.querySelector<HTMLElement>(target)!
|
||||
.click();
|
||||
await wait();
|
||||
expect(editor.host!.querySelector('icon-picker-wrapper') !== null).toBe(
|
||||
opened
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
test.each(['page', 'edgeless'] as const)(
|
||||
'table selection preserves its input owner in %s mode',
|
||||
async mode => {
|
||||
|
||||
Reference in new issue
Block a user