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

Commit 0a50520

Browse files
committed
edit key column works
1 parent 35d0a1c commit 0a50520

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

src/helpers/VaultManagement.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
116116

117117
// Modify key of a column
118118
async function columnKey(): Promise<void> {
119+
if (column.isInline) {
120+
await inlineColumnKey();
121+
return;
122+
}
119123
// Check if the column is already in the frontmatter
120124
// assign an empty value to the new key
121125
rowFields.frontmatter[newValue] = rowFields.frontmatter[columnId] ?? "";
@@ -154,7 +158,25 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
154158
action: 'replace',
155159
file: file,
156160
regexp: frontmatterRegex,
157-
newValue: `$1${newValue} `
161+
newValue: `$1${newValue}`
162+
};
163+
await VaultManagerDB.editNoteContent(noteObject);
164+
}
165+
166+
async function inlineColumnKey(): Promise<void> {
167+
/* Regex explanation
168+
* group 1 is inline field checking that starts in new line
169+
* group 2 is the current value of inline field
170+
*/
171+
const frontmatterRegex = new RegExp(`(^${columnId}[:]{2}\\s)+([\\w\\W]+?$)`, 'gm');
172+
if (!frontmatterRegex.test(content)) {
173+
return;
174+
}
175+
const noteObject = {
176+
action: 'replace',
177+
file: file,
178+
regexp: frontmatterRegex,
179+
newValue: `${newValue}:: $2`
158180
};
159181
await VaultManagerDB.editNoteContent(noteObject);
160182
}

src/services/DatabaseInfo.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,6 @@ export default class DatabaseInfo {
6767
LOGGER.debug(`<=setDatabaseconfigYaml`, `set file ${databaseFilePath} with ${databaseConfigUpdated}`);
6868
}
6969

70-
/**
71-
* modify column key
72-
* @param oldColumnId
73-
* @param newColumnId
74-
*/
75-
async updateColumnKey(oldColumnId: string, newColumnId: string): Promise<void> {
76-
// clone current column configuration
77-
const currentCol = this.yaml.columns[oldColumnId];
78-
// update column id
79-
currentCol.label = newColumnId;
80-
currentCol.accessor = newColumnId;
81-
delete this.yaml.columns[oldColumnId];
82-
this.yaml.columns[newColumnId] = currentCol;
83-
// save on disk
84-
await this.saveOnDisk();
85-
}
86-
8770
/**
8871
* Modify or add properties to a column
8972
* @param columnId
@@ -97,7 +80,6 @@ export default class DatabaseInfo {
9780
}
9881
this.yaml.columns[columnId] = colToUpdate;
9982
if (state !== undefined) {
100-
await this.updateColumnKey(columnId, colToUpdate.accessor);
10183
// Once the column is updated, update the rows in case the key is changed
10284
await Promise.all(state.data.map(async (row: RowDataType) => {
10385
updateRowFile(

0 commit comments

Comments
 (0)