From 1cbdf704bde529e247d8ebfd8d073865c8e2cbb9 Mon Sep 17 00:00:00 2001 From: Yuri Karamian Date: Fri, 7 Aug 2026 00:56:54 +0200 Subject: [PATCH] Add opt-in title bar note switcher --- src-tauri/src/commands.rs | 2 + src-tauri/src/types.rs | 18 + src/lib/api.ts | 2 + src/lib/components/AppLayout.svelte | 20 +- src/lib/components/NoteSwitcher.svelte | 442 ++++++++++++++++++++++++ src/lib/components/SettingsPanel.svelte | 22 +- src/lib/components/TitleBar.svelte | 24 +- src/lib/types.ts | 1 + src/lib/utils/note-switcher.ts | 83 +++++ 9 files changed, 608 insertions(+), 6 deletions(-) create mode 100644 src/lib/components/NoteSwitcher.svelte create mode 100644 src/lib/utils/note-switcher.ts diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 2500e07..0bf0de6 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -1459,6 +1459,7 @@ pub fn set_general_settings( close_to_tray: bool, enable_wiki_links: bool, show_note_dates: bool, + show_note_switcher: bool, startup_view: StartupView, restore_last_session: bool, show_all_notes: bool, @@ -1470,6 +1471,7 @@ pub fn set_general_settings( let mut config = state.config.lock().map_err(|e| e.to_string())?; config.compact_notes = compact_notes; config.show_note_dates = show_note_dates; + config.show_note_switcher = show_note_switcher; config.startup_view = startup_view; config.restore_last_session = restore_last_session; config.show_all_notes = show_all_notes; diff --git a/src-tauri/src/types.rs b/src-tauri/src/types.rs index 89902f5..b8b278c 100644 --- a/src-tauri/src/types.rs +++ b/src-tauri/src/types.rs @@ -137,6 +137,8 @@ pub struct AppConfig { #[serde(default = "default_true")] pub show_note_dates: bool, #[serde(default)] + pub show_note_switcher: bool, + #[serde(default)] pub time_format: String, #[serde(default = "default_week_start")] pub week_start: String, @@ -300,6 +302,7 @@ impl Default for AppConfig { content_width: None, compact_notes: false, show_note_dates: true, + show_note_switcher: false, time_format: "relative".to_string(), week_start: "monday".to_string(), daily_title_format: "localized".to_string(), @@ -539,4 +542,19 @@ mod startup_view_tests { assert_eq!(config.system_light_theme, "light"); assert_eq!(config.system_dark_theme, "dark"); } + + #[test] + fn note_switcher_is_opt_in_for_new_and_existing_configs() { + let config = AppConfig::default(); + assert!(!config.show_note_switcher); + + let mut value = serde_json::to_value(config).unwrap(); + value + .as_object_mut() + .unwrap() + .remove("show_note_switcher"); + let config: AppConfig = serde_json::from_value(value).unwrap(); + + assert!(!config.show_note_switcher); + } } diff --git a/src/lib/api.ts b/src/lib/api.ts index 5991cba..5144214 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -278,6 +278,7 @@ export async function setGeneralSettings( closeToTray: boolean, enableWikiLinks: boolean, showNoteDates: boolean, + showNoteSwitcher: boolean, startupView: StartupView, restoreLastSession: boolean, showAllNotes: boolean, @@ -305,6 +306,7 @@ export async function setGeneralSettings( closeToTray, enableWikiLinks, showNoteDates, + showNoteSwitcher, startupView, restoreLastSession, showAllNotes, diff --git a/src/lib/components/AppLayout.svelte b/src/lib/components/AppLayout.svelte index 1e444b6..26366ff 100644 --- a/src/lib/components/AppLayout.svelte +++ b/src/lib/components/AppLayout.svelte @@ -296,6 +296,24 @@ if (isMobile) $mobileView = 'editor'; } + async function selectNoteFromSwitcher(path: string): Promise { + const currentPath = $activeNotePath; + if (currentPath && currentPath.replace(/\\/g, '/') === path.replace(/\\/g, '/')) return true; + editor?.flushSave(); + try { + const content = await readNote(path); + $viewerNote = null; + $activeNote = content; + $activeNotePath = path; + $editorDirty = false; + handleNoteSelected(path, content.content); + return true; + } catch (e) { + console.error('Failed to switch note:', e); + return false; + } + } + function handleViewChanged() { taskNoteOpened = false; // Picking a notebook/tag/Tasks/etc. in the sidebar is a request to browse that view's @@ -997,7 +1015,7 @@ {:else} - + {/if}
{#if !$focusMode} diff --git a/src/lib/components/NoteSwitcher.svelte b/src/lib/components/NoteSwitcher.svelte new file mode 100644 index 0000000..87dfb63 --- /dev/null +++ b/src/lib/components/NoteSwitcher.svelte @@ -0,0 +1,442 @@ + + +
+ + + {#if open} + + {/if} +
+ + diff --git a/src/lib/components/SettingsPanel.svelte b/src/lib/components/SettingsPanel.svelte index 1105f59..73806f8 100644 --- a/src/lib/components/SettingsPanel.svelte +++ b/src/lib/components/SettingsPanel.svelte @@ -1,5 +1,5 @@