Skip to content

Commit 4a239c2

Browse files
update setTaskText signature to allow overwriting inline fields with new values
1 parent 82408e7 commit 4a239c2

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/api/local-api.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ export class DatacoreLocalApi {
191191
return this.api.tryFullQuery(query);
192192
}
193193
/** Sets the text of a given task programmatically. */
194-
public setTaskText(newText: string, task: MarkdownTaskItem): void {
195-
setTaskText(this.app, this.core, newText, task);
194+
public setTaskText(newText: string, task: MarkdownTaskItem, newFields: Record<string, Literal> = {}): void {
195+
setTaskText(this.app, this.core, newText, task, newFields);
196196
}
197197

198198
/** Sets the completion status of a given task programmatically. */

src/utils/fields.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Field } from "expression/field";
2-
import { Literal } from "expression/literal";
2+
import { Literal, Literals } from "expression/literal";
33
import { setInlineField } from "index/import/inline-field";
44
import { MarkdownTaskItem } from "index/types/markdown";
55
import { App } from "obsidian";
@@ -21,10 +21,10 @@ export function useSetField<T extends Literal>(field: Field, onChange?: (newValu
2121
[field, onChange]
2222
);
2323
}
24-
export async function setTaskText(app: App, core: Datacore, text: string, item: MarkdownTaskItem) {
24+
export async function setTaskText(app: App, core: Datacore, text: string, item: MarkdownTaskItem, newFields: Record<string, Literal> = {}) {
2525
let withFields = `${text}${Object.keys(item.$infields).length ? " " : ""}`;
2626
for (let field in item.$infields) {
27-
withFields = setInlineField(withFields, field, item.$infields[field].raw);
27+
withFields = setInlineField(withFields, field, Literals.toString(newFields[field]) ?? item.$infields[field].raw);
2828
}
2929
await rewriteTask(app.vault, core, item, item.$status, withFields);
3030
}

0 commit comments

Comments
 (0)