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(*): fix compatibility (#5378)

白熱11e97f27efad
diff --git a/packages/core/src/common/shims.ts b/packages/core/src/common/shims.ts
index f0f8099a80..8de6de5ebd 100644
--- a/packages/core/src/common/shims.ts
+++ b/packages/core/src/common/shims.ts
@@ -87,7 +87,29 @@ function installArrayFindLastIndex() {
}
}
+/**
+ * Polyfill for String.prototype.at
+ */
+function installStringAt() {
+ if (typeof glob.String.prototype.at !== 'function') {
+ glob.String.prototype.at = function at(index: number): string | undefined {
+ if (this == null) {
+ throw new TypeError('String.prototype.at called on null or undefined');
+ }
+ const len = this.length;
+ if (index < 0) {
+ index = len + index;
+ }
+ if (index < 0 || index >= len) {
+ return undefined;
+ }
+ return this.charAt(index);
+ };
+ }
+}
+
export function installShims() {
installRequestIdleCallback();
installArrayFindLastIndex();
+ installStringAt();
}
diff --git a/packages/docs-ui/src/services/doc-event-manager.service.ts b/packages/docs-ui/src/services/doc-event-manager.service.ts
index 7ecd8b3260..75ea3ca329 100644
--- a/packages/docs-ui/src/services/doc-event-manager.service.ts
+++ b/packages/docs-ui/src/services/doc-event-manager.service.ts
@@ -714,10 +714,14 @@ export class DocEventManagerService extends Disposable implements IRenderModule
};
}
- const paragraph = this._paragraphBounds.values().find((bounds) => {
- return bounds.rects.some((rect) => isPointInRect(x, y, rect));
- });
-
+ let paragraph: IMutiPageParagraphBound | undefined;
+ for (const bounds of this._paragraphBounds) {
+ const bound = bounds[1];
+ if (bound.rects.some((rect) => isPointInRect(x, y, rect))) {
+ paragraph = bound;
+ break;
+ }
+ }
return paragraph;
}