fix: resize isn't triggered on app restoring (#483)

This commit is contained in:
三咲雅 · Misaki Masa 2024-01-07 22:12:17 +08:00 committed by GitHub
parent 72f924b9e5
commit 1908ff2047
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 26 additions and 19 deletions

View File

@ -23,7 +23,7 @@ impl Tab {
return;
};
if hovered != &opt.lock.url {
if opt.lock.url != *hovered {
return;
}

View File

@ -33,7 +33,7 @@ impl App {
Event::Call(exec, layer) => app.dispatch_call(exec, layer),
Event::Render => render_in_place = true,
Event::Key(key) => app.dispatch_key(key),
Event::Resize(cols, rows) => app.dispatch_resize(cols, rows)?,
Event::Resize => app.resize()?,
Event::Paste(str) => app.dispatch_paste(str),
Event::Quit(no_cwd_file) => {
app.quit(no_cwd_file)?;
@ -65,15 +65,6 @@ impl App {
}
}
fn dispatch_resize(&mut self, _: u16, _: u16) -> Result<()> {
self.cx.manager.active_mut().preview.reset();
self.render()?;
self.cx.manager.current_mut().sync_page(true);
self.cx.manager.peek(false);
Ok(())
}
#[inline]
fn dispatch_call(&mut self, exec: Vec<Exec>, layer: Layer) {
Executor::new(self).dispatch(&exec, layer);

View File

@ -1,4 +1,5 @@
mod plugin;
mod quit;
mod render;
mod resize;
mod stop;

View File

@ -0,0 +1,14 @@
use anyhow::Result;
use crate::app::App;
impl App {
pub(crate) fn resize(&mut self) -> Result<()> {
self.cx.manager.active_mut().preview.reset();
self.render()?;
self.cx.manager.current_mut().sync_page(true);
self.cx.manager.hover(None);
Ok(())
}
}

View File

@ -27,10 +27,10 @@ impl App {
} else {
self.term = Some(Term::start().unwrap());
self.signals.stop_term(false);
// FIXME: find a better way to handle this
self.render().unwrap();
self.cx.manager.hover(None);
self.cx.manager.peek(true);
// While the app resumes, it's possible that the terminal size has changed.
// We need to trigger a resize, and render the UI based on the resized area.
self.resize().unwrap();
}
if let Some(tx) = opt.tx {
tx.send(()).ok();

View File

@ -88,7 +88,7 @@ impl Signals {
// otherwise event will be dispatched twice.
CrosstermEvent::Key(key @ KeyEvent { kind: KeyEventKind::Press, .. }) => Event::Key(key),
CrosstermEvent::Paste(str) => Event::Paste(str),
CrosstermEvent::Resize(cols, rows) => Event::Resize(cols, rows),
CrosstermEvent::Resize(..) => Event::Resize,
_ => continue,
};
if tx.send(event).is_err() {

View File

@ -22,7 +22,8 @@ impl Loader {
return Ok(());
}
let b = fs::read(BOOT.plugin_dir.join(name)).await.map(|v| v.into()).or_else(|_| {
let path = BOOT.plugin_dir.join(format!("{name}.yazi/init.lua"));
let b = fs::read(path).await.map(|v| v.into()).or_else(|_| {
Ok(Cow::from(match name {
"noop.lua" => include_bytes!("../preset/plugins/noop.lua") as &[u8],
"archive.lua" => include_bytes!("../preset/plugins/archive.lua"),

View File

@ -33,7 +33,7 @@ pub fn init() {
fn stage_2(lua: &Lua) {
let setup = br#"
ya.SYNC_ON = true
package.path = BOOT.plugin_dir .. "/?.yazi/init.lua;" .. BOOT.plugin_dir .. "/?.lua;" .. package.path
package.path = BOOT.plugin_dir .. "/?.yazi/init.lua;" .. package.path
"#;
lua.load(setup as &[u8]).exec().unwrap();

View File

@ -11,7 +11,7 @@ pub enum Event {
Call(Vec<Exec>, Layer),
Render,
Key(KeyEvent),
Resize(u16, u16),
Resize,
Paste(String),
Quit(bool), // no-cwd-file
}