Skip to content

Commit 6e36a49

Browse files
committed
Bugfix: Sync View menu Full/Brief state when switching panes
- Added `sync_view_mode_menu` Tauri command that updates menu checkmarks without emitting events - Called on pane focus change (`handleFocus`, `switchPane`) and on init - Extracted shared `sync_view_mode_menu_impl` to avoid duplication with `set_view_mode`
1 parent af86442 commit 6e36a49

5 files changed

Lines changed: 31 additions & 5 deletions

File tree

apps/desktop/src-tauri/src/commands/ui.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ pub fn toggle_hidden_files<R: Runtime>(app: AppHandle<R>) -> Result<bool, String
6666
/// This is used by the command palette to sync with menu state.
6767
#[tauri::command]
6868
pub fn set_view_mode<R: Runtime>(app: AppHandle<R>, mode: String) -> Result<(), String> {
69+
sync_view_mode_menu_impl::<R>(&app, &mode)?;
70+
71+
// Emit event to frontend
72+
app.emit("view-mode-changed", serde_json::json!({ "mode": mode }))
73+
.map_err(|e| e.to_string())?;
74+
75+
Ok(())
76+
}
77+
78+
/// Sync the View menu checkmarks to match the given mode, without emitting any event.
79+
/// Called when the focused pane changes so the menu reflects the active pane's view mode.
80+
#[tauri::command]
81+
pub fn sync_view_mode_menu<R: Runtime>(app: AppHandle<R>, mode: String) -> Result<(), String> {
82+
sync_view_mode_menu_impl::<R>(&app, &mode)
83+
}
84+
85+
fn sync_view_mode_menu_impl<R: Runtime>(app: &AppHandle<R>, mode: &str) -> Result<(), String> {
6986
let menu_state = app.state::<MenuState<R>>();
7087
let full_guard = menu_state.view_mode_full.lock_ignore_poison();
7188
let brief_guard = menu_state.view_mode_brief.lock_ignore_poison();
@@ -74,15 +91,10 @@ pub fn set_view_mode<R: Runtime>(app: AppHandle<R>, mode: String) -> Result<(),
7491
return Err("Menu not initialized".to_string());
7592
};
7693

77-
// Set the correct check state (radio behavior)
7894
let is_full = mode == "full";
7995
full_item.set_checked(is_full).map_err(|e| e.to_string())?;
8096
brief_item.set_checked(!is_full).map_err(|e| e.to_string())?;
8197

82-
// Emit event to frontend
83-
app.emit("view-mode-changed", serde_json::json!({ "mode": mode }))
84-
.map_err(|e| e.to_string())?;
85-
8698
Ok(())
8799
}
88100

apps/desktop/src-tauri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ pub fn run() {
712712
commands::ui::set_menu_context,
713713
commands::ui::toggle_hidden_files,
714714
commands::ui::set_view_mode,
715+
commands::ui::sync_view_mode_menu,
715716
commands::ui::show_in_finder,
716717
commands::ui::copy_to_clipboard,
717718
commands::ui::quick_look,

apps/desktop/src/lib/file-explorer/pane/DualPaneExplorer.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
cutFilesToClipboard,
3232
readClipboardFiles,
3333
clearClipboardCutState,
34+
syncViewModeMenu,
3435
} from '$lib/tauri-commands'
3536
import type {
3637
VolumeInfo,
@@ -588,6 +589,7 @@
588589
saveAppStatus({ focusedPane: pane })
589590
void updateFocusedPane(pane)
590591
syncPinTabMenu()
592+
void syncViewModeMenu(getPaneViewMode(pane))
591593
}
592594
// Always restore DOM focus (needed after inline rename or dialog close within a pane)
593595
containerElement?.focus()
@@ -1080,6 +1082,7 @@
10801082
10811083
initialized = true
10821084
syncPinTabMenu()
1085+
void syncViewModeMenu(getPaneViewMode(focusedPane))
10831086
10841087
// Sync initial tab state to MCP backend
10851088
syncTabsToBackend()
@@ -1680,6 +1683,7 @@
16801683
focusedPane = newFocus
16811684
saveAppStatus({ focusedPane: newFocus })
16821685
void updateFocusedPane(newFocus)
1686+
void syncViewModeMenu(getPaneViewMode(newFocus))
16831687
containerElement?.focus()
16841688
}
16851689

apps/desktop/src/lib/tauri-commands/app-state.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ export async function setViewMode(mode: 'full' | 'brief'): Promise<void> {
131131
await invoke('set_view_mode', { mode })
132132
}
133133

134+
/**
135+
* Sync the View menu checkmarks to match the given mode, without emitting events.
136+
* Used when the focused pane changes so the menu reflects the active pane's view mode.
137+
*/
138+
export async function syncViewModeMenu(mode: 'full' | 'brief'): Promise<void> {
139+
await invoke('sync_view_mode_menu', { mode })
140+
}
141+
134142
// ============================================================================
135143
// Window lifecycle
136144
// ============================================================================

apps/desktop/src/lib/tauri-commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export {
7777
setMenuContext,
7878
toggleHiddenFiles,
7979
setViewMode,
80+
syncViewModeMenu,
8081
showMainWindow,
8182
updatePinTabMenu,
8283
} from './app-state'

0 commit comments

Comments
 (0)