fix: mark-range restore location error

This commit is contained in:
yanmao 2022-01-06 21:36:03 +08:00
parent f34d86eb01
commit 679bb4116f
3 changed files with 7 additions and 10 deletions

View File

@ -59,7 +59,7 @@ const Comment: React.FC<CommentProps> = forwardRef<CommentRef, CommentProps>(
const loading = useSelector((state) => state.loading['comment/fetch']);
useEffect(() => {
if (loading) return;
const list: Array<DataItem> = [];
const tempList: Array<DataItem> = [];
dataSource.forEach((item: DataSourceItem) => {
//获取评论编号对应在编辑器中的所有节点
const elements: Array<NodeInterface> =
@ -74,14 +74,14 @@ const Comment: React.FC<CommentProps> = forwardRef<CommentRef, CommentProps>(
//获取目标评论在编辑器中的 top
const top = getRectTop(elements[0]);
if (top < 0) return;
list.push({
tempList.push({
...item,
top,
type: 'view',
type: list.find((c) => c.id === item.id)?.type || 'view',
});
});
//根据top大小排序越小排在越前面
updateList(list.sort((a, b) => (a.top < b.top ? -1 : 1)));
updateList(tempList.sort((a, b) => (a.top < b.top ? -1 : 1)));
}, [loading, dataSource]);
const remove = (render_id: string, id: number) => {

View File

@ -18,12 +18,9 @@ export type CommentItemProps = Omit<
onOk: (event: React.MouseEvent) => void;
onEdit: (itme: DataItem, info_id: number) => void;
onRemove: (id: string, info_id: number) => void;
} & { ref: React.Ref<HTMLDivElement> };
};
const CommentItem: React.FC<CommentItemProps> = forwardRef<
HTMLDivElement,
CommentItemProps
>(
const CommentItem = forwardRef<HTMLDivElement, CommentItemProps>(
(
{
item,

View File

@ -701,7 +701,7 @@ export default class<T extends MarkRangeOptions> extends MarkPlugin<T> {
.shrinkToElementNode()
.shrinkToTextNode()
.toPath(undefined, container);
paths.push({
paths.unshift({
id: id.split(','),
path: rangePath
? [rangePath.start.path, rangePath.end.path]