From 800bad0bd801a5a0a47fafdde0b02f0e9e453b5e Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 31 Jul 2020 04:57:29 -0700 Subject: fix click panic --- src/main.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index f427011..0acbc59 100644 --- a/src/main.rs +++ b/src/main.rs @@ -257,11 +257,13 @@ impl View for Page { fn on_mouse(&self, bk: &mut Bk, e: MouseEvent) { match e { MouseEvent::Down(_, col, row, _) => { - if col < bk.pad() { + let c = bk.chap(); + let line = bk.line + row as usize; + + if col < bk.pad() || line >= c.lines.len() { return; } - let c = bk.chap(); - let (start, end) = c.lines[bk.line + row as usize]; + let (start, end) = c.lines[line]; let line_col = (col - bk.pad()) as usize; let mut cols = 0; -- cgit v1.2.3