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

Commit e21bfdc

Browse files
committed
remove inline key works
1 parent 0a50520 commit e21bfdc

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

src/cdm/FolderModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,5 @@ export type NoteContentAction = {
121121
file: TFile,
122122
action: string,
123123
regexp: RegExp,
124-
newValue: string
124+
newValue?: string
125125
}

src/helpers/VaultManagement.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
103103
// update content on disk and in memory
104104
await VaultManagerDB.editNoteContent(noteObject);
105105
}
106-
106+
/*******************************************************************************************
107+
* FRONTMATTER GROUP FUNCTIONS
108+
*******************************************************************************************/
107109
// Modify value of a column
108110
async function columnValue(): Promise<void> {
109111
if (column.isInline) {
@@ -129,6 +131,10 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
129131

130132
// Remove a column
131133
async function removeColumn(): Promise<void> {
134+
if (column.isInline) {
135+
await inlineRemoveColumn();
136+
return;
137+
}
132138
delete rowFields.frontmatter[columnId];
133139
await persistFrontmatter(columnId);
134140
}
@@ -143,21 +149,23 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
143149
};
144150
await VaultManagerDB.editNoteContent(noteObject);
145151
}
146-
152+
/*******************************************************************************************
153+
* INLINE GROUP FUNCTIONS
154+
*******************************************************************************************/
147155
async function inlineColumnEdit(): Promise<void> {
148156
/* Regex explanation
149157
* group 1 is inline field checking that starts in new line
150158
* group 2 is the current value of inline field
151159
*/
152-
const frontmatterRegex = new RegExp(`(^${columnId}[:]{2}\\s)+([\\w\\W]+?$)`, 'gm');
153-
if (!frontmatterRegex.test(content)) {
154-
await addInlineColumn();
160+
const inlineFieldRegex = new RegExp(`(^${columnId}[:]{2}\\s)+([\\w\\W]+?$)`, 'gm');
161+
if (!inlineFieldRegex.test(content)) {
162+
await inlineAddColumn();
155163
return;
156164
}
157165
const noteObject = {
158166
action: 'replace',
159167
file: file,
160-
regexp: frontmatterRegex,
168+
regexp: inlineFieldRegex,
161169
newValue: `$1${newValue}`
162170
};
163171
await VaultManagerDB.editNoteContent(noteObject);
@@ -168,20 +176,20 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
168176
* group 1 is inline field checking that starts in new line
169177
* group 2 is the current value of inline field
170178
*/
171-
const frontmatterRegex = new RegExp(`(^${columnId}[:]{2}\\s)+([\\w\\W]+?$)`, 'gm');
172-
if (!frontmatterRegex.test(content)) {
179+
const inlineFieldRegex = new RegExp(`(^${columnId}[:]{2}\\s)+([\\w\\W]+?$)`, 'gm');
180+
if (!inlineFieldRegex.test(content)) {
173181
return;
174182
}
175183
const noteObject = {
176184
action: 'replace',
177185
file: file,
178-
regexp: frontmatterRegex,
186+
regexp: inlineFieldRegex,
179187
newValue: `${newValue}:: $2`
180188
};
181189
await VaultManagerDB.editNoteContent(noteObject);
182190
}
183191

184-
async function addInlineColumn(): Promise<void> {
192+
async function inlineAddColumn(): Promise<void> {
185193
const inlineAddRegex = new RegExp(`(^---\\s+[\\w\\W]+?\\s+---\\s)+(.[\\w\\W]+)`, 'g');
186194
const noteObject = {
187195
action: 'replace',
@@ -191,6 +199,20 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
191199
};
192200
await VaultManagerDB.editNoteContent(noteObject);
193201
}
202+
203+
async function inlineRemoveColumn(): Promise<void> {
204+
/* Regex explanation
205+
* group 1 is inline field checking that starts in new line
206+
* group 2 is the current value of inline field
207+
*/
208+
const inlineFieldRegex = new RegExp(`(^${columnId}[:]{2}\\s)+([\\w\\W]+?$)`, 'gm');
209+
const noteObject = {
210+
action: 'remove',
211+
file: file,
212+
regexp: inlineFieldRegex
213+
};
214+
await VaultManagerDB.editNoteContent(noteObject);
215+
}
194216
// Record of options
195217
const updateOptions: Record<string, any> = {};
196218
updateOptions[UpdateRowOptions.COLUMN_VALUE] = columnValue;

0 commit comments

Comments
 (0)