@@ -94,6 +94,7 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
9494 LOGGER . info ( `=>updateRowFile. file: ${ file . path } | columnId: ${ columnId } | newValue: ${ newValue } | option: ${ option } ` ) ;
9595 const rowFields = obtainRowDatabaseFields ( file , state . columns ) ;
9696 const content = await VaultManagerDB . obtainContentFromTfile ( file ) ;
97+ let currentFrontmatter = VaultManagerDB . ontainCurrentFrontmatter ( content ) ;
9798 const column = state . columns . find ( c => c . key === columnId ) ;
9899
99100 // Adds an empty frontmatter at the beginning of the file
@@ -128,12 +129,15 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
128129 // Modify key of a column
129130 async function columnKey ( ) : Promise < void > {
130131 if ( column . isInline ) {
132+ // Go to inline mode
131133 await inlineColumnKey ( ) ;
132134 return ;
133135 }
134- if ( ! Object . prototype . hasOwnProperty . call ( rowFields . frontmatter , columnId ) ) {
136+ // If field does not exist yet, ignore it
137+ if ( ! Object . prototype . hasOwnProperty . call ( currentFrontmatter , columnId ) ) {
135138 return ;
136139 }
140+
137141 // Check if the column is already in the frontmatter
138142 // assign an empty value to the new key
139143 rowFields . frontmatter [ newValue ] = rowFields . frontmatter [ columnId ] ?? "" ;
@@ -157,7 +161,7 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
157161 action : 'replace' ,
158162 file : file ,
159163 regexp : frontmatterGroupRegex ,
160- newValue : parseFrontmatterFieldsToString ( rowFields , content , deletedColumn )
164+ newValue : parseFrontmatterFieldsToString ( rowFields , currentFrontmatter , deletedColumn )
161165 } ;
162166 await VaultManagerDB . editNoteContent ( noteObject ) ;
163167 }
@@ -238,9 +242,10 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
238242 // Execute action
239243 if ( updateOptions [ option ] ) {
240244 // Check if file has frontmatter
241- if ( ! hasFrontmatterKey ( content ) ) {
245+ if ( currentFrontmatter === undefined ) {
242246 // If not, add it
243247 await addFrontmatter ( ) ;
248+ currentFrontmatter = { } ;
244249 }
245250 // Then execute the action
246251 await updateOptions [ option ] ( ) ;
0 commit comments