mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-15 00:56:26 +08:00
fix(core): should not be able to comment with empty content (#13061)
fix AF-2712 #### PR Dependency Tree * **PR #13061** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * The comment editor now disables the commit button when the editor is empty, preventing accidental submissions. * The commit action is now triggered by pressing Enter together with CMD/CTRL, instead of Enter without Shift. * **Style** * The disabled state styling for the commit button now matches the native HTML `disabled` attribute for improved consistency. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
MarkdownAdapter,
|
||||
} from '@blocksuite/affine/shared/adapters';
|
||||
import {
|
||||
type BlockModel,
|
||||
type DocSnapshot,
|
||||
nanoid,
|
||||
type Store,
|
||||
@@ -152,4 +153,31 @@ export class SnapshotHelper extends Service {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
isDocEmpty(store?: Store): boolean {
|
||||
if (!store) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const checkBlock = (block: BlockModel) => {
|
||||
if (block.text && block.text.length > 0) {
|
||||
return false;
|
||||
}
|
||||
const children = block.children;
|
||||
for (const child of children) {
|
||||
if (!checkBlock(child)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
const blocks = store.blocks.peek();
|
||||
for (const block of Object.values(blocks)) {
|
||||
if (!checkBlock(block.model)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user