aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Campos <james.r.campos@gmail.com>2020-07-31 04:57:29 -0700
committerJames Campos <james.r.campos@gmail.com>2020-07-31 04:57:29 -0700
commit800bad0bd801a5a0a47fafdde0b02f0e9e453b5e (patch)
tree972ce3f96409aaf4820fceabbb7c777af279a9fe
parent39f0f4cd8ace36b1dfe4ab3c1eb84b4575907c15 (diff)
downloadbk-800bad0bd801a5a0a47fafdde0b02f0e9e453b5e.tar.gz
fix click panic
-rw-r--r--src/main.rs8
1 files changed, 5 insertions, 3 deletions
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;