Skip to content

Commit

Permalink
add tag filter for inline todo item scanning #27
Browse files Browse the repository at this point in the history
  • Loading branch information
SeptemberHX committed Feb 26, 2023
1 parent 34610cf commit 20d1a63
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/inlineTodo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import panelHtml, {allDue, allProjectsStr, allTagsStr} from "./panelHtml";
import {debounce} from "ts-debounce";
import {set_origin_todo} from "./mark_todo";
import {
INLINE_TODO_AUTO_COMPLETION,
INLINE_TODO_AUTO_COMPLETION, INLINE_TODO_FILTER_TAG,
INLINE_TODO_ITEM_DESCRIPTION,
INLINE_TODO_NOTE_TITLE_AS_DATE,
settings
Expand Down Expand Up @@ -199,7 +199,8 @@ class TodolistPlugin extends SidebarPlugin {
force_sync: true,
note_title_date: await joplin.settings.value(INLINE_TODO_NOTE_TITLE_AS_DATE),
showDescription: await joplin.settings.value(INLINE_TODO_ITEM_DESCRIPTION),
auto_completion: await joplin.settings.value(INLINE_TODO_AUTO_COMPLETION)
auto_completion: await joplin.settings.value(INLINE_TODO_AUTO_COMPLETION),
filterTags: (await joplin.settings.value(INLINE_TODO_FILTER_TAG)).split('|')
};
}

Expand Down
9 changes: 9 additions & 0 deletions src/inlineTodo/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {SettingItemType} from "../../api/types";
export const INLINE_TODO_NOTE_TITLE_AS_DATE = 'bundle_inline_todo_note_title_as_date';
export const INLINE_TODO_ITEM_DESCRIPTION = 'bundle_inline_todo_item_description';
export const INLINE_TODO_AUTO_COMPLETION = 'bundle_inline_todo_auto_completion';
export const INLINE_TODO_FILTER_TAG = 'bundle_inline_todo_filter_tag';

export namespace settings {
const SECTION = 'BundleInlineTodoSettings';
Expand Down Expand Up @@ -42,6 +43,14 @@ export namespace settings {
label: 'Show hints for todo tags and project. Triggered by "+" and "@". Requires restart'
};

PLUGIN_SETTINGS[INLINE_TODO_FILTER_TAG] = {
value: '',
public: true,
section: SECTION,
type: SettingItemType.String,
label: 'Note tags that you want to avoid in todo item scanning. tag1|tag2|tag3|...'
};

await joplin.settings.registerSettings(PLUGIN_SETTINGS);
}
}
11 changes: 11 additions & 0 deletions src/inlineTodo/todoEngine.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Note, Settings, Summary} from "./types";
import * as chrono from "chrono-node";
import joplin from "../../api";
import {getNoteTags} from "../utils/noteUtils";

const dateStrReg = /^\d{4}-\d{2}-\d{2}$/;

Expand Down Expand Up @@ -42,6 +43,16 @@ export default class TodoEngine {
async search_in_note(note: Note) : Promise<boolean> {
// Conflict notes are duplicates usually
if (note.is_conflict) { return; }

if (this._settings.filterTags.length > 0) {
let noteTags = await getNoteTags(note.id);
for (let tag of noteTags) {
if (this._settings.filterTags.includes(tag.title)) {
return false;
}
}
}

let matches = [];

let folder = await this.get_parent_title(note.parent_id);
Expand Down
2 changes: 2 additions & 0 deletions src/inlineTodo/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export interface Settings {
note_title_date: boolean;
showDescription: boolean;

filterTags: string[];

auto_completion: boolean;
}

Expand Down

0 comments on commit 20d1a63

Please sign in to comment.