Skip to content

Commit

Permalink
Add setting to only show todo in active file
Browse files Browse the repository at this point in the history
Might cover #189
  • Loading branch information
flankstaek committed Jan 11, 2025
1 parent cea69d3 commit 814957a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface TodoSettings {
todoPageName: string
showChecked: boolean
showAllTodos: boolean
showOnlyActiveFile: boolean
autoRefresh: boolean
groupBy: GroupByType
subGroups: boolean
Expand All @@ -23,6 +24,7 @@ export const DEFAULT_SETTINGS: TodoSettings = {
todoPageName: 'todo',
showChecked: false,
showAllTodos: false,
showOnlyActiveFile: false,
autoRefresh: true,
subGroups: false,
groupBy: 'page',
Expand Down Expand Up @@ -95,6 +97,18 @@ export class TodoSettingTab extends PluginSettingTab {
})
})

new Setting(this.containerEl)
.setName('Show only in currently active file?')
.setDesc(
'Show only todos present in currently active file?'
)
.addToggle(toggle => {
toggle.setValue(this.plugin.getSettingValue('showOnlyActiveFile'))
toggle.onChange(async value => {
await this.plugin.updateSettings({showOnlyActiveFile: value})
})
})

/** GORUPING & SORTING */

new Setting(this.containerEl).setName('Grouping & Sorting')
Expand Down
11 changes: 10 additions & 1 deletion src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export default class TodoListView extends ItemView {
await this.refresh()
}),
)
this.registerEvent(
this.app.workspace.on('active-leaf-change', async () => {
if (!this.plugin.getSettingValue('showOnlyActiveFile')) return
await this.refresh()
})
)
this.registerEvent(
this.app.vault.on('delete', file => this.deleteFile(file.path)),
)
Expand Down Expand Up @@ -126,7 +132,10 @@ export default class TodoListView extends ItemView {

private groupItems() {
const flattenedItems = Array.from(this.itemsByFile.values()).flat()
const searchedItems = flattenedItems.filter(e =>
const viewOnlyOpen = this.plugin.getSettingValue('showOnlyActiveFile');
const openFile = this.app.workspace.getActiveFile();
const filteredItems = viewOnlyOpen ? flattenedItems.filter(i => i.filePath === openFile.path) : flattenedItems;
const searchedItems = filteredItems.filter(e =>
e.originalText.toLowerCase().includes(this.searchTerm.toLowerCase()),
)
this.groupedItems = groupTodos(
Expand Down

0 comments on commit 814957a

Please sign in to comment.