diff --git a/Cargo.lock b/Cargo.lock index 6d50162..7aa16fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2470,7 +2470,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.5", ] [[package]] @@ -2964,9 +2964,9 @@ dependencies = [ [[package]] name = "modalkit" -version = "0.0.19" +version = "0.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6820ebd6a3dbb8006e67a0300cf247e09764758b6ae0ea865ed716fe0265392b" +checksum = "24f070af2372cc39349d6415c9a2ae050e1e9dc71dddc9a7a036babe7ad2b192" dependencies = [ "anymap2", "arboard", @@ -2986,9 +2986,9 @@ dependencies = [ [[package]] name = "modalkit-ratatui" -version = "0.0.19" +version = "0.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac33423f5f8d3d1ac82b322734e129750b0b710b076b16a018917d8c2b1c8a80" +checksum = "df272b6822a22154034a9761ea10235746fefec7623dc1a6ed0cfbaad6f5d070" dependencies = [ "crossterm", "intervaltree", diff --git a/Cargo.toml b/Cargo.toml index 97059e9..cfe1b6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,14 +66,14 @@ edit = "0.1.4" humansize = "2.0.0" [dependencies.modalkit] -version = "0.0.19" +version = "0.0.20" #git = "https://github.com/ulyssa/modalkit" -#rev = "cb8c8aeb9a499b9b16615ce144f9014d78036e01" +#rev = "24f3ec11c7f634005a27b26878d0fbbdcc08f272" [dependencies.modalkit-ratatui] -version = "0.0.19" +version = "0.0.20" #git = "https://github.com/ulyssa/modalkit" -#rev = "cb8c8aeb9a499b9b16615ce144f9014d78036e01" +#rev = "24f3ec11c7f634005a27b26878d0fbbdcc08f272" [dependencies.matrix-sdk] version = "0.7.1" diff --git a/src/main.rs b/src/main.rs index 4105236..073149f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -129,8 +129,8 @@ use modalkit::{ use modalkit_ratatui::{ cmdbar::CommandBarState, - screen::{Screen, ScreenState, TabLayoutDescription}, - windows::WindowLayoutDescription, + screen::{Screen, ScreenState, TabbedLayoutDescription}, + windows::{WindowLayoutDescription, WindowLayoutState}, TerminalCursor, TerminalExtOps, Window, @@ -176,6 +176,17 @@ fn config_tab_to_desc( Ok(desc) } +fn restore_layout( + area: Rect, + settings: &ApplicationSettings, + store: &mut ProgramStore, +) -> IambResult>> { + let layout = std::fs::read(&settings.layout_json)?; + let tabs: TabbedLayoutDescription = + serde_json::from_slice(&layout).map_err(IambError::from)?; + tabs.to_layout(area.into(), store) +} + fn setup_screen( settings: ApplicationSettings, store: &mut ProgramStore, @@ -186,12 +197,14 @@ fn setup_screen( match settings.layout { config::Layout::Restore => { - if let Ok(layout) = std::fs::read(&settings.layout_json) { - let tabs: TabLayoutDescription = - serde_json::from_slice(&layout).map_err(IambError::from)?; - let tabs = tabs.to_layout(area.into(), store)?; - - return Ok(ScreenState::from_list(tabs, cmd)); + match restore_layout(area, &settings, store) { + Ok(tabs) => { + return Ok(ScreenState::from_list(tabs, cmd)); + }, + Err(e) => { + // Log the issue with restoring and then continue. + tracing::warn!(err = %e, "Failed to restore layout from disk"); + }, } }, config::Layout::New => {}, @@ -242,7 +255,7 @@ struct Application { focused: bool, /// The tab layout before the last executed [TabAction]. - last_layout: Option>, + last_layout: Option>, /// Whether we need to do a full redraw (e.g., after running a subprocess). dirty: bool, @@ -479,7 +492,7 @@ impl Application { None }, Action::Command(act) => { - let acts = store.application.cmds.command(&act, &ctx)?; + let acts = store.application.cmds.command(&act, &ctx, &mut store.registers)?; self.action_prepend(acts); None diff --git a/src/windows/room/scrollback.rs b/src/windows/room/scrollback.rs index 7aa47ff..716deac 100644 --- a/src/windows/room/scrollback.rs +++ b/src/windows/room/scrollback.rs @@ -673,8 +673,7 @@ impl EditorActions for ScrollbackState { let dir = ctx.get_search_regex_dir(); let dir = flip.resolve(&dir); - let lsearch = store.registers.get(&Register::LastSearch)?; - let lsearch = lsearch.value.to_string(); + let lsearch = store.registers.get_last_search().to_string(); let needle = Regex::new(lsearch.as_ref())?; let (mc, needs_load) = self.find_message(key, dir, &needle, count, info); @@ -753,8 +752,7 @@ impl EditorActions for ScrollbackState { let dir = ctx.get_search_regex_dir(); let dir = flip.resolve(&dir); - let lsearch = store.registers.get(&Register::LastSearch)?; - let lsearch = lsearch.value.to_string(); + let lsearch = store.registers.get_last_search().to_string(); let needle = Regex::new(lsearch.as_ref())?; let (mc, needs_load) = self.find_message(key, dir, &needle, count, info);