AppFlowy-IO / AppFlowy-IO/appflowy-editor

[Bug] replaceText has the possibility of throwing `Bad state: no element`

オープン
#767 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug p0
主要言語
Dart
スター
684
フォーク
329
PR マージ指標
30日以内にマージされた PR はありません

説明

### Bug Description

The transaction of `replaceText` does not check the length of the Delta before calling `.first`.

### How to Reproduce

Immediately after inserting a TextDelta with no attribute, call replaceText.

Eg.
```
final transaction = editorState.transaction
..insertTextDelta(
node,
selection.end.offset,
Delta(operations: [TextInsert('insert')]),
)
..replaceText(
node,
selection.end.offset - 3,
3,
'replacement',
);
```

### Expected Behavior

Change the code in `replaceText`:
```
var newAttributes = attributes;
if (index != 0 && attributes == null) {
newAttributes = delta.slice(max(index - 1, 0), index).first.attributes;
if (newAttributes == null) {
final slicedDelta = delta.slice(index, index + length);
if (slicedDelta.isNotEmpty) {
newAttributes = slicedDelta.first.attributes;
}
}
}
```
To add a required check and make sure the logic is correct.

Specifically the call to `.first` on `delta.slice(max(index - 1, 0), index)` is what might fail.

### Operating System

*

### AppFlowy Editor Version(s)

main

### Screenshots

_No response_

### Additional Context

_No response_

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。