expand the area

This commit is contained in:
sxyazi 2023-11-03 22:09:05 +08:00
parent 774f382e2d
commit ab723c5ba7
No known key found for this signature in database
2 changed files with 11 additions and 4 deletions

View file

@ -12,6 +12,7 @@ pub struct Completion {
}
impl Completion {
// --- Cands
#[inline]
pub fn window(&self) -> &[String] {
let end = (self.offset + self.limit()).min(self.cands.len());
@ -19,8 +20,12 @@ impl Completion {
}
#[inline]
pub fn limit(&self) -> usize { self.cands.len().min(5) }
pub fn limit(&self) -> usize { self.cands.len().min(10) }
#[inline]
pub fn selected(&self) -> &String { &self.cands[self.cursor] }
// --- Cursor
#[inline]
pub fn rel_cursor(&self) -> usize { self.cursor - self.offset }
}

View file

@ -26,7 +26,7 @@ impl<'a> Widget for Completion<'a> {
};
let mut item = ListItem::new(format!(" {} {}", icon, x));
if i == self.cx.completion.cursor {
if i == self.cx.completion.rel_cursor() {
item = item.style(THEME.completion.active.into());
} else {
item = item.style(THEME.completion.inactive.into());
@ -37,8 +37,10 @@ impl<'a> Widget for Completion<'a> {
.collect::<Vec<_>>();
let input_area = self.cx.area(&self.cx.input.position);
let mut area =
self.cx.area(&Position::Sticky(Rect { x: 1, y: 0, width: 20, height: 15 }, input_area));
let mut area = self.cx.area(&Position::Sticky(
Rect { x: 1, y: 0, width: 20, height: items.len() as u16 + 2 },
input_area,
));
if area.y > input_area.y {
area.y = area.y.saturating_sub(1);