Fix Select height

This commit is contained in:
sxyazi 2023-11-17 09:03:30 +08:00
parent 420a6ddf18
commit 16473af4e6
No known key found for this signature in database
8 changed files with 34 additions and 20 deletions

View file

@ -127,7 +127,7 @@ quit_offset = [ 0, 2, 50, 3 ]
[select] [select]
open_title = "Open with:" open_title = "Open with:"
open_origin = "hovered" open_origin = "hovered"
open_offset = [ 0, 1, 50, 3 ] open_offset = [ 0, 1, 50, 7 ]
[log] [log]
enabled = false enabled = false

View file

@ -66,3 +66,8 @@ impl Default for Input {
toml::from_str::<Outer>(&MERGED_YAZI).unwrap().input toml::from_str::<Outer>(&MERGED_YAZI).unwrap().input
} }
} }
impl Input {
#[inline]
pub const fn border(&self) -> u16 { 2 }
}

View file

@ -15,10 +15,13 @@ impl TryFrom<Vec<i16>> for Offset {
fn try_from(values: Vec<i16>) -> Result<Self, Self::Error> { fn try_from(values: Vec<i16>) -> Result<Self, Self::Error> {
if values.len() != 4 { if values.len() != 4 {
bail!("invalid offset: {:?}", values); bail!("offset must have 4 values: {:?}", values);
} }
if values[2] < 0 || values[3] < 0 { if values[2] < 0 || values[3] < 0 {
bail!("invalid offset: {:?}", values); bail!("offset width and height must be positive: {:?}", values);
}
if values[3] < 3 {
bail!("offset height must be at least 3: {:?}", values);
} }
Ok(Self { Ok(Self {

View file

@ -1,4 +1,4 @@
use super::Position; use super::{Offset, Position};
use crate::{INPUT, SELECT}; use crate::{INPUT, SELECT};
#[derive(Default)] #[derive(Default)]
@ -124,17 +124,20 @@ impl InputOpt {
impl SelectOpt { impl SelectOpt {
#[inline] #[inline]
pub fn open() -> Self { fn max_height(len: usize) -> u16 {
Self { SELECT.open_offset.height.min(SELECT.border().saturating_add(len as u16))
title: SELECT.open_title.to_owned(),
position: Position::new(SELECT.open_origin, SELECT.open_offset),
..Default::default()
}
} }
#[inline] #[inline]
pub fn with_items(mut self, items: Vec<String>) -> Self { pub fn open(items: Vec<String>) -> Self {
self.items = items; let max_height = Self::max_height(items.len());
self Self {
title: SELECT.open_title.to_owned(),
items,
position: Position::new(SELECT.open_origin, Offset {
height: max_height,
..SELECT.open_offset
}),
}
} }
} }

View file

@ -21,3 +21,8 @@ impl Default for Select {
toml::from_str::<Outer>(&MERGED_YAZI).unwrap().select toml::from_str::<Outer>(&MERGED_YAZI).unwrap().select
} }
} }
impl Select {
#[inline]
pub const fn border(&self) -> u16 { 2 }
}

View file

@ -20,9 +20,7 @@ impl Manager {
return; return;
} }
let result = let result = emit!(Select(SelectOpt::open(openers.iter().map(|o| o.desc.clone()).collect())));
emit!(Select(SelectOpt::open().with_items(openers.iter().map(|o| o.desc.clone()).collect())));
if let Ok(choice) = result.await { if let Ok(choice) = result.await {
emit!(Open(files, Some(openers[choice].clone()))); emit!(Open(files, Some(openers[choice].clone())));
} }

View file

@ -2,5 +2,3 @@ mod commands;
mod select; mod select;
pub use select::*; pub use select::*;
pub const SELECT_PADDING: u16 = 2;

View file

@ -1,6 +1,6 @@
use anyhow::Result; use anyhow::Result;
use tokio::sync::oneshot::Sender; use tokio::sync::oneshot::Sender;
use yazi_config::popup::{Position, SelectOpt}; use yazi_config::{popup::{Position, SelectOpt}, SELECT};
#[derive(Default)] #[derive(Default)]
pub struct Select { pub struct Select {
@ -34,7 +34,9 @@ impl Select {
} }
#[inline] #[inline]
pub fn limit(&self) -> usize { self.items.len().min(5) } pub(super) fn limit(&self) -> usize {
self.position.offset.height.saturating_sub(SELECT.border()) as usize
}
} }
impl Select { impl Select {