From 18ebaa27dcf07eb0ebd4f7842c54dd178e97efe8 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 29 Dec 2024 22:31:16 +0000 Subject: [PATCH 1/6] refactor: ! Remove one use of global app variable - in backlinksClickHandler() --- src/Renderer/QueryRenderer.ts | 30 +++++++++++++++------------- src/Renderer/QueryResultsRenderer.ts | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Renderer/QueryRenderer.ts b/src/Renderer/QueryRenderer.ts index d595fad157..4f2a5c98fc 100644 --- a/src/Renderer/QueryRenderer.ts +++ b/src/Renderer/QueryRenderer.ts @@ -17,7 +17,7 @@ import type { TasksEvents } from '../Obsidian/TasksEvents'; import { TasksFile } from '../Scripting/TasksFile'; import { DateFallback } from '../DateTime/DateFallback'; import type { Task } from '../Task/Task'; -import { QueryResultsRenderer } from './QueryResultsRenderer'; +import { type BacklinksEventHandler, QueryResultsRenderer } from './QueryResultsRenderer'; import { createAndAppendElement } from './TaskLineRenderer'; export class QueryRenderer { @@ -155,7 +155,7 @@ class QueryRenderChild extends MarkdownRenderChild { await this.queryResultsRenderer.render(state, tasks, content, { allTasks: this.plugin.getTasks(), allMarkdownFiles: this.app.vault.getMarkdownFiles(), - backlinksClickHandler, + backlinksClickHandler: createBacklinksClickHandler(this.app), backlinksMousedownHandler, editTaskPencilClickHandler, }); @@ -184,18 +184,20 @@ function editTaskPencilClickHandler(event: MouseEvent, task: Task, allTasks: Tas taskModal.open(); } -async function backlinksClickHandler(ev: MouseEvent, task: Task) { - const result = await getTaskLineAndFile(task, app.vault); - if (result) { - const [line, file] = result; - const leaf = app.workspace.getLeaf(Keymap.isModEvent(ev)); - // When the corresponding task has been found, - // suppress the default behavior of the mouse click event - // (which would interfere e.g. if the query is rendered inside a callout). - ev.preventDefault(); - // Instead of the default behavior, open the file with the required line highlighted. - await leaf.openFile(file, { eState: { line: line } }); - } +function createBacklinksClickHandler(app: App): BacklinksEventHandler { + return async function backlinksClickHandler(ev: MouseEvent, task: Task) { + const result = await getTaskLineAndFile(task, app.vault); + if (result) { + const [line, file] = result; + const leaf = app.workspace.getLeaf(Keymap.isModEvent(ev)); + // When the corresponding task has been found, + // suppress the default behavior of the mouse click event + // (which would interfere e.g. if the query is rendered inside a callout). + ev.preventDefault(); + // Instead of the default behavior, open the file with the required line highlighted. + await leaf.openFile(file, { eState: { line } }); + } + }; } async function backlinksMousedownHandler(ev: MouseEvent, task: Task) { diff --git a/src/Renderer/QueryResultsRenderer.ts b/src/Renderer/QueryResultsRenderer.ts index 3fd7e3d8bb..0341f374e8 100644 --- a/src/Renderer/QueryResultsRenderer.ts +++ b/src/Renderer/QueryResultsRenderer.ts @@ -17,7 +17,7 @@ import { Task } from '../Task/Task'; import { PostponeMenu } from '../ui/Menus/PostponeMenu'; import { TaskLineRenderer, type TextRenderer, createAndAppendElement } from './TaskLineRenderer'; -type BacklinksEventHandler = (ev: MouseEvent, task: Task) => Promise; +export type BacklinksEventHandler = (ev: MouseEvent, task: Task) => Promise; type EditButtonClickHandler = (event: MouseEvent, task: Task, allTasks: Task[]) => void; export interface QueryRendererParameters { From b533a3d90255fbf071ee0b57bc95427056fe8b1d Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 29 Dec 2024 22:33:35 +0000 Subject: [PATCH 2/6] refactor: ! Remove one use of global app variable - in backlinksMousedownHandler() --- src/Renderer/QueryRenderer.ts | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Renderer/QueryRenderer.ts b/src/Renderer/QueryRenderer.ts index 4f2a5c98fc..adc96187cc 100644 --- a/src/Renderer/QueryRenderer.ts +++ b/src/Renderer/QueryRenderer.ts @@ -156,7 +156,7 @@ class QueryRenderChild extends MarkdownRenderChild { allTasks: this.plugin.getTasks(), allMarkdownFiles: this.app.vault.getMarkdownFiles(), backlinksClickHandler: createBacklinksClickHandler(this.app), - backlinksMousedownHandler, + backlinksMousedownHandler: createBacklinksMousedownHandler(this.app), editTaskPencilClickHandler, }); @@ -200,19 +200,21 @@ function createBacklinksClickHandler(app: App): BacklinksEventHandler { }; } -async function backlinksMousedownHandler(ev: MouseEvent, task: Task) { - // Open in a new tab on middle-click. - // This distinction is not available in the 'click' event, so we handle the 'mousedown' event - // solely for this. - // (for regular left-click we prefer the 'click' event, and not to just do everything here, because - // the 'click' event is more generic for touch devices etc.) - if (ev.button === 1) { - const result = await getTaskLineAndFile(task, app.vault); - if (result) { - const [line, file] = result; - const leaf = app.workspace.getLeaf('tab'); - ev.preventDefault(); - await leaf.openFile(file, { eState: { line: line } }); +function createBacklinksMousedownHandler(app: App): BacklinksEventHandler { + return async function backlinksMousedownHandler(ev: MouseEvent, task: Task) { + // Open in a new tab on middle-click. + // This distinction is not available in the 'click' event, so we handle the 'mousedown' event + // solely for this. + // (for regular left-click we prefer the 'click' event, and not to just do everything here, because + // the 'click' event is more generic for touch devices etc.) + if (ev.button === 1) { + const result = await getTaskLineAndFile(task, app.vault); + if (result) { + const [line, file] = result; + const leaf = app.workspace.getLeaf('tab'); + ev.preventDefault(); + await leaf.openFile(file, { eState: { line: line } }); + } } - } + }; } From 1c9dd0c27aa95aede5f2db84496d874abd70f6c2 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 29 Dec 2024 22:36:05 +0000 Subject: [PATCH 3/6] refactor: ! Remove one use of global app variable - in editTaskPencilClickHandler() --- src/Renderer/QueryRenderer.ts | 38 +++++++++++++++------------- src/Renderer/QueryResultsRenderer.ts | 2 +- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/Renderer/QueryRenderer.ts b/src/Renderer/QueryRenderer.ts index adc96187cc..880fbfac23 100644 --- a/src/Renderer/QueryRenderer.ts +++ b/src/Renderer/QueryRenderer.ts @@ -17,7 +17,7 @@ import type { TasksEvents } from '../Obsidian/TasksEvents'; import { TasksFile } from '../Scripting/TasksFile'; import { DateFallback } from '../DateTime/DateFallback'; import type { Task } from '../Task/Task'; -import { type BacklinksEventHandler, QueryResultsRenderer } from './QueryResultsRenderer'; +import { type BacklinksEventHandler, type EditButtonClickHandler, QueryResultsRenderer } from './QueryResultsRenderer'; import { createAndAppendElement } from './TaskLineRenderer'; export class QueryRenderer { @@ -157,31 +157,33 @@ class QueryRenderChild extends MarkdownRenderChild { allMarkdownFiles: this.app.vault.getMarkdownFiles(), backlinksClickHandler: createBacklinksClickHandler(this.app), backlinksMousedownHandler: createBacklinksMousedownHandler(this.app), - editTaskPencilClickHandler, + editTaskPencilClickHandler: createEditTaskPencilClickHandler(this.app), }); this.containerEl.firstChild?.replaceWith(content); } } -function editTaskPencilClickHandler(event: MouseEvent, task: Task, allTasks: Task[]) { - event.preventDefault(); - - const onSubmit = async (updatedTasks: Task[]): Promise => { - await replaceTaskWithTasks({ - originalTask: task, - newTasks: DateFallback.removeInferredStatusIfNeeded(task, updatedTasks), +function createEditTaskPencilClickHandler(app: App): EditButtonClickHandler { + return function editTaskPencilClickHandler(event: MouseEvent, task: Task, allTasks: Task[]) { + event.preventDefault(); + + const onSubmit = async (updatedTasks: Task[]): Promise => { + await replaceTaskWithTasks({ + originalTask: task, + newTasks: DateFallback.removeInferredStatusIfNeeded(task, updatedTasks), + }); + }; + + // Need to create a new instance every time, as cursor/task can change. + const taskModal = new TaskModal({ + app, + task, + onSubmit, + allTasks, }); + taskModal.open(); }; - - // Need to create a new instance every time, as cursor/task can change. - const taskModal = new TaskModal({ - app, - task, - onSubmit, - allTasks, - }); - taskModal.open(); } function createBacklinksClickHandler(app: App): BacklinksEventHandler { diff --git a/src/Renderer/QueryResultsRenderer.ts b/src/Renderer/QueryResultsRenderer.ts index 0341f374e8..bacc3ee00f 100644 --- a/src/Renderer/QueryResultsRenderer.ts +++ b/src/Renderer/QueryResultsRenderer.ts @@ -18,7 +18,7 @@ import { PostponeMenu } from '../ui/Menus/PostponeMenu'; import { TaskLineRenderer, type TextRenderer, createAndAppendElement } from './TaskLineRenderer'; export type BacklinksEventHandler = (ev: MouseEvent, task: Task) => Promise; -type EditButtonClickHandler = (event: MouseEvent, task: Task, allTasks: Task[]) => void; +export type EditButtonClickHandler = (event: MouseEvent, task: Task, allTasks: Task[]) => void; export interface QueryRendererParameters { allTasks: Task[]; From 64dd4a3baa07a7077a544887b4ffe324e47d7762 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 29 Dec 2024 23:11:23 +0000 Subject: [PATCH 4/6] chore: Update the Obsidian API version to 1.4.0, released July 26, 2023 --- package.json | 2 +- src/Obsidian/TasksEvents.ts | 4 ++++ tests/Obsidian/Cache.test.ts | 2 -- yarn.lock | 18 +++++++++--------- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 247fffb8c6..9f65b853f0 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "madge": "^8.0.0", "markdownlint-cli2": "^0.13.0", "moment": "^2.29.4", - "obsidian": "^1.1.1", + "obsidian": "^1.4.0", "prettier": "^2.8.8", "prettier-plugin-svelte": "^2.10.1", "svelte": "^3.59.1", diff --git a/src/Obsidian/TasksEvents.ts b/src/Obsidian/TasksEvents.ts index 88a325694b..9e536bed0b 100644 --- a/src/Obsidian/TasksEvents.ts +++ b/src/Obsidian/TasksEvents.ts @@ -24,6 +24,8 @@ export class TasksEvents { public onCacheUpdate(handler: (cacheData: CacheUpdateData) => void): EventRef { this.logger.debug('TasksEvents.onCacheUpdate()'); + // @ts-expect-error: error TS2345: Argument of type '(cacheData: CacheUpdateData) => void' + // is not assignable to parameter of type '(...data: unknown[]) => unknown'. return this.obsidianEvents.on(Event.CacheUpdate, handler); } @@ -34,6 +36,8 @@ export class TasksEvents { public onRequestCacheUpdate(handler: (fn: (cacheData: CacheUpdateData) => void) => void): EventRef { this.logger.debug('TasksEvents.onRequestCacheUpdate()'); + // @ts-expect-error: error TS2345: Argument of type '(cacheData: CacheUpdateData) => void' + // is not assignable to parameter of type '(...data: unknown[]) => unknown'. return this.obsidianEvents.on(Event.RequestCacheUpdate, handler); } diff --git a/tests/Obsidian/Cache.test.ts b/tests/Obsidian/Cache.test.ts index 60e72e8a62..bbedba4802 100644 --- a/tests/Obsidian/Cache.test.ts +++ b/tests/Obsidian/Cache.test.ts @@ -649,8 +649,6 @@ describe('accessing links in file', function () { }); it('should access links in frontmatter', () => { - // Update to Obsidian API 1.4.0 to access cachedMetadata.frontmatterLinks - // @ts-expect-error TS2551: Property frontmatterLinks does not exist on type CachedMetadata const frontMatterLinks = cachedMetadata['frontmatterLinks']; expect(frontMatterLinks).toBeDefined(); diff --git a/yarn.lock b/yarn.lock index fffe6078d1..1406145ff0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1112,10 +1112,10 @@ dependencies: "@babel/types" "^7.3.0" -"@types/codemirror@0.0.108": - version "0.0.108" - resolved "https://registry.yarnpkg.com/@types/codemirror/-/codemirror-0.0.108.tgz#e640422b666bf49251b384c390cdeb2362585bde" - integrity sha512-3FGFcus0P7C2UOGCNUVENqObEb4SFk+S8Dnxq7K6aIsLVs/vDtlangl3PEO0ykaKXyK56swVF6Nho7VsA44uhw== +"@types/codemirror@5.60.8": + version "5.60.8" + resolved "https://registry.yarnpkg.com/@types/codemirror/-/codemirror-5.60.8.tgz#b647d04b470e8e1836dd84b2879988fc55c9de68" + integrity sha512-VjFgDF/eB+Aklcy15TtOTLQeMjTo07k7KAjql8OK5Dirr7a6sJY4T1uVBDuTVG9VEmn1uUsohOpYnVfgC6/jyw== dependencies: "@types/tern" "*" @@ -4573,12 +4573,12 @@ object.values@^1.1.7: define-properties "^1.2.0" es-abstract "^1.22.1" -obsidian@^1.1.1: - version "1.2.5" - resolved "https://registry.yarnpkg.com/obsidian/-/obsidian-1.2.5.tgz#86a075de3894303b90450fb98af1293918d13bc3" - integrity sha512-RKN4W3PaHsoWwlNRg1SV+iJssQ5vnQYzsCSfmFAUHvA8Q8nzk4pW3HGWXSvor3ZM532KECljG86lEx02OvBwpA== +obsidian@^1.4.0: + version "1.7.2" + resolved "https://registry.yarnpkg.com/obsidian/-/obsidian-1.7.2.tgz#2d989288742ae7a65760fd87a953d1ff2a402808" + integrity sha512-k9hN9brdknJC+afKr5FQzDRuEFGDKbDjfCazJwpgibwCAoZNYHYV8p/s3mM8I6AsnKrPKNXf8xGuMZ4enWelZQ== dependencies: - "@types/codemirror" "0.0.108" + "@types/codemirror" "5.60.8" moment "2.29.4" once@^1.3.0: From b223ebbaa139a654da0d474dbcf8992dab5b7447 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Tue, 31 Dec 2024 07:03:47 +0000 Subject: [PATCH 5/6] chore: Update Obsidian minAppVersion to 1.4.0 in manifest.json --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 686fe845cc..a910dbdd74 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "id": "obsidian-tasks-plugin", "name": "Tasks", "version": "7.14.0", - "minAppVersion": "1.1.1", + "minAppVersion": "1.4.0", "description": "Track tasks across your vault. Supports due dates, recurring tasks, done dates, sub-set of checklist items, and filtering.", "helpUrl": "https://publish.obsidian.md/tasks/", "author": "Clare Macrae and Ilyas Landikov (created by Martin Schenck)", From 378497e96c6c9e465f7d2fb95bd37661c68e3d14 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Thu, 9 Jan 2025 20:45:18 +0000 Subject: [PATCH 6/6] vault: Edit duplicate tasks in Smoke Test to make them different. This is a temporary workaround for #3267, which I discovered whilst testing on this branch. --- .../Smoke Testing the Tasks Plugin.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/resources/sample_vaults/Tasks-Demo/Manual Testing/Smoke Testing the Tasks Plugin.md b/resources/sample_vaults/Tasks-Demo/Manual Testing/Smoke Testing the Tasks Plugin.md index 6eb4916ecf..64d4e8de35 100644 --- a/resources/sample_vaults/Tasks-Demo/Manual Testing/Smoke Testing the Tasks Plugin.md +++ b/resources/sample_vaults/Tasks-Demo/Manual Testing/Smoke Testing the Tasks Plugin.md @@ -149,15 +149,15 @@ heading includes Rendering of Task Blocks - View this file in **Reading mode**... - On the task line above: - - [ ] #task **left**-click on a date value, and use the date picker to select and save a different date. Check that the date is updated. - - [ ] #task **left**-click on a date value, and click outside the date picker, to confirm that the picker closes. - - [ ] #task **right**-click on a date value, and use the context menu to select and save a different date. Check that the date is updated. - - [ ] #task **right**-click on a date value, and click outside the context menu, to confirm that the menu closes. + - [ ] #task **left**-click on a date value (above), and use the date picker to select and save a different date. Check that the date is updated. + - [ ] #task **left**-click on a date value (above), and click outside the date picker, to confirm that the picker closes. + - [ ] #task **right**-click on a date value (above), and use the context menu to select and save a different date. Check that the date is updated. + - [ ] #task **right**-click on a date value (above), and click outside the context menu, to confirm that the menu closes. - In the tasks search block below: - - [ ] #task **left**-click on a date value, and use the date picker to select and save a different date. Check that the date is updated. - - [ ] #task **left**-click on a date value, and click outside the date picker, to confirm that the picker closes. - - [ ] #task **right**-click on a date value, and use the context menu to select and save a different date. Check that the date is updated. - - [ ] #task **right**-click on a date value, and click outside the context menu, to confirm that the menu closes. + - [ ] #task **left**-click on a date value (below), and use the date picker to select and save a different date. Check that the date is updated. + - [ ] #task **left**-click on a date value (below), and click outside the date picker, to confirm that the picker closes. + - [ ] #task **right**-click on a date value (below), and use the context menu to select and save a different date. Check that the date is updated. + - [ ] #task **right**-click on a date value (below), and click outside the context menu, to confirm that the menu closes. - [ ] #task **check**: Checked all above steps for **editing dates** worked ```tasks