mirror of
https://github.com/taskgenius/taskgenius-plugin.git
synced 2026-07-22 06:40:25 +00:00
fix(view): improve view switching to focus existing leaves and sync sidebar
- Check for existing TaskView leaves before creating new ones - Focus the existing view using revealLeaf when available - Update sidebar component to reflect current view mode when switching - Add missing BasesViewRegistration import to type definitions This ensures the task view properly reuses existing instances and keeps the sidebar synchronized with the current view mode.
This commit is contained in:
parent
afadd5fade
commit
3c75f68ce6
2 changed files with 9 additions and 3 deletions
|
|
@ -285,9 +285,11 @@ export class TaskView extends ItemView {
|
|||
return true;
|
||||
}
|
||||
|
||||
const currentView =
|
||||
this.plugin.app.workspace.getActiveViewOfType(TaskView);
|
||||
if (currentView) {
|
||||
const existingLeaves = this.plugin.app.workspace.getLeavesOfType(TASK_VIEW_TYPE);
|
||||
if (existingLeaves.length > 0) {
|
||||
// Focus the existing view
|
||||
this.plugin.app.workspace.revealLeaf(existingLeaves[0]);
|
||||
const currentView = existingLeaves[0].view as TaskView;
|
||||
currentView.switchView(view.id);
|
||||
} else {
|
||||
// If no view is active, activate one and then switch
|
||||
|
|
@ -829,6 +831,9 @@ export class TaskView extends ItemView {
|
|||
private switchView(viewId: ViewMode, project?: string | null) {
|
||||
this.currentViewId = viewId;
|
||||
console.log("Switching view to:", viewId, "Project:", project);
|
||||
|
||||
// Update sidebar to reflect current view
|
||||
this.sidebarComponent.setViewMode(viewId);
|
||||
|
||||
// Hide all components first
|
||||
this.contentComponent.containerEl.hide();
|
||||
|
|
|
|||
1
src/types/obsidian-ex.d.ts
vendored
1
src/types/obsidian-ex.d.ts
vendored
|
|
@ -13,6 +13,7 @@ import {
|
|||
import { Component } from "obsidian";
|
||||
import { HabitProps } from "./habit-card";
|
||||
import { RootFilterState } from "../components/task-filter/ViewTaskFilter";
|
||||
import { BasesViewRegistration } from "./bases";
|
||||
|
||||
interface Token extends EditorRange {
|
||||
/** @todo Documentation incomplete. */
|
||||
|
|
|
|||
Loading…
Reference in a new issue