From 9a1d8a6908868d81bb2bcf57c08534156b63edae Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 3 Jan 2024 17:26:39 -0500 Subject: [PATCH] Add Text.splitText() method to linkedom. (mathjax/MathJax#3134) --- ts/adaptors/linkedomAdaptor.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ts/adaptors/linkedomAdaptor.ts b/ts/adaptors/linkedomAdaptor.ts index bc6c772de..04b1819eb 100644 --- a/ts/adaptors/linkedomAdaptor.ts +++ b/ts/adaptors/linkedomAdaptor.ts @@ -66,6 +66,22 @@ export class LinkedomAdaptor extends NodeMixin'); - window.HTMLCollection = class {}; // add fake class for missing HTMLCollecton + // + // Add fake class for missing HTMLCollection + // + window.HTMLCollection = class {}; + // + // Add missing splitText() method + // + window.Text.prototype.splitText = function (offset: number) { + const text = this.data; + if (offset > text.length) { + throw Error('Index Size Error'); + } + const newNode = window.document.createTextNode(text.substring(offset)); + this.parentNode.insertBefore(newNode, this.nextSibling); + this.data = text.substring(0, offset); + return newNode; + }; return new LinkedomAdaptor(window, options); }