From edd0ad7997697736476d3402372c28ed73fd28dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Tue, 15 Aug 2023 07:33:25 +0800 Subject: [PATCH] fix: selection rect out of bounds (#59) --- app/src/input/input.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/input/input.rs b/app/src/input/input.rs index aab7fc88..f58fb0d0 100644 --- a/app/src/input/input.rs +++ b/app/src/input/input.rs @@ -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)), ) }