mirror of
https://github.com/taskgenius/taskgenius-plugin.git
synced 2026-07-22 06:40:25 +00:00
fix(write): preserve spaces in project and context tags when updating tasks
Allow spaces within project tags (#project/...) and context tags (@context...) when stripping trailing metadata during task updates. This prevents breaking multi-word project and context values.
This commit is contained in:
parent
c93406cbe7
commit
f770126e33
1 changed files with 22 additions and 6 deletions
|
|
@ -570,19 +570,20 @@ export class WriteAPI {
|
|||
"x".repeat(m.length)
|
||||
);
|
||||
|
||||
// Build strict trailing-metadata matcher using recognized Dataview keys
|
||||
// Build trailing-metadata matcher. Recognize Dataview fields and
|
||||
// tolerate spaces inside known tokens like #project/... and @context...
|
||||
const esc = (s: string) =>
|
||||
s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
const projectKey =
|
||||
const dvProjectKey =
|
||||
this.plugin.settings.projectTagPrefix
|
||||
?.dataview || "project";
|
||||
const contextKey =
|
||||
const dvContextKey =
|
||||
this.plugin.settings.contextTagPrefix
|
||||
?.dataview || "context";
|
||||
const dvKeysGroup = [
|
||||
"tags",
|
||||
esc(projectKey),
|
||||
esc(contextKey),
|
||||
esc(dvProjectKey),
|
||||
esc(dvContextKey),
|
||||
"priority",
|
||||
"repeat",
|
||||
"start",
|
||||
|
|
@ -596,11 +597,26 @@ export class WriteAPI {
|
|||
].join("|");
|
||||
const baseEmoji = "(🔺|⏫|🔼|🔽|⏬|🛫|⏳|📅|✅|🔁)";
|
||||
const dvFieldToken = `\\[(?:${dvKeysGroup})\\s*::[^\\]]*\\]`;
|
||||
// Tasks-format prefixes
|
||||
const projectPrefixTasks =
|
||||
this.plugin.settings.projectTagPrefix?.tasks ||
|
||||
"project";
|
||||
const contextPrefixTasks =
|
||||
this.plugin.settings.contextTagPrefix?.tasks ||
|
||||
"@";
|
||||
// Allow spaces within project/context values when stripping trailing metadata
|
||||
const projectWideToken = `#${esc(
|
||||
projectPrefixTasks
|
||||
)}/[^\\n\\r]*`;
|
||||
const atWideToken = `${esc(
|
||||
contextPrefixTasks
|
||||
)}[^\\n\\r]*`;
|
||||
const tagToken = "#[A-Za-z][\\w/-]*";
|
||||
const atToken = "@[A-Za-z][\\w/-]*";
|
||||
const plusToken = "\\+[A-Za-z][\\w/-]*";
|
||||
const emojiSeg = `(?:${baseEmoji}[^\\n]*)`;
|
||||
const token = `(?:${emojiSeg}|${dvFieldToken}|${tagToken}|${atToken}|${plusToken})`;
|
||||
// Prefer the wide tokens first so we consume the full trailing segment
|
||||
const token = `(?:${emojiSeg}|${dvFieldToken}|${projectWideToken}|${atWideToken}|${tagToken}|${atToken}|${plusToken})`;
|
||||
const trailing = new RegExp(`(?:\\s+${token})+$`);
|
||||
const tm = sanitized.match(trailing);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue