Skip to content

Commit 8e2f953

Browse files
committed
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.
1 parent 5c4f402 commit 8e2f953

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/pages/TaskView.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,11 @@ export class TaskView extends ItemView {
285285
return true;
286286
}
287287

288-
const currentView =
289-
this.plugin.app.workspace.getActiveViewOfType(TaskView);
290-
if (currentView) {
288+
const existingLeaves = this.plugin.app.workspace.getLeavesOfType(TASK_VIEW_TYPE);
289+
if (existingLeaves.length > 0) {
290+
// Focus the existing view
291+
this.plugin.app.workspace.revealLeaf(existingLeaves[0]);
292+
const currentView = existingLeaves[0].view as TaskView;
291293
currentView.switchView(view.id);
292294
} else {
293295
// If no view is active, activate one and then switch
@@ -829,6 +831,9 @@ export class TaskView extends ItemView {
829831
private switchView(viewId: ViewMode, project?: string | null) {
830832
this.currentViewId = viewId;
831833
console.log("Switching view to:", viewId, "Project:", project);
834+
835+
// Update sidebar to reflect current view
836+
this.sidebarComponent.setViewMode(viewId);
832837

833838
// Hide all components first
834839
this.contentComponent.containerEl.hide();

src/types/obsidian-ex.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { Component } from "obsidian";
1414
import { HabitProps } from "./habit-card";
1515
import { RootFilterState } from "../components/task-filter/ViewTaskFilter";
16+
import { BasesViewRegistration } from "./bases";
1617

1718
interface Token extends EditorRange {
1819
/** @todo Documentation incomplete. */

0 commit comments

Comments
 (0)