mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 11:36:25 +08:00
eb56adea46
#### PR Dependency Tree * **PR #13031** 👈 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** * Added the ability to filter comments by their resolution status (resolved, unresolved, or all) when viewing or managing comments. * **Refactor** * Improved the way commented text is identified and retrieved, resulting in more reliable comment selection and filtering. * Enhanced comment retrieval to support asynchronous data loading, ensuring up-to-date comment information. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
import type { CommentId } from '@blocksuite/affine-shared/services';
|
|
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
|
import { TextSelection } from '@blocksuite/std';
|
|
import type { DeltaInsert, Store } from '@blocksuite/store';
|
|
|
|
export function findAllCommentedTexts(
|
|
store: Store
|
|
): Map<TextSelection, CommentId> {
|
|
const result = new Map<TextSelection, CommentId>();
|
|
|
|
store.getAllModels().forEach(model => {
|
|
if (!model.text) return;
|
|
|
|
let index = 0;
|
|
model.text.toDelta().forEach(delta => {
|
|
if (!delta.insert) return;
|
|
|
|
const length = delta.insert.length;
|
|
|
|
if (!delta.attributes) {
|
|
index += length;
|
|
return;
|
|
}
|
|
|
|
Object.keys(delta.attributes)
|
|
.filter(key => key.startsWith('comment-'))
|
|
.forEach(key => {
|
|
const commentId = key.replace('comment-', '');
|
|
const selection = new TextSelection({
|
|
from: {
|
|
blockId: model.id,
|
|
index,
|
|
length,
|
|
},
|
|
to: null,
|
|
});
|
|
result.set(selection, commentId);
|
|
});
|
|
|
|
index += length;
|
|
});
|
|
});
|
|
|
|
return result;
|
|
}
|
|
|
|
export function findCommentedTexts(
|
|
store: Store,
|
|
commentId: CommentId
|
|
): TextSelection[] {
|
|
return [...findAllCommentedTexts(store).entries()]
|
|
.filter(([_, id]) => id === commentId)
|
|
.map(([selection]) => selection);
|
|
}
|
|
|
|
export function extractCommentIdFromDelta(
|
|
delta: DeltaInsert<AffineTextAttributes>
|
|
) {
|
|
if (!delta.attributes) return [];
|
|
|
|
return Object.keys(delta.attributes)
|
|
.filter(key => key.startsWith('comment-'))
|
|
.map(key => key.replace('comment-', ''));
|
|
}
|