From 13b25676724d51ba9e9fdb4bd87481c5486e8af7 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Fri, 26 Sep 2025 08:58:23 +0200 Subject: [PATCH] Avoids potential null reference error Ensures that the modal element is not null before attempting to append it to the document body or remove it from its parent node. This prevents potential errors if the modal element is not properly initialized. --- settings.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/settings.ts b/settings.ts index e1da8c3..c449d85 100644 --- a/settings.ts +++ b/settings.ts @@ -254,7 +254,7 @@ class ConfirmModal { private title: string; private message: string; private callback: (result: boolean) => void; - private modalEl: HTMLElement; + private modalEl: HTMLElement | null = null; constructor(app: App, title: string, message: string, callback: (result: boolean) => void) { this.app = app; @@ -284,7 +284,9 @@ class ConfirmModal { const confirmButton = buttons.createEl('button', { text: 'Confirm', cls: 'mod-warning' }); confirmButton.onclick = () => this.close(true); - document.body.appendChild(this.modalEl); + if (this.modalEl) { + document.body.appendChild(this.modalEl); + } confirmButton.focus(); } @@ -292,6 +294,7 @@ class ConfirmModal { if (this.modalEl && this.modalEl.parentNode) { this.modalEl.parentNode.removeChild(this.modalEl); } + this.modalEl = null; this.callback(result); } } \ No newline at end of file