Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 044962b

Browse files
committed
improving behaviour
1 parent dc241e4 commit 044962b

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/helpers/FileManagement.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ export function destination_folder(view: DatabaseView, ddbbConfig: LocalSettings
7070
return destination_folder;
7171
}
7272

73-
export function inline_regex_target_in_function_of(position: string, columnId: string, newValue: string) {
73+
export function inline_regex_target_in_function_of(position: string, columnId: string, newValue: string, contentHasFrontmatter: boolean) {
7474
let regex_target = "";
7575
switch (position) {
7676
case INLINE_POSITION.BOTTOM:
77-
regex_target = `$1$2${columnId}:: ${newValue}`;
77+
regex_target = contentHasFrontmatter ? `$1$2\n${columnId}:: ${newValue}` : `$1\n${columnId}:: ${newValue}`;
7878
break;
7979
default:
80-
regex_target = `$1${columnId}:: ${newValue}\n$2`;
80+
regex_target = contentHasFrontmatter ? `$1\n${columnId}:: ${newValue}$2` : `${columnId}:: ${newValue}\n$1`;
8181
}
8282
return regex_target;
8383
}

src/helpers/VaultManagement.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: Lit
232232

233233
async function persistFrontmatter(deletedColumn?: string): Promise<void> {
234234
// If the frontmatter is empty, do not persist it
235-
if (Object.keys(rowFields.frontmatter).length > 0) {
235+
if (Object.keys(rowFields.frontmatter).length > 0 || deletedColumn !== undefined) {
236236
const frontmatterGroupRegex = contentHasFrontmatter ? /^---[\s\S]+?---/g : /(^[\s\S]*$)/g;
237237
const frontmatterFieldsText = parseFrontmatterFieldsToString(rowFields, ddbbConfig, deletedColumn);
238238
const noteObject = {
@@ -265,7 +265,7 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: Lit
265265
newValue: `$3$6$7$8 ${DataviewService.parseLiteral(newValue, InputType.MARKDOWN, ddbbConfig, true)}$10$11`
266266
};
267267
await VaultManagerDB.editNoteContent(noteObject);
268-
await persistFrontmatter();
268+
await persistFrontmatter(columnId);
269269
}
270270

271271
async function inlineColumnKey(): Promise<void> {
@@ -288,18 +288,19 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: Lit
288288
}
289289

290290
async function inlineAddColumn(): Promise<void> {
291-
const inlineAddRegex = new RegExp(`(^---[\\s\\S]+?---\\n)+([\\s\\S]+?$)`, 'g');
291+
const inlineAddRegex = contentHasFrontmatter ? new RegExp(`(^---[\\s\\S]+?---)+([\\s\\S]*$)`, 'g') : new RegExp(`(^[\\s\\S]*$)`, 'g');
292292
const noteObject = {
293293
action: 'replace',
294294
file: file,
295295
regexp: inlineAddRegex,
296296
newValue: inline_regex_target_in_function_of(
297297
ddbbConfig.inline_new_position,
298298
columnId,
299-
DataviewService.parseLiteral(newValue, InputType.MARKDOWN, ddbbConfig).toString()
299+
DataviewService.parseLiteral(newValue, InputType.MARKDOWN, ddbbConfig).toString(),
300+
contentHasFrontmatter
300301
)
301302
};
302-
await persistFrontmatter();
303+
await persistFrontmatter(columnId);
303304
await VaultManagerDB.editNoteContent(noteObject);
304305
}
305306

0 commit comments

Comments
 (0)