From 3f439880219e660626a5d21a4e5aa909e69c4226 Mon Sep 17 00:00:00 2001 From: yuxuan-ctrl <714180720@qq.com> Date: Fri, 1 Sep 2023 16:25:40 +0800 Subject: [PATCH] fix: fix iframe module incomptible with monaco --- src/sandbox/iframe/document.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/sandbox/iframe/document.ts b/src/sandbox/iframe/document.ts index a8f2e9022..de7c07ea4 100644 --- a/src/sandbox/iframe/document.ts +++ b/src/sandbox/iframe/document.ts @@ -65,6 +65,19 @@ function patchDocumentPrototype (appName: string, microAppWindow: microAppWindow const rawMicroGetElementsByClassName = microRootDocument.prototype.getElementsByClassName const rawMicroGetElementsByTagName = microRootDocument.prototype.getElementsByTagName const rawMicroGetElementsByName = microRootDocument.prototype.getElementsByName + const rawMicroElementFromPoint = microRootDocument.prototype.elementFromPoint + const rawMicroCaretRangeFromPoint = microRootDocument.prototype.caretRangeFromPoint + + microRootDocument.prototype.caretRangeFromPoint = function caretRangeFromPoint ( + x: number, + y: number, + ): Range { + // 这里this指向document才可以获取到子应用的document实例,range才可以被成功生成 + const element = rawMicroElementFromPoint.call(document, x, y) + const range = rawMicroCaretRangeFromPoint.call(document, x, y) + updateElementInfo(element, appName) + return range + } microRootDocument.prototype.createElement = function createElement ( tagName: string,