From 3cb56a9e8a5282a6828c6ee23cc6827704828932 Mon Sep 17 00:00:00 2001 From: Karlie Fang Date: Fri, 12 Jul 2024 14:51:20 -0400 Subject: [PATCH] fix: remove `meiData` entry after clearing cell Refs: #122 --- src/Editor/MeiTools.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Editor/MeiTools.ts b/src/Editor/MeiTools.ts index 9804310..34d4e04 100644 --- a/src/Editor/MeiTools.ts +++ b/src/Editor/MeiTools.ts @@ -43,21 +43,22 @@ export class MeiTools { ) { const meiData = this.meiData.find((meiData) => meiData.row === row); if (meiData) { - if (mei !== undefined) { - meiData.mei = mei; - } - if (isValid !== undefined) { - meiData.isValid = isValid; - } - if (errorMsg !== undefined) { - meiData.errorMsg = errorMsg; + // Update this.meiData if it exists + if (mei === '') { + // if the mei cell is empty, remove the row from meiData + this.meiData = this.meiData.filter((data) => data.row !== row); + return; } + if (mei !== undefined) meiData.mei = mei; + if (isValid !== undefined) meiData.isValid = isValid; + if (errorMsg !== undefined) meiData.errorMsg = errorMsg; } else { + // Add a new entry to this.meiData if it doesn't exist this.meiData.push({ row, - mei: mei ?? meiData.mei, - isValid: isValid ?? meiData.isValid, - errorMsg: errorMsg ?? meiData.errorMsg, + mei: mei ?? '', + isValid: isValid ?? null, + errorMsg: errorMsg ?? null, }); } }