@@ -98,9 +98,9 @@ export async function updateRowFileProxy(file: TFile, columnId: string, newValue
9898 */
9999export async function updateRowFile ( file : TFile , columnId : string , newValue : string , state : TableDataType , option : string ) : Promise < void > {
100100 LOGGER . info ( `=>updateRowFile. file: ${ file . path } | columnId: ${ columnId } | newValue: ${ newValue } | option: ${ option } ` ) ;
101- const rowFields = obtainRowDatabaseFields ( file , state . columns ) ;
102101 const content = await VaultManagerDB . obtainContentFromTfile ( file ) ;
103- let currentFrontmatter = VaultManagerDB . ontainCurrentFrontmatter ( content ) ;
102+ const frontmatterKeys = await VaultManagerDB . obtainFrontmatterKeys ( content ) ;
103+ const rowFields = obtainRowDatabaseFields ( file , state . columns , frontmatterKeys ) ;
104104 const column = state . columns . find ( c => c . key === columnId ) ;
105105 // Adds an empty frontmatter at the beginning of the file
106106 async function addFrontmatter ( ) : Promise < void > {
@@ -139,7 +139,8 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
139139 return ;
140140 }
141141 // If field does not exist yet, ignore it
142- if ( ! Object . prototype . hasOwnProperty . call ( currentFrontmatter , columnId ) ) {
142+ if ( ! Object . prototype . hasOwnProperty . call ( rowFields . frontmatter , columnId )
143+ && ! Object . prototype . hasOwnProperty . call ( rowFields . inline , columnId ) ) {
143144 return ;
144145 }
145146
@@ -162,7 +163,7 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
162163
163164 async function persistFrontmatter ( deletedColumn ?: string ) : Promise < void > {
164165 const frontmatterGroupRegex = / ^ - - - [ \s \S ] + ?- - - / g;
165- const frontmatterFieldsText = parseFrontmatterFieldsToString ( rowFields , currentFrontmatter , deletedColumn ) ;
166+ const frontmatterFieldsText = parseFrontmatterFieldsToString ( rowFields , deletedColumn ) ;
166167 const noteObject = {
167168 action : 'replace' ,
168169 file : file ,
@@ -176,15 +177,15 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
176177 * INLINE GROUP FUNCTIONS
177178 *******************************************************************************************/
178179 async function inlineColumnEdit ( ) : Promise < void > {
179- /* Regex explanation
180- * group 1 is inline field checking that starts in new line
181- * group 2 is the current value of inline field
182- */
183180 const inlineFieldRegex = new RegExp ( `(^${ columnId } [:]{2})+(.*$)` , 'gm' ) ;
184181 if ( ! inlineFieldRegex . test ( content ) ) {
185182 await inlineAddColumn ( ) ;
186183 return ;
187184 }
185+ /* Regex explanation
186+ * group 1 is inline field checking that starts in new line
187+ * group 2 is the current value of inline field
188+ */
188189 const noteObject = {
189190 action : 'replace' ,
190191 file : file ,
@@ -196,14 +197,14 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
196197 }
197198
198199 async function inlineColumnKey ( ) : Promise < void > {
200+ if ( ! Object . keys ( rowFields . inline ) . contains ( columnId ) ) {
201+ return ;
202+ }
199203 /* Regex explanation
200204 * group 1 is inline field checking that starts in new line
201205 * group 2 is the current value of inline field
202206 */
203207 const inlineFieldRegex = new RegExp ( `(^${ columnId } [:]{2})+(.*$)` , 'gm' ) ;
204- if ( ! inlineFieldRegex . test ( content ) ) {
205- return ;
206- }
207208 const noteObject = {
208209 action : 'replace' ,
209210 file : file ,
@@ -215,15 +216,15 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
215216 }
216217
217218 async function inlineAddColumn ( ) : Promise < void > {
218- const inlineAddRegex = new RegExp ( `(^---\\s+[\\w\\W ]+?\\s+ ---\\s )+(.[\\w\\W]+ )` , 'g' ) ;
219+ const inlineAddRegex = new RegExp ( `(^---[ \\s\\S ]+?---\\n )+(.* )` , 'g' ) ;
219220 const noteObject = {
220221 action : 'replace' ,
221222 file : file ,
222223 regexp : inlineAddRegex ,
223224 newValue : `$1${ columnId } :: ${ newValue } \n$2`
224225 } ;
225- await VaultManagerDB . editNoteContent ( noteObject ) ;
226226 await persistFrontmatter ( ) ;
227+ await VaultManagerDB . editNoteContent ( noteObject ) ;
227228 }
228229
229230 async function inlineRemoveColumn ( ) : Promise < void > {
@@ -238,7 +239,6 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
238239 regexp : inlineFieldRegex
239240 } ;
240241 await VaultManagerDB . editNoteContent ( noteObject ) ;
241- await persistFrontmatter ( columnId ) ;
242242 }
243243 // Record of options
244244 const updateOptions : Record < string , any > = { } ;
@@ -249,10 +249,9 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
249249 // Execute action
250250 if ( updateOptions [ option ] ) {
251251 // Check if file has frontmatter
252- if ( currentFrontmatter === undefined ) {
252+ if ( rowFields . frontmatter ) {
253253 // If not, add it
254254 await addFrontmatter ( ) ;
255- currentFrontmatter = { } ;
256255 }
257256 // Then execute the action
258257 await updateOptions [ option ] ( ) ;
0 commit comments