mirror of
https://github.com/brendan-ch/todo-tracker-obsidian.git
synced 2026-04-16 23:00:32 +00:00
Fix linting issues
This commit is contained in:
25
src/main.ts
25
src/main.ts
@@ -1,9 +1,9 @@
|
||||
import { Plugin, WorkspaceLeaf } from 'obsidian';
|
||||
import { DEFAULT_SETTINGS, MyPluginSettings, SampleSettingTab } from './settings';
|
||||
import { DEFAULT_SETTINGS, TodoTrackerSettings, TodoTrackerSettingTab } from './settings';
|
||||
import { TodoSidebarView, TODO_VIEW_TYPE } from './views/todo-sidebar-view';
|
||||
|
||||
export default class TodoTrackerPlugin extends Plugin {
|
||||
settings: MyPluginSettings;
|
||||
settings: TodoTrackerSettings;
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
@@ -14,26 +14,25 @@ export default class TodoTrackerPlugin extends Plugin {
|
||||
});
|
||||
|
||||
// Add ribbon icon to open todo tracker
|
||||
this.addRibbonIcon('check-square', 'Open Todo Tracker', () => {
|
||||
this.activateView();
|
||||
this.addRibbonIcon('check-square', 'Open todo tracker', () => {
|
||||
void this.activateView();
|
||||
});
|
||||
|
||||
// Add command to toggle todo tracker
|
||||
this.addCommand({
|
||||
id: 'open-todo-tracker',
|
||||
name: 'Open Todo Tracker',
|
||||
id: 'open',
|
||||
name: 'Open sidebar',
|
||||
callback: () => {
|
||||
this.activateView();
|
||||
void this.activateView();
|
||||
},
|
||||
});
|
||||
|
||||
// Add settings tab
|
||||
this.addSettingTab(new SampleSettingTab(this.app, this));
|
||||
this.addSettingTab(new TodoTrackerSettingTab(this.app, this));
|
||||
}
|
||||
|
||||
onunload() {
|
||||
// Detach all leaves of this view type to ensure clean unload
|
||||
this.app.workspace.detachLeavesOfType(TODO_VIEW_TYPE);
|
||||
// Cleanup is handled automatically by registered events
|
||||
}
|
||||
|
||||
async activateView(): Promise<void> {
|
||||
@@ -45,7 +44,7 @@ export default class TodoTrackerPlugin extends Plugin {
|
||||
// Reveal the existing view
|
||||
const leaf = existingLeaves[0];
|
||||
if (leaf) {
|
||||
workspace.revealLeaf(leaf);
|
||||
await workspace.revealLeaf(leaf);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -57,12 +56,12 @@ export default class TodoTrackerPlugin extends Plugin {
|
||||
type: TODO_VIEW_TYPE,
|
||||
active: true,
|
||||
});
|
||||
workspace.revealLeaf(leaf);
|
||||
await workspace.revealLeaf(leaf);
|
||||
}
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData() as Partial<MyPluginSettings>);
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData() as Partial<TodoTrackerSettings>);
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import { App, Modal, Setting } from 'obsidian';
|
||||
|
||||
export class DailyNoteSelectModal extends Modal {
|
||||
constructor(app: App, onSubmit: (result: string) => void) {
|
||||
super(app);
|
||||
this.setTitle('Select a daily note');
|
||||
|
||||
let name = '';
|
||||
new Setting(this.contentEl)
|
||||
.setName('Date')
|
||||
.addMomentFormat((component) => {
|
||||
|
||||
});
|
||||
|
||||
new Setting(this.contentEl)
|
||||
.addButton((btn) =>
|
||||
btn
|
||||
.setButtonText('Submit')
|
||||
.setCta()
|
||||
.onClick(() => {
|
||||
constructor(app: App, onSubmit: (result: string) => void) {
|
||||
super(app);
|
||||
this.setTitle('Select a daily note');
|
||||
|
||||
let name = '';
|
||||
new Setting(this.contentEl)
|
||||
.setName('Date')
|
||||
.addMomentFormat((component) => {
|
||||
|
||||
});
|
||||
|
||||
new Setting(this.contentEl)
|
||||
.addButton((btn) =>
|
||||
btn
|
||||
.setButtonText('Submit')
|
||||
.setCta()
|
||||
.onClick(() => {
|
||||
this.close();
|
||||
onSubmit(name);
|
||||
}));
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,8 +55,8 @@ export class HeadingSelectModal extends FuzzySuggestModal<HeadingOption> {
|
||||
return option.displayText;
|
||||
}
|
||||
|
||||
async onChooseItem(option: HeadingOption): Promise<void> {
|
||||
await this.moveTodo(option.heading);
|
||||
onChooseItem(option: HeadingOption): void {
|
||||
void this.moveTodo(option.heading);
|
||||
}
|
||||
|
||||
private async moveTodo(selectedHeading: HeadingCache | null): Promise<void> {
|
||||
|
||||
@@ -22,7 +22,7 @@ export class NoteSelectModal extends FuzzySuggestModal<TFile> {
|
||||
return file.path;
|
||||
}
|
||||
|
||||
async onChooseItem(file: TFile): Promise<void> {
|
||||
onChooseItem(file: TFile): void {
|
||||
// Get headings from the target file
|
||||
const fileCache = this.app.metadataCache.getFileCache(file);
|
||||
const headings = fileCache?.headings ?? [];
|
||||
@@ -38,7 +38,7 @@ export class NoteSelectModal extends FuzzySuggestModal<TFile> {
|
||||
).open();
|
||||
} else {
|
||||
// No headings - move directly to beginning of file
|
||||
await this.moveTodo(file);
|
||||
void this.moveTodo(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import {App, PluginSettingTab, Setting} from "obsidian";
|
||||
import TodoTrackerPlugin from "./main";
|
||||
|
||||
export interface MyPluginSettings {
|
||||
export interface TodoTrackerSettings {
|
||||
mySetting: string;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: MyPluginSettings = {
|
||||
export const DEFAULT_SETTINGS: TodoTrackerSettings = {
|
||||
mySetting: 'default'
|
||||
}
|
||||
|
||||
export class SampleSettingTab extends PluginSettingTab {
|
||||
export class TodoTrackerSettingTab extends PluginSettingTab {
|
||||
plugin: TodoTrackerPlugin;
|
||||
|
||||
constructor(app: App, plugin: TodoTrackerPlugin) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ItemView, Platform, TFile, WorkspaceLeaf } from 'obsidian';
|
||||
import { App, ItemView, Platform, TFile, WorkspaceLeaf } from 'obsidian';
|
||||
import type { TodoItem, TodoGroup } from '../core/types';
|
||||
import { parseTodosGroupedByHeading } from '../core/todo-parser';
|
||||
import { toggleTodo } from '../core/todo-transformer';
|
||||
@@ -27,7 +27,7 @@ export class TodoSidebarView extends ItemView {
|
||||
}
|
||||
|
||||
getDisplayText(): string {
|
||||
return 'Todo Tracker';
|
||||
return 'Todo tracker';
|
||||
}
|
||||
|
||||
getIcon(): string {
|
||||
@@ -44,14 +44,14 @@ export class TodoSidebarView extends ItemView {
|
||||
|
||||
this.registerEvent(
|
||||
this.app.workspace.on('active-leaf-change', () => {
|
||||
this.refresh();
|
||||
void this.refresh();
|
||||
})
|
||||
);
|
||||
|
||||
this.registerEvent(
|
||||
this.app.vault.on('modify', (file) => {
|
||||
if (this.currentFile && file.path === this.currentFile.path) {
|
||||
this.refresh();
|
||||
void this.refresh();
|
||||
}
|
||||
})
|
||||
);
|
||||
@@ -142,7 +142,7 @@ export class TodoSidebarView extends ItemView {
|
||||
group: TodoGroup
|
||||
): void {
|
||||
const itemEl = createTodoItemEl(container, todo, {
|
||||
onToggle: (t) => this.handleToggle(file, t),
|
||||
onToggle: (t) => { void this.handleToggle(file, t); },
|
||||
onMoveClick: (t) => this.handleMoveClick(t, file),
|
||||
onMoveDailyNoteClick: (t) => this.handleMoveDailyNoteClick(t, file),
|
||||
onClick: (t) => this.openTodoInEditor(file, t),
|
||||
@@ -163,9 +163,9 @@ export class TodoSidebarView extends ItemView {
|
||||
group: TodoGroup
|
||||
): void {
|
||||
// Find the child's <li> element within the parent
|
||||
const childEl = parentEl.querySelector(
|
||||
const childEl = parentEl.querySelector<HTMLElement>(
|
||||
`li[data-line-number="${todo.lineNumber}"]`
|
||||
) as HTMLElement | null;
|
||||
);
|
||||
if (childEl) {
|
||||
this.flatTodoList.push({ todo, element: childEl, group });
|
||||
|
||||
@@ -222,15 +222,19 @@ export class TodoSidebarView extends ItemView {
|
||||
}
|
||||
|
||||
private isToggleCheckboxHotkey(evt: KeyboardEvent): boolean {
|
||||
// Bug 3 fix: properly match Obsidian hotkeys using correct API
|
||||
const hotkeyManager = (this.app as any).hotkeyManager;
|
||||
interface HotkeyDef { modifiers: string[]; key: string; }
|
||||
interface HotkeyManager {
|
||||
getHotkeys(commandId: string): HotkeyDef[];
|
||||
getDefaultHotkeys(commandId: string): HotkeyDef[];
|
||||
}
|
||||
const hotkeyManager = (this.app as App & { hotkeyManager?: HotkeyManager }).hotkeyManager;
|
||||
if (!hotkeyManager) return false;
|
||||
|
||||
const commandId = 'editor:toggle-checklist-status';
|
||||
|
||||
// Get custom hotkeys (user-configured), then fall back to defaults
|
||||
const customHotkeys = hotkeyManager.getHotkeys?.(commandId) ?? [];
|
||||
const defaultHotkeys = hotkeyManager.getDefaultHotkeys?.(commandId) ?? [];
|
||||
const customHotkeys = hotkeyManager.getHotkeys(commandId);
|
||||
const defaultHotkeys = hotkeyManager.getDefaultHotkeys(commandId);
|
||||
const allHotkeys = [...customHotkeys, ...defaultHotkeys];
|
||||
|
||||
if (allHotkeys.length === 0) return false;
|
||||
@@ -256,8 +260,6 @@ export class TodoSidebarView extends ItemView {
|
||||
|
||||
// "Mod" means Cmd on Mac, Ctrl on Windows/Linux
|
||||
const isMac = Platform.isMacOS;
|
||||
const modPressed = isMac ? evt.metaKey : evt.ctrlKey;
|
||||
const modExpected = needsMod;
|
||||
|
||||
// On Mac, Ctrl is separate from Mod (Cmd)
|
||||
// On Windows/Linux, Mod and Ctrl both map to ctrlKey
|
||||
@@ -315,7 +317,7 @@ export class TodoSidebarView extends ItemView {
|
||||
|
||||
private openTodoInEditor(file: TFile, todo: TodoItem): void {
|
||||
const leaf = this.app.workspace.getLeaf(false);
|
||||
leaf.openFile(file).then(() => {
|
||||
void leaf.openFile(file).then(() => {
|
||||
const editor = this.app.workspace.activeEditor?.editor;
|
||||
if (editor) {
|
||||
const line = todo.lineNumber;
|
||||
@@ -328,7 +330,7 @@ export class TodoSidebarView extends ItemView {
|
||||
private toggleFocusedTodo(file: TFile): void {
|
||||
const entry = this.flatTodoList[this.focusedIndex];
|
||||
if (!entry) return;
|
||||
this.handleToggle(file, entry.todo);
|
||||
void this.handleToggle(file, entry.todo);
|
||||
}
|
||||
|
||||
private moveFocusedTodo(file: TFile): void {
|
||||
@@ -346,7 +348,7 @@ export class TodoSidebarView extends ItemView {
|
||||
}
|
||||
|
||||
private handleMoveClick(todo: TodoItem, file: TFile): void {
|
||||
import('../modals/note-select-modal').then(({ NoteSelectModal }) => {
|
||||
void import('../modals/note-select-modal').then(({ NoteSelectModal }) => {
|
||||
new NoteSelectModal(this.app, todo, file).open();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
"src/**/*.ts",
|
||||
"vitest.config.ts"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user