aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs3
-rw-r--r--src/view.rs8
2 files changed, 10 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 1792dfb..ac3d8cc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -185,6 +185,7 @@ impl Bk<'_> {
match event::read()? {
Event::Key(e) => view.on_key(self, e.code),
+ Event::Mouse(e) => view.on_mouse(self, e),
Event::Resize(cols, rows) => {
self.rows = rows as usize;
if cols != self.cols {
@@ -194,8 +195,8 @@ impl Bk<'_> {
c.lines = wrap(&c.text, width);
}
}
+ view.on_resize(self);
}
- Event::Mouse(e) => view.on_mouse(self, e),
}
}
diff --git a/src/view.rs b/src/view.rs
index cdb2ceb..d92ad58 100644
--- a/src/view.rs
+++ b/src/view.rs
@@ -14,6 +14,7 @@ pub trait View {
fn render(&self, bk: &Bk) -> Vec<String>;
fn on_key(&self, bk: &mut Bk, kc: KeyCode);
fn on_mouse(&self, _: &mut Bk, _: MouseEvent) {}
+ fn on_resize(&self, _: &mut Bk) {}
}
// TODO render something useful?
@@ -127,6 +128,9 @@ impl Nav {
}
}
impl View for Nav {
+ fn on_resize(&self, bk: &mut Bk) {
+ self.cursor(bk);
+ }
fn on_mouse(&self, bk: &mut Bk, e: MouseEvent) {
match e {
MouseEvent::Down(_, _, row, _) => self.click(bk, row as usize),
@@ -273,6 +277,10 @@ impl View for Page {
_ => (),
}
}
+ fn on_resize(&self, bk: &mut Bk) {
+ // lazy
+ bk.line = min(bk.line, bk.chap().lines.len() - 1);
+ }
fn render(&self, bk: &Bk) -> Vec<String> {
let c = bk.chap();
let line_end = min(bk.line + bk.rows, c.lines.len());