From 1501433bec774019cf28157965a9b1144ba67508 Mon Sep 17 00:00:00 2001 From: Hendrik Schmitz Date: Mon, 10 Jun 2024 09:03:58 +0200 Subject: [PATCH] feat(ts-model-api): add method for removing node --- ts-model-api/src/ChildrenAccessor.ts | 2 +- ts-model-api/src/TypedNode.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ts-model-api/src/ChildrenAccessor.ts b/ts-model-api/src/ChildrenAccessor.ts index 57f70f61cd..a01727411c 100644 --- a/ts-model-api/src/ChildrenAccessor.ts +++ b/ts-model-api/src/ChildrenAccessor.ts @@ -47,7 +47,7 @@ export class SingleChildAccessor extends ChildrenAcce public setNew(): ChildT { const existing = this.get(); if (existing !== undefined) { - this.parentNode.removeChild(existing.unwrap()) + existing.remove(); } return this.wrapChild(this.parentNode.addNewChild(this.role, 0, undefined)) } diff --git a/ts-model-api/src/TypedNode.ts b/ts-model-api/src/TypedNode.ts index f8dd4e5ece..a4b663f0f4 100644 --- a/ts-model-api/src/TypedNode.ts +++ b/ts-model-api/src/TypedNode.ts @@ -8,10 +8,14 @@ export class TypedNode implements ITypedNode { return this._node; } + remove(): void { + this._node.getParent()?.removeChild(this._node); + } } export interface ITypedNode { unwrap(): INodeJS + remove(): void } export class UnknownTypedNode extends TypedNode {