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

Commit 7788215

Browse files
committed
Merge branch '134-fr-search-inline-fields-that-do-not-start-the-line-or-be-bold'
2 parents 1bfa405 + 372b998 commit 7788215

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/helpers/QueryHelper.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import { TableColumn } from "cdm/FolderModel";
22
import { DatabaseCore } from "helpers/Constants";
3+
import { LOGGER } from "services/Logger";
34

45
export function generateDataviewTableQuery(columns: TableColumn[], fromQuery: string): string {
56
return `TABLE ${columns
67
.filter((col) => !col.isMetadata)
78
.map((col) => col.key)
89
.join(",")},${DatabaseCore.DATAVIEW_FILE},${DatabaseCore.FRONTMATTER_KEY} ${fromQuery}`
10+
}
11+
12+
13+
export function inlineRegexInFunctionOf(columnId: string) {
14+
const wrappererKey = `_\\*~\``;
15+
const conditionalInitWithField = `[${wrappererKey}]{0,2}${columnId}[${wrappererKey}]{0,2}[:]{2}`;
16+
const thenRegex = `(^${conditionalInitWithField})(.*$)`;
17+
const elseRegex = `(.*)([(])(${conditionalInitWithField})(.*)([)])(.*$)`;
18+
const finalExpression = `(?:(?=(^${conditionalInitWithField})(${thenRegex})|(${elseRegex}))`;
19+
LOGGER.debug(`<=> inlineRegexInFunctionOf: ${finalExpression}`);
20+
return new RegExp(`(?:(?=(^${conditionalInitWithField}))(${thenRegex})|(${elseRegex}))`, 'gm');
921
}

src/helpers/VaultManagement.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { VaultManagerDB } from 'services/FileManagerService';
44
import { LOGGER } from "services/Logger";
55
import NoteInfo from 'services/NoteInfo';
66
import { DatabaseCore, InputType, SourceDataTypes, UpdateRowOptions } from "helpers/Constants";
7-
import { generateDataviewTableQuery } from 'helpers/QueryHelper';
7+
import { generateDataviewTableQuery, inlineRegexInFunctionOf } from 'helpers/QueryHelper';
88
import obtainRowDatabaseFields from 'parsers/FileToRowDatabaseFields';
99
import { parseFrontmatterFieldsToString } from 'parsers/RowDatabaseFieldsToFile';
1010
import { DataviewService } from 'services/DataviewService';
@@ -261,7 +261,7 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: Lit
261261
* INLINE GROUP FUNCTIONS
262262
*******************************************************************************************/
263263
async function inlineColumnEdit(): Promise<void> {
264-
const inlineFieldRegex = new RegExp(`(^${columnId}[:]{2})+(.*$)`, 'gm');
264+
const inlineFieldRegex = inlineRegexInFunctionOf(columnId);
265265
if (!inlineFieldRegex.test(content)) {
266266
await inlineAddColumn();
267267
return;
@@ -274,7 +274,7 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: Lit
274274
action: 'replace',
275275
file: file,
276276
regexp: inlineFieldRegex,
277-
newValue: `$1 ${DataviewService.parseLiteral(newValue, InputType.MARKDOWN, ddbbConfig, true)}`
277+
newValue: `$3$6$7$8 ${DataviewService.parseLiteral(newValue, InputType.MARKDOWN, ddbbConfig, true)}$10$11`
278278
};
279279
await VaultManagerDB.editNoteContent(noteObject);
280280
await persistFrontmatter();
@@ -288,12 +288,12 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: Lit
288288
* group 1 is inline field checking that starts in new line
289289
* group 2 is the current value of inline field
290290
*/
291-
const inlineFieldRegex = new RegExp(`(^${columnId}[:]{2})+(.*$)`, 'gm');
291+
const inlineFieldRegex = inlineRegexInFunctionOf(columnId);
292292
const noteObject = {
293293
action: 'replace',
294294
file: file,
295295
regexp: inlineFieldRegex,
296-
newValue: `${newValue}::$2`
296+
newValue: `$6$7${newValue}:: $4$9$10$11`
297297
};
298298
await VaultManagerDB.editNoteContent(noteObject);
299299
await persistFrontmatter();
@@ -316,11 +316,12 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: Lit
316316
* group 1 is inline field checking that starts in new line
317317
* group 2 is the current value of inline field
318318
*/
319-
const inlineFieldRegex = new RegExp(`(^${columnId}[:]{2}\\s)+([\\w\\W]+?$)`, 'gm');
319+
const inlineFieldRegex = inlineRegexInFunctionOf(columnId);
320320
const noteObject = {
321-
action: 'remove',
321+
action: 'replace',
322322
file: file,
323-
regexp: inlineFieldRegex
323+
regexp: inlineFieldRegex,
324+
newValue: `$6$11`
324325
};
325326
await VaultManagerDB.editNoteContent(noteObject);
326327
}

0 commit comments

Comments
 (0)