From 5bc6081f4b35dc81b20bd3e76c92a6ca0e5b3d4e Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Tue, 21 Nov 2023 16:57:53 +0600 Subject: [PATCH 1/5] refactor: . introduce parameter --- src/TaskLineRenderer.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TaskLineRenderer.ts b/src/TaskLineRenderer.ts index 38b747dae2..89ebdd1fb7 100644 --- a/src/TaskLineRenderer.ts +++ b/src/TaskLineRenderer.ts @@ -289,7 +289,7 @@ export class TaskLineRenderer { checkbox.setAttribute('data-line', taskIndex.toString()); if (this.layoutOptions.shortMode) { - this.addTooltip(task, textSpan); + this.addTooltip(task, textSpan, this.isFilenameUnique); } return li; @@ -435,7 +435,7 @@ export class TaskLineRenderer { } } - private addTooltip(task: Task, element: HTMLSpanElement) { + private addTooltip(task: Task, element: HTMLSpanElement, isFilenameUnique: boolean | undefined) { const { recurrenceSymbol, startDateSymbol, @@ -478,7 +478,7 @@ export class TaskLineRenderer { addDateToTooltip(tooltip, task.dueDate, dueDateSymbol); addDateToTooltip(tooltip, task.doneDate, doneDateSymbol); - const linkText = task.getLinkText({ isFilenameUnique: this.isFilenameUnique }); + const linkText = task.getLinkText({ isFilenameUnique: isFilenameUnique }); if (linkText) { const backlinkDiv = tooltip.createDiv(); backlinkDiv.setText(`🔗 ${linkText}`); From 018c78237b4230b153727c079425d1f31d40235d Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Tue, 21 Nov 2023 16:58:35 +0600 Subject: [PATCH 2/5] refactor: . shorten param name --- src/TaskLineRenderer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TaskLineRenderer.ts b/src/TaskLineRenderer.ts index 89ebdd1fb7..5868deb60c 100644 --- a/src/TaskLineRenderer.ts +++ b/src/TaskLineRenderer.ts @@ -478,7 +478,7 @@ export class TaskLineRenderer { addDateToTooltip(tooltip, task.dueDate, dueDateSymbol); addDateToTooltip(tooltip, task.doneDate, doneDateSymbol); - const linkText = task.getLinkText({ isFilenameUnique: isFilenameUnique }); + const linkText = task.getLinkText({ isFilenameUnique }); if (linkText) { const backlinkDiv = tooltip.createDiv(); backlinkDiv.setText(`🔗 ${linkText}`); From 92eb5ed8cb3124ac2a576ba0e566ead08429fb8b Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Tue, 21 Nov 2023 17:04:20 +0600 Subject: [PATCH 3/5] refactor: . introduce parameter --- src/QueryRenderer.ts | 2 +- src/TaskLineRenderer.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/QueryRenderer.ts b/src/QueryRenderer.ts index fda26189a3..346390cb74 100644 --- a/src/QueryRenderer.ts +++ b/src/QueryRenderer.ts @@ -227,7 +227,7 @@ class QueryRenderChild extends MarkdownRenderChild { layoutOptions: this.query.layoutOptions, isFilenameUnique, }); - const listItem = await taskLineRenderer.renderTaskLine(task, taskIndex); + const listItem = await taskLineRenderer.renderTaskLine(task, taskIndex, isFilenameUnique); // Remove all footnotes. They don't re-appear in another document. const footnotes = listItem.querySelectorAll('[data-footnote-id]'); diff --git a/src/TaskLineRenderer.ts b/src/TaskLineRenderer.ts index 5868deb60c..90caf6fe29 100644 --- a/src/TaskLineRenderer.ts +++ b/src/TaskLineRenderer.ts @@ -235,8 +235,9 @@ export class TaskLineRenderer { * @note Output is based on the {@link DefaultTaskSerializer}'s format, with default (emoji) symbols * @param task The task to be rendered. * @param taskIndex Task's index in the list. This affects `data-line` data attributes of the list item. + * @param isFilenameUnique */ - public async renderTaskLine(task: Task, taskIndex: number): Promise { + public async renderTaskLine(task: Task, taskIndex: number, isFilenameUnique?: boolean): Promise { const li: HTMLLIElement = document.createElement('li'); this.parentUlElement.appendChild(li); @@ -289,7 +290,7 @@ export class TaskLineRenderer { checkbox.setAttribute('data-line', taskIndex.toString()); if (this.layoutOptions.shortMode) { - this.addTooltip(task, textSpan, this.isFilenameUnique); + this.addTooltip(task, textSpan, isFilenameUnique); } return li; From 585d8a08275b56c3927355a24aeedae5686d5517 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Tue, 21 Nov 2023 17:07:15 +0600 Subject: [PATCH 4/5] refactor: - remove unused parameter --- src/QueryRenderer.ts | 1 - src/TaskLineRenderer.ts | 12 +++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/QueryRenderer.ts b/src/QueryRenderer.ts index 346390cb74..e3ba4b5996 100644 --- a/src/QueryRenderer.ts +++ b/src/QueryRenderer.ts @@ -225,7 +225,6 @@ class QueryRenderChild extends MarkdownRenderChild { obsidianComponent: this, parentUlElement: taskList, layoutOptions: this.query.layoutOptions, - isFilenameUnique, }); const listItem = await taskLineRenderer.renderTaskLine(task, taskIndex, isFilenameUnique); diff --git a/src/TaskLineRenderer.ts b/src/TaskLineRenderer.ts index 90caf6fe29..23dd14769a 100644 --- a/src/TaskLineRenderer.ts +++ b/src/TaskLineRenderer.ts @@ -174,7 +174,6 @@ export class TaskLineRenderer { obsidianComponent: Component | null; parentUlElement: HTMLElement; layoutOptions: LayoutOptions; - isFilenameUnique?: boolean; static async obsidianMarkdownRenderer( text: string, @@ -198,29 +197,22 @@ export class TaskLineRenderer { * @param parentUlElement HTML element where the task shall be rendered. * * @param layoutOptions See {@link LayoutOptions}. - * - * @param isFilenameUnique Whether the name of the file that contains the task is unique in the vault. - * If it is undefined, the outcome will be the same as with a unique file name: the file name only. - * If set to `true`, the full path will be returned. */ constructor({ textRenderer, obsidianComponent, parentUlElement, layoutOptions, - isFilenameUnique, }: { textRenderer: TextRenderer; obsidianComponent: Component | null; parentUlElement: HTMLElement; layoutOptions: LayoutOptions; - isFilenameUnique?: boolean; }) { this.textRenderer = textRenderer; this.obsidianComponent = obsidianComponent; this.parentUlElement = parentUlElement; this.layoutOptions = layoutOptions; - this.isFilenameUnique = isFilenameUnique; } /** @@ -235,7 +227,9 @@ export class TaskLineRenderer { * @note Output is based on the {@link DefaultTaskSerializer}'s format, with default (emoji) symbols * @param task The task to be rendered. * @param taskIndex Task's index in the list. This affects `data-line` data attributes of the list item. - * @param isFilenameUnique + * @param isFilenameUnique Whether the name of the file that contains the task is unique in the vault. + * If it is undefined, the outcome will be the same as with a unique file name: + * the file name only. If set to `true`, the full path will be returned. */ public async renderTaskLine(task: Task, taskIndex: number, isFilenameUnique?: boolean): Promise { const li: HTMLLIElement = document.createElement('li'); From 25d8f2b998257d04dd5ed3f3a8f8562551d6491c Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Tue, 21 Nov 2023 17:11:39 +0600 Subject: [PATCH 5/5] refactor: - reuse TaskLineRenderer objects --- src/InlineRenderer.ts | 16 ++++++++-------- src/QueryRenderer.ts | 15 ++++++++------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/InlineRenderer.ts b/src/InlineRenderer.ts index f4a5da3491..246e9c5c8c 100644 --- a/src/InlineRenderer.ts +++ b/src/InlineRenderer.ts @@ -87,26 +87,26 @@ export class InlineRenderer { } } + const taskLineRenderer = new TaskLineRenderer({ + textRenderer: TaskLineRenderer.obsidianMarkdownRenderer, + obsidianComponent: childComponent, + parentUlElement: element, + layoutOptions: new LayoutOptions(), + }); + // The section index is the nth task within this section. for (let sectionIndex = 0; sectionIndex < renderedElements.length; sectionIndex++) { const task = fileTasks[sectionIndex]; - const renderedElement = renderedElements[sectionIndex]; + const renderedElement = renderedElements[sectionIndex]; if (task === undefined || renderedElement === undefined) { // Assuming match of tasks in file and render preview. // If there is a mis-match in the numbers, we still process // what we can. continue; } - const dataLine: string = renderedElement.getAttr('data-line') ?? '0'; const taskIndex: number = Number.parseInt(dataLine, 10); - const taskLineRenderer = new TaskLineRenderer({ - textRenderer: TaskLineRenderer.obsidianMarkdownRenderer, - obsidianComponent: childComponent, - parentUlElement: element, - layoutOptions: new LayoutOptions(), - }); const taskElement = await taskLineRenderer.renderTaskLine(task, taskIndex); // If the rendered element contains a sub-list or sub-div (e.g. the diff --git a/src/QueryRenderer.ts b/src/QueryRenderer.ts index e3ba4b5996..13e26ed3ec 100644 --- a/src/QueryRenderer.ts +++ b/src/QueryRenderer.ts @@ -217,15 +217,16 @@ class QueryRenderChild extends MarkdownRenderChild { taskList.addClasses(layout.taskListHiddenClasses); const groupingAttribute = this.getGroupingAttribute(); if (groupingAttribute && groupingAttribute.length > 0) taskList.dataset.taskGroupBy = groupingAttribute; + + const taskLineRenderer = new TaskLineRenderer({ + textRenderer: TaskLineRenderer.obsidianMarkdownRenderer, + obsidianComponent: this, + parentUlElement: taskList, + layoutOptions: this.query.layoutOptions, + }); + for (const [taskIndex, task] of tasks.entries()) { const isFilenameUnique = this.isFilenameUnique({ task }); - - const taskLineRenderer = new TaskLineRenderer({ - textRenderer: TaskLineRenderer.obsidianMarkdownRenderer, - obsidianComponent: this, - parentUlElement: taskList, - layoutOptions: this.query.layoutOptions, - }); const listItem = await taskLineRenderer.renderTaskLine(task, taskIndex, isFilenameUnique); // Remove all footnotes. They don't re-appear in another document.