mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 06:18:45 +08:00
feat(editor): resolve unassociated comments on init (#13008)
#### PR Dependency Tree * **PR #13008** 👈 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 * **Bug Fixes** * Improved synchronization between comment states in the editor and the comment provider to ensure consistency of inline and block comments. * **Refactor** * Separated and modularized utility functions for finding commented texts and blocks, enhancing maintainability and reusability. * **Style** * Updated styles to remove background color and border from inline comments within embedded note content. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -42,10 +42,10 @@ export class BlockCommentManager extends LifeCycleWatcher {
|
||||
|
||||
this._disposables.add(provider.onCommentAdded(this._handleAddComment));
|
||||
this._disposables.add(
|
||||
provider.onCommentDeleted(this._handleDeleteAndResolve)
|
||||
provider.onCommentDeleted(this.handleDeleteAndResolve)
|
||||
);
|
||||
this._disposables.add(
|
||||
provider.onCommentResolved(this._handleDeleteAndResolve)
|
||||
provider.onCommentResolved(this.handleDeleteAndResolve)
|
||||
);
|
||||
this._disposables.add(
|
||||
provider.onCommentHighlighted(this._handleHighlightComment)
|
||||
@@ -103,7 +103,7 @@ export class BlockCommentManager extends LifeCycleWatcher {
|
||||
});
|
||||
};
|
||||
|
||||
private readonly _handleDeleteAndResolve = (id: CommentId) => {
|
||||
readonly handleDeleteAndResolve = (id: CommentId) => {
|
||||
const commentedBlocks = findCommentedBlocks(this.std.store, id);
|
||||
this.std.store.withoutTransact(() => {
|
||||
commentedBlocks.forEach(block => {
|
||||
|
||||
@@ -5,18 +5,23 @@ import type { BlockModel, Store } from '@blocksuite/store';
|
||||
import type { ToolbarAction } from '../toolbar-service';
|
||||
import { type CommentId, CommentProviderIdentifier } from './comment-provider';
|
||||
|
||||
export function findCommentedBlocks(store: Store, commentId: CommentId) {
|
||||
export function findAllCommentedBlocks(store: Store) {
|
||||
type CommentedBlock = BlockModel<{ comments: Record<CommentId, boolean> }>;
|
||||
return store.getAllModels().filter((block): block is CommentedBlock => {
|
||||
return (
|
||||
'comments' in block.props &&
|
||||
typeof block.props.comments === 'object' &&
|
||||
block.props.comments !== null &&
|
||||
commentId in block.props.comments
|
||||
block.props.comments !== null
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function findCommentedBlocks(store: Store, commentId: CommentId) {
|
||||
return findAllCommentedBlocks(store).filter(block => {
|
||||
return block.props.comments[commentId];
|
||||
});
|
||||
}
|
||||
|
||||
export const blockCommentToolbarButton: Omit<ToolbarAction, 'id'> = {
|
||||
tooltip: 'Comment',
|
||||
when: ({ std }) => !!std.getOptional(CommentProviderIdentifier),
|
||||
|
||||
Reference in New Issue
Block a user