fix(editor): time issues of comment initialization (#13031)

#### 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 -->
This commit is contained in:
L-Sun
2025-07-04 16:19:00 +08:00
committed by GitHub
parent a485ad5c45
commit eb56adea46
7 changed files with 111 additions and 68 deletions

View File

@@ -138,8 +138,10 @@ class AffineCommentService implements CommentProvider {
this.commentEntity.highlightComment(id);
}
getComments(): string[] {
return this.commentEntity.getComments();
async getComments(
type: 'resolved' | 'unresolved' | 'all' = 'all'
): Promise<string[]> {
return this.commentEntity.getComments(type);
}
onCommentAdded(callback: (id: string, selections: BaseSelection[]) => void) {

View File

@@ -14,7 +14,16 @@ import {
onStart,
} from '@toeverything/infra';
import { nanoid } from 'nanoid';
import { catchError, of, Subject, switchMap, tap, timer } from 'rxjs';
import {
catchError,
filter,
first,
of,
Subject,
switchMap,
tap,
timer,
} from 'rxjs';
import { type DocDisplayMetaService } from '../../doc-display-meta';
import { GlobalContextService } from '../../global-context';
@@ -280,8 +289,30 @@ export class DocCommentEntity extends Entity<{
this.commentHighlighted$.next(id);
}
getComments(): CommentId[] {
return this.comments$.value.map(comment => comment.id);
async getComments(
type: 'resolved' | 'unresolved' | 'all' = 'all'
): Promise<CommentId[]> {
return new Promise<CommentId[]>(resolve => {
this.revalidate();
this.loading$
.pipe(
filter(loading => !loading),
first()
)
.subscribe(() => {
resolve(
this.comments$.value
.filter(comment =>
type === 'all'
? true
: type === 'resolved'
? comment.resolved
: !comment.resolved
)
.map(comment => comment.id)
);
});
});
}
onCommentAdded(

View File

@@ -214,9 +214,12 @@ export class Editor extends Entity {
const std = editorContainer.host.std;
// First try to find inline commented texts
const inlineCommentedSelections = findCommentedTexts(std, commentId);
const inlineCommentedSelections = findCommentedTexts(
std.store,
commentId
);
if (inlineCommentedSelections.length > 0) {
const firstSelection = inlineCommentedSelections[0][0];
const firstSelection = inlineCommentedSelections[0];
finalId = firstSelection.from.blockId;
finalKey = 'blockIds';
} else {