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:
L-Sun
2025-07-03 20:30:07 +08:00
committed by GitHub
parent c5b442225f
commit 558279da29
4 changed files with 73 additions and 12 deletions
+15 -5
View File
@@ -5,8 +5,8 @@ import { type BlockStdScope, TextSelection } from '@blocksuite/std';
import type { InlineEditor } from '@blocksuite/std/inline';
import type { DeltaInsert } from '@blocksuite/store';
export function findCommentedTexts(std: BlockStdScope, commentId: CommentId) {
const selections: [TextSelection, InlineEditor][] = [];
export function findAllCommentedTexts(std: BlockStdScope) {
const selections: [TextSelection, InlineEditor<AffineTextAttributes>][] = [];
std.store.getAllModels().forEach(model => {
const inlineEditor = getInlineEditorByModel(std, model);
if (!inlineEditor) return;
@@ -19,9 +19,7 @@ export function findCommentedTexts(std: BlockStdScope, commentId: CommentId) {
(delta, rangeIndex) => {
if (
delta.attributes &&
Object.keys(delta.attributes).some(
key => key === `comment-${commentId}`
)
Object.keys(delta.attributes).some(key => key.startsWith('comment-'))
) {
selections.push([
new TextSelection({
@@ -42,6 +40,18 @@ export function findCommentedTexts(std: BlockStdScope, commentId: CommentId) {
return selections;
}
export function findCommentedTexts(std: BlockStdScope, commentId: CommentId) {
return findAllCommentedTexts(std).filter(([selection, inlineEditor]) => {
const deltas = inlineEditor.getDeltasByInlineRange({
index: selection.from.index,
length: selection.from.length,
});
return deltas
.flatMap(([delta]) => extractCommentIdFromDelta(delta))
.includes(commentId);
});
}
export function extractCommentIdFromDelta(
delta: DeltaInsert<AffineTextAttributes>
) {