mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Fix Select height
This commit is contained in:
parent
420a6ddf18
commit
16473af4e6
8 changed files with 34 additions and 20 deletions
|
|
@ -127,7 +127,7 @@ quit_offset = [ 0, 2, 50, 3 ]
|
|||
[select]
|
||||
open_title = "Open with:"
|
||||
open_origin = "hovered"
|
||||
open_offset = [ 0, 1, 50, 3 ]
|
||||
open_offset = [ 0, 1, 50, 7 ]
|
||||
|
||||
[log]
|
||||
enabled = false
|
||||
|
|
|
|||
|
|
@ -66,3 +66,8 @@ impl Default for Input {
|
|||
toml::from_str::<Outer>(&MERGED_YAZI).unwrap().input
|
||||
}
|
||||
}
|
||||
|
||||
impl Input {
|
||||
#[inline]
|
||||
pub const fn border(&self) -> u16 { 2 }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,10 +15,13 @@ impl TryFrom<Vec<i16>> for Offset {
|
|||
|
||||
fn try_from(values: Vec<i16>) -> Result<Self, Self::Error> {
|
||||
if values.len() != 4 {
|
||||
bail!("invalid offset: {:?}", values);
|
||||
bail!("offset must have 4 values: {:?}", values);
|
||||
}
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use super::Position;
|
||||
use super::{Offset, Position};
|
||||
use crate::{INPUT, SELECT};
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -124,17 +124,20 @@ impl InputOpt {
|
|||
|
||||
impl SelectOpt {
|
||||
#[inline]
|
||||
pub fn open() -> Self {
|
||||
Self {
|
||||
title: SELECT.open_title.to_owned(),
|
||||
position: Position::new(SELECT.open_origin, SELECT.open_offset),
|
||||
..Default::default()
|
||||
}
|
||||
fn max_height(len: usize) -> u16 {
|
||||
SELECT.open_offset.height.min(SELECT.border().saturating_add(len as u16))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn with_items(mut self, items: Vec<String>) -> Self {
|
||||
self.items = items;
|
||||
self
|
||||
pub fn open(items: Vec<String>) -> Self {
|
||||
let max_height = Self::max_height(items.len());
|
||||
Self {
|
||||
title: SELECT.open_title.to_owned(),
|
||||
items,
|
||||
position: Position::new(SELECT.open_origin, Offset {
|
||||
height: max_height,
|
||||
..SELECT.open_offset
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,3 +21,8 @@ impl Default for Select {
|
|||
toml::from_str::<Outer>(&MERGED_YAZI).unwrap().select
|
||||
}
|
||||
}
|
||||
|
||||
impl Select {
|
||||
#[inline]
|
||||
pub const fn border(&self) -> u16 { 2 }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,7 @@ impl Manager {
|
|||
return;
|
||||
}
|
||||
|
||||
let result =
|
||||
emit!(Select(SelectOpt::open().with_items(openers.iter().map(|o| o.desc.clone()).collect())));
|
||||
|
||||
let result = emit!(Select(SelectOpt::open(openers.iter().map(|o| o.desc.clone()).collect())));
|
||||
if let Ok(choice) = result.await {
|
||||
emit!(Open(files, Some(openers[choice].clone())));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,5 +2,3 @@ mod commands;
|
|||
mod select;
|
||||
|
||||
pub use select::*;
|
||||
|
||||
pub const SELECT_PADDING: u16 = 2;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use anyhow::Result;
|
||||
use tokio::sync::oneshot::Sender;
|
||||
use yazi_config::popup::{Position, SelectOpt};
|
||||
use yazi_config::{popup::{Position, SelectOpt}, SELECT};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Select {
|
||||
|
|
@ -34,7 +34,9 @@ impl Select {
|
|||
}
|
||||
|
||||
#[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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue