Skip to content

Commit

Permalink
Tasks now works on iOS
Browse files Browse the repository at this point in the history
The way that the LI was taken from the path of the event did not work
on mobile. Instead, the list item is now given in an arrow function of
a click handler on the checkbox.

This also means there is no longer the global click event listener.
Overall, some due clean-up happened.

Fixes #22
  • Loading branch information
schemar committed Apr 14, 2021
1 parent 1225516 commit 19df9db
Show file tree
Hide file tree
Showing 11 changed files with 247 additions and 258 deletions.
22 changes: 9 additions & 13 deletions src/Obsidian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,6 @@ export class Obsidian {
this.plugin.addCommand(command);
}

public subscribeToClickEvent(
eventsHandler: (
this: HTMLElement,
ev: HTMLElementEventMap['click'],
) => any,
): void {
this.plugin.registerDomEvent(document, 'click', eventsHandler);
}

public subscribeToLayoutReadyEvent(func: () => void): void {
this.workspace.onLayoutReady(func);
}
Expand Down Expand Up @@ -128,10 +119,15 @@ export class Obsidian {
this.eventReferences.push(eventRef);
}

public subscribeToRenaming(func: (oldPath: string, newPath: string) => Promise<void>) {
const eventRef = this.vault.on('rename', (file: TAbstractFile, oldPath: string) => {
func(oldPath, file.path);
});
public subscribeToRenaming(
func: (oldPath: string, newPath: string) => Promise<void>,
) {
const eventRef = this.vault.on(
'rename',
(file: TAbstractFile, oldPath: string) => {
func(oldPath, file.path);
},
);

this.eventReferences.push(eventRef);
}
Expand Down
126 changes: 0 additions & 126 deletions src/Tasks/Events.ts

This file was deleted.

47 changes: 0 additions & 47 deletions src/Tasks/Render/Checkbox.ts

This file was deleted.

48 changes: 0 additions & 48 deletions src/Tasks/Render/ListItem.ts

This file was deleted.

8 changes: 3 additions & 5 deletions src/Tasks/Render/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class Query {
source: string;
}): ((task: Task) => boolean)[] {
const filters: ((task: Task) => boolean)[] = [];
const sourceLines = source.split('\n').map(line => line.trim());
const sourceLines = source.split('\n').map((line) => line.trim());

for (const sourceLine of sourceLines) {
if (sourceLine === '') {
Expand Down Expand Up @@ -122,11 +122,9 @@ export class Query {
let filter;
const filterMethod = pathMatch[1];
if (filterMethod === 'includes') {
filter = (task: Task) =>
task.path.includes(pathMatch[2]);
filter = (task: Task) => task.path.includes(pathMatch[2]);
} else if (pathMatch[1] === 'does not include') {
filter = (task: Task) =>
!task.path.includes(pathMatch[2]);
filter = (task: Task) => !task.path.includes(pathMatch[2]);
} else {
console.error('Tasks: do not understand path query: ' + line);
return undefined;
Expand Down
15 changes: 9 additions & 6 deletions src/Tasks/Render/Render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,36 @@ import { CLASS_ITEM, Task } from '../Task';
import { Cache } from '../Cache';
import { Query } from './Query';
import { Transclusion } from './Transclusion';
import { Checkbox } from './Checkbox';
import { ListItem } from './ListItem';
import { TaskItem } from './TaskItem';

export class Render {
private readonly cache: Cache;
private readonly taskItem: TaskItem;
private readonly obsidian: Obsidian;

public constructor({
cache,
taskItem,
obsidian,
}: {
cache: Cache;
taskItem: TaskItem;
obsidian: Obsidian;
}) {
this.cache = cache;
this.taskItem = taskItem;
this.obsidian = obsidian;

this.obsidian.registerMarkdownPostProcessor(
this.renderCheckBoxes.bind(this),
this.renderInLineTasks.bind(this),
);

this.obsidian.registerCodeBlockPostProcessor(
this.renderTranscludedTasks.bind(this),
);
}

private renderCheckBoxes(
private renderInLineTasks(
element: HTMLElement,
context: MarkdownPostProcessorContext,
) {
Expand All @@ -52,8 +55,7 @@ export class Render {
return;
}

ListItem.addAttributes({ listItem, task });
Checkbox.prependTo({ listItem, taskStatus: task.status });
this.taskItem.processListItem({ listItem, task });
});
}

Expand All @@ -67,6 +69,7 @@ export class Render {
context.addChild(
new Transclusion({
cache: this.cache,
taskItem: this.taskItem,
container: element,
filters: query.filters,
}),
Expand Down
Loading

0 comments on commit 19df9db

Please sign in to comment.