filter tags
This commit is contained in:
@@ -104,6 +104,7 @@ class OrgTodoListView extends ItemView {
|
|||||||
input.addEventListener("input", () => {
|
input.addEventListener("input", () => {
|
||||||
this.filterText = input.value.toLowerCase();
|
this.filterText = input.value.toLowerCase();
|
||||||
this.renderList();
|
this.renderList();
|
||||||
|
this.renderTagBar();
|
||||||
});
|
});
|
||||||
|
|
||||||
const toggleWrap = root.createDiv({ cls: "org-todo-toggle" });
|
const toggleWrap = root.createDiv({ cls: "org-todo-toggle" });
|
||||||
@@ -120,8 +121,8 @@ class OrgTodoListView extends ItemView {
|
|||||||
|
|
||||||
async refresh() {
|
async refresh() {
|
||||||
this.tasks = await this.scanVault();
|
this.tasks = await this.scanVault();
|
||||||
this.renderTagBar();
|
|
||||||
this.renderList();
|
this.renderList();
|
||||||
|
this.renderTagBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
async scanFile(file) {
|
async scanFile(file) {
|
||||||
@@ -174,8 +175,8 @@ class OrgTodoListView extends ItemView {
|
|||||||
// Remove all tasks belonging to a given path, then re-render.
|
// Remove all tasks belonging to a given path, then re-render.
|
||||||
removeFile(path) {
|
removeFile(path) {
|
||||||
this.tasks = this.tasks.filter((t) => t.file.path !== path);
|
this.tasks = this.tasks.filter((t) => t.file.path !== path);
|
||||||
this.renderTagBar();
|
|
||||||
this.renderList();
|
this.renderList();
|
||||||
|
this.renderTagBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rescan one file and splice its tasks in, replacing its previous entries.
|
// Rescan one file and splice its tasks in, replacing its previous entries.
|
||||||
@@ -184,21 +185,29 @@ class OrgTodoListView extends ItemView {
|
|||||||
const fresh = await this.scanFile(file);
|
const fresh = await this.scanFile(file);
|
||||||
this.tasks = this.tasks.filter((t) => t.file.path !== file.path);
|
this.tasks = this.tasks.filter((t) => t.file.path !== file.path);
|
||||||
for (const t of fresh) this.tasks.push(t);
|
for (const t of fresh) this.tasks.push(t);
|
||||||
this.renderTagBar();
|
|
||||||
this.renderList();
|
this.renderList();
|
||||||
|
this.renderTagBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
renderTagBar() {
|
renderTagBar() {
|
||||||
this.tagBarEl.empty();
|
this.tagBarEl.empty();
|
||||||
|
|
||||||
|
// Every tag in the vault — the chip bar is a stable, complete palette.
|
||||||
const all = new Set();
|
const all = new Set();
|
||||||
for (const t of this.tasks) t.tags.forEach((x) => all.add(x));
|
for (const t of this.tasks) t.tags.forEach((x) => all.add(x));
|
||||||
|
|
||||||
// Drop any active filters whose tag no longer exists anywhere.
|
// Prune active filters whose tag no longer exists (the ghost-filter fix).
|
||||||
for (const tag of [...this.activeTags]) {
|
for (const tag of [...this.activeTags]) {
|
||||||
if (!all.has(tag)) this.activeTags.delete(tag);
|
if (!all.has(tag)) this.activeTags.delete(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sorted = [...all].sort();
|
// Narrow the CHIPS by the text box. Strip a leading '#' the user may type,
|
||||||
|
// so "#wo" and "wo" both match. Active tags always show so they stay clickable.
|
||||||
|
const needle = this.filterText.replace(/^#/, "");
|
||||||
|
const sorted = [...all].sort().filter(
|
||||||
|
(tag) => !needle || tag.toLowerCase().includes(needle) || this.activeTags.has(tag)
|
||||||
|
);
|
||||||
|
|
||||||
for (const tag of sorted) {
|
for (const tag of sorted) {
|
||||||
const chip = this.tagBarEl.createEl("button", { text: "#" + tag });
|
const chip = this.tagBarEl.createEl("button", { text: "#" + tag });
|
||||||
chip.addClass("org-todo-chip");
|
chip.addClass("org-todo-chip");
|
||||||
@@ -206,8 +215,8 @@ class OrgTodoListView extends ItemView {
|
|||||||
chip.addEventListener("click", () => {
|
chip.addEventListener("click", () => {
|
||||||
if (this.activeTags.has(tag)) this.activeTags.delete(tag);
|
if (this.activeTags.has(tag)) this.activeTags.delete(tag);
|
||||||
else this.activeTags.add(tag);
|
else this.activeTags.add(tag);
|
||||||
this.renderTagBar();
|
|
||||||
this.renderList();
|
this.renderList();
|
||||||
|
this.renderTagBar();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user