Skip to content

Commit

Permalink
fix: changes to tag handling code for iOS
Browse files Browse the repository at this point in the history
iOS added regex related features late and devices are slow to update, so
we shouldn't use these features.

  lookbehind assertion /(?<=\s)\+\S+/ - iOS 16.4 (Released 2023-03-27)
  string.prototype.matchAll - iOS 13 (Released 2019-09-19)

Closes #18
  • Loading branch information
mvgrimes committed Sep 19, 2023
1 parent 1023fbd commit a62a6a8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dist/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "todotxt",
"name": "TodoTxt",
"version": "1.4.0",
"version": "1.4.3",
"minAppVersion": "0.15.0",
"description": "Manage Todo.txt files.",
"author": "Mark Grimes",
Expand Down
3 changes: 2 additions & 1 deletion dist/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"1.3.1": "0.15.0",
"1.3.2": "0.15.0",
"1.3.3": "0.15.0",
"1.4.0": "0.15.0"
"1.4.0": "0.15.0",
"1.4.3": "0.15.0"
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "todotxt",
"name": "TodoTxt",
"version": "1.4.0",
"version": "1.4.3",
"minAppVersion": "0.15.0",
"description": "Manage Todo.txt files.",
"author": "Mark Grimes",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-sample-plugin",
"version": "1.4.0",
"version": "1.4.3",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"main": "dist/main.js",
"scripts": {
Expand Down
27 changes: 18 additions & 9 deletions src/lib/todo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const TODO_RE = RegExp(
);

export class TodoTag {
constructor(public key: string, public value: string) {}
constructor(
public key: string,
public value: string,
) {}
clone() {
return new TodoTag(this.key, this.value);
}
Expand Down Expand Up @@ -249,24 +252,30 @@ export function sortTodo(a: Todo, b: Todo) {
function extractTags(description: string) {
// Don't use \w here for better unicode support
// Per the todo.txt spec (https://github.com/todotxt/todo.txt), context/projects are preceded by a space
// Would like to use lookbehind assertion /(?<=\s)\+\S+/ but that isn't available on iOS (until 16.4 (Released 2023-03-27))
return {
projects: matchAll(description, /(?<=\s)\+\S+/g),
ctx: matchAll(description, /(?<=\s)@\S+/g),
projects: matchAll(description, /\s\+\S+/g),
ctx: matchAll(description, /\s@\S+/g),
tags: matchTags(description),
description: description.replace(/\s+([@+]|\S+:)\S+/g, ''),
};
}

function matchAll(s: string, re: RegExp) {
const results = [...s.matchAll(re)];
return results.map((r) => r[0]);
const results = s.match(re);
return results || [];
}

// Would like to use string.prototype.matchAll but not available on iOS (until 13 (Released 2019-09-19))
function matchTags(s: string) {
const results = [...s.matchAll(/(?<=\s)(\S+):(\S+)/g)];
return results.map((r) => {
return new TodoTag(r[1], r[2]);
});
const re = /\s(\S+):(\S+)/g;
const tags: TodoTag[] = [];
let result;
while ((result = re.exec(s)) !== null) {
tags.push(new TodoTag(result[1], result[2]));
}

return tags;
}

function getDuration(n: number, datePart: string) {
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"1.3.1": "0.15.0",
"1.3.2": "0.15.0",
"1.3.3": "0.15.0",
"1.4.0": "0.15.0"
"1.4.0": "0.15.0",
"1.4.3": "0.15.0"
}

0 comments on commit a62a6a8

Please sign in to comment.