diff --git a/yazi-core/src/context.rs b/yazi-core/src/context.rs index 50b6f9b6..78c8ab66 100644 --- a/yazi-core/src/context.rs +++ b/yazi-core/src/context.rs @@ -2,7 +2,7 @@ use crossterm::terminal::WindowSize; use ratatui::prelude::Rect; use yazi_shared::Term; -use crate::{completion::Completion, help::Help, input::Input, manager::Manager, select::Select, tasks::Tasks, which::Which, Position, Offset}; +use crate::{completion::Completion, help::Help, input::Input, manager::Manager, select::Select, tasks::Tasks, which::Which, Offset, Position}; pub struct Ctx { pub manager: Manager, @@ -125,18 +125,21 @@ impl Ctx { }); } Position::Sticky(Offset { x_offset, y_offset, width, height }, r) => { - // TODO: - unimplemented!("Position::Sticky is not implemented"); - // let mut x = columns.saturating_sub(width); - // x = x.saturating_add_signed(x_offset); - // let mut y = r.y; - // y = y.saturating_add_signed(y_offset); - - // if y + height + r.height > rows { - // (x + r.x, r.y.saturating_sub(height.saturating_sub(y))) - // } else { - // (x + r.x, y + r.height) - // } + let base_x = r.x; + let base_y = r.y; + if base_y.saturating_add(height).saturating_add(r.height).saturating_add_signed(y_offset) + > rows + { + ( + base_x.saturating_add_signed(x_offset).max(0).min(columns.saturating_sub(width)), + base_y.saturating_sub(height.saturating_sub(y_offset.unsigned_abs())), + ) + } else { + ( + base_x.saturating_add_signed(x_offset), + base_y.saturating_add(r.height).saturating_add_signed(y_offset), + ) + } } }; diff --git a/yazi-fm/src/completion/completion.rs b/yazi-fm/src/completion/completion.rs index b9f32254..9b4459a0 100644 --- a/yazi-fm/src/completion/completion.rs +++ b/yazi-fm/src/completion/completion.rs @@ -2,7 +2,7 @@ use std::path::MAIN_SEPARATOR; use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, Borders, Clear, List, ListItem, Widget}}; use yazi_config::THEME; -use yazi_core::{Ctx, Position, Offset}; +use yazi_core::{Ctx, Offset, Position}; pub(crate) struct Completion<'a> { cx: &'a Ctx, @@ -40,7 +40,6 @@ impl<'a> Widget for Completion<'a> { let input_area = self.cx.area(&self.cx.input.position); let mut area = self.cx.area(&Position::Sticky( - // TODO: Offset { x_offset: 1, y_offset: 0,