fix: selection rect out of bounds (#59)

This commit is contained in:
三咲雅 · Misaki Masa 2023-08-15 07:33:25 +08:00 committed by GitHub
parent 05433c38d0
commit edd0ad7997
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,7 +16,7 @@ impl<'a> Input<'a> {
}
impl<'a> Widget for Input<'a> {
fn render(self, _: Rect, buf: &mut Buffer) {
fn render(self, win: Rect, buf: &mut Buffer) {
let input = &self.cx.input;
let area = self.cx.area(&input.position);
@ -43,8 +43,11 @@ impl<'a> Widget for Input<'a> {
.render(area, buf);
if let Some(Range { start, end }) = input.selected() {
let x = win.width.min(area.x + 1 + start);
let y = win.height.min(area.y + 1);
buf.set_style(
Rect { x: area.x + 1 + start, y: area.y + 1, width: end - start, height: 1 },
Rect { x, y, width: (end - start).min(win.width - x), height: 1.min(win.height - y) },
Style::new().bg(Color::Rgb(72, 77, 102)),
)
}