Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(docs): find cursor by cood (#3105)

Ran Luo5d80b5b4485d
diff --git a/packages/engine-render/src/components/docs/layout/doc-skeleton.ts b/packages/engine-render/src/components/docs/layout/doc-skeleton.ts
index 60e90f4720..1eca696f50 100644
--- a/packages/engine-render/src/components/docs/layout/doc-skeleton.ts
+++ b/packages/engine-render/src/components/docs/layout/doc-skeleton.ts
@@ -66,7 +66,6 @@ interface IDistance {
interface INearestCache {
nearestNodeList: INodeInfo[];
nearestNodeDistanceList: IDistance[];
- nearestNodeDistanceY: number;
}
export interface IFindNodeRestrictions {
@@ -510,7 +509,6 @@ export class DocumentSkeleton extends Skeleton {
const cache: INearestCache = {
nearestNodeList: [],
nearestNodeDistanceList: [],
- nearestNodeDistanceY: Number.POSITIVE_INFINITY,
};
const { pages, skeHeaders, skeFooters } = skeletonData;
@@ -731,6 +729,8 @@ export class DocumentSkeleton extends Skeleton {
}
if (pointInPage) {
+ let nearestNodeDistanceY = Number.POSITIVE_INFINITY;
+
for (const section of sections) {
const { columns } = section;
@@ -794,7 +794,7 @@ export class DocumentSkeleton extends Skeleton {
};
}
- if (cache.nearestNodeDistanceY !== Number.NEGATIVE_INFINITY) {
+ if (nearestNodeDistanceY !== Number.NEGATIVE_INFINITY) {
cache.nearestNodeList = [];
cache.nearestNodeDistanceList = [];
}
@@ -812,17 +812,17 @@ export class DocumentSkeleton extends Skeleton {
nestLevel,
});
- cache.nearestNodeDistanceY = Number.NEGATIVE_INFINITY;
+ nearestNodeDistanceY = Number.NEGATIVE_INFINITY;
continue;
}
- if (distanceY < cache.nearestNodeDistanceY) {
- cache.nearestNodeDistanceY = distanceY;
+ if (distanceY < nearestNodeDistanceY) {
+ nearestNodeDistanceY = distanceY;
cache.nearestNodeList = [];
cache.nearestNodeDistanceList = [];
}
- if (distanceY === cache.nearestNodeDistanceY) {
+ if (distanceY === nearestNodeDistanceY) {
cache.nearestNodeList.push({
node: glyph,
segmentPage: pageType === DocumentSkeletonPageType.BODY ? -1 : pi,