Skip to content

Commit 6d80b51

Browse files
authored
Update to modalkit{,-ratatui}@0.0.20 (#319)
1 parent 04480ed commit 6d80b51

File tree

4 files changed

+35
-24
lines changed

4 files changed

+35
-24
lines changed

Cargo.lock

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ edit = "0.1.4"
6666
humansize = "2.0.0"
6767

6868
[dependencies.modalkit]
69-
version = "0.0.19"
69+
version = "0.0.20"
7070
#git = "https://github.com/ulyssa/modalkit"
71-
#rev = "cb8c8aeb9a499b9b16615ce144f9014d78036e01"
71+
#rev = "24f3ec11c7f634005a27b26878d0fbbdcc08f272"
7272

7373
[dependencies.modalkit-ratatui]
74-
version = "0.0.19"
74+
version = "0.0.20"
7575
#git = "https://github.com/ulyssa/modalkit"
76-
#rev = "cb8c8aeb9a499b9b16615ce144f9014d78036e01"
76+
#rev = "24f3ec11c7f634005a27b26878d0fbbdcc08f272"
7777

7878
[dependencies.matrix-sdk]
7979
version = "0.7.1"

src/main.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ use modalkit::{
129129

130130
use modalkit_ratatui::{
131131
cmdbar::CommandBarState,
132-
screen::{Screen, ScreenState, TabLayoutDescription},
133-
windows::WindowLayoutDescription,
132+
screen::{Screen, ScreenState, TabbedLayoutDescription},
133+
windows::{WindowLayoutDescription, WindowLayoutState},
134134
TerminalCursor,
135135
TerminalExtOps,
136136
Window,
@@ -176,6 +176,17 @@ fn config_tab_to_desc(
176176
Ok(desc)
177177
}
178178

179+
fn restore_layout(
180+
area: Rect,
181+
settings: &ApplicationSettings,
182+
store: &mut ProgramStore,
183+
) -> IambResult<FocusList<WindowLayoutState<IambWindow, IambInfo>>> {
184+
let layout = std::fs::read(&settings.layout_json)?;
185+
let tabs: TabbedLayoutDescription<IambInfo> =
186+
serde_json::from_slice(&layout).map_err(IambError::from)?;
187+
tabs.to_layout(area.into(), store)
188+
}
189+
179190
fn setup_screen(
180191
settings: ApplicationSettings,
181192
store: &mut ProgramStore,
@@ -186,12 +197,14 @@ fn setup_screen(
186197

187198
match settings.layout {
188199
config::Layout::Restore => {
189-
if let Ok(layout) = std::fs::read(&settings.layout_json) {
190-
let tabs: TabLayoutDescription<IambInfo> =
191-
serde_json::from_slice(&layout).map_err(IambError::from)?;
192-
let tabs = tabs.to_layout(area.into(), store)?;
193-
194-
return Ok(ScreenState::from_list(tabs, cmd));
200+
match restore_layout(area, &settings, store) {
201+
Ok(tabs) => {
202+
return Ok(ScreenState::from_list(tabs, cmd));
203+
},
204+
Err(e) => {
205+
// Log the issue with restoring and then continue.
206+
tracing::warn!(err = %e, "Failed to restore layout from disk");
207+
},
195208
}
196209
},
197210
config::Layout::New => {},
@@ -242,7 +255,7 @@ struct Application {
242255
focused: bool,
243256

244257
/// The tab layout before the last executed [TabAction].
245-
last_layout: Option<TabLayoutDescription<IambInfo>>,
258+
last_layout: Option<TabbedLayoutDescription<IambInfo>>,
246259

247260
/// Whether we need to do a full redraw (e.g., after running a subprocess).
248261
dirty: bool,
@@ -479,7 +492,7 @@ impl Application {
479492
None
480493
},
481494
Action::Command(act) => {
482-
let acts = store.application.cmds.command(&act, &ctx)?;
495+
let acts = store.application.cmds.command(&act, &ctx, &mut store.registers)?;
483496
self.action_prepend(acts);
484497

485498
None

src/windows/room/scrollback.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
673673
let dir = ctx.get_search_regex_dir();
674674
let dir = flip.resolve(&dir);
675675

676-
let lsearch = store.registers.get(&Register::LastSearch)?;
677-
let lsearch = lsearch.value.to_string();
676+
let lsearch = store.registers.get_last_search().to_string();
678677
let needle = Regex::new(lsearch.as_ref())?;
679678

680679
let (mc, needs_load) = self.find_message(key, dir, &needle, count, info);
@@ -753,8 +752,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
753752
let dir = ctx.get_search_regex_dir();
754753
let dir = flip.resolve(&dir);
755754

756-
let lsearch = store.registers.get(&Register::LastSearch)?;
757-
let lsearch = lsearch.value.to_string();
755+
let lsearch = store.registers.get_last_search().to_string();
758756
let needle = Regex::new(lsearch.as_ref())?;
759757

760758
let (mc, needs_load) = self.find_message(key, dir, &needle, count, info);
@@ -1452,7 +1450,7 @@ mod tests {
14521450
// MSG4: "help"
14531451
// MSG5: "character"
14541452
// MSG1: "writhe"
1455-
store.set_last_search("he");
1453+
store.registers.set_last_search("he");
14561454

14571455
assert_eq!(scrollback.cursor, MessageCursor::latest());
14581456

0 commit comments

Comments
 (0)