Skip to content

Commit 9536159

Browse files
author
Noam Lewis
committed
WIP
1 parent 9a3a9df commit 9536159

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/main.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ impl State {
8585
) -> Result<(), io::Error> {
8686
self.status_text = format!("Line {}, Column {}", self.cursor.y, self.cursor.x);
8787

88-
self.scroll_to_cursor(terminal.get_frame().area());
89-
88+
self.scroll_to_cursor();
9089
terminal.draw(|x| self.draw_frame(x))?;
9190
Ok(())
9291
}
@@ -99,13 +98,13 @@ impl State {
9998
return Position::new(a.x.max(b.x), a.y.max(b.y));
10099
}
101100

102-
fn text_area(&self, window_area: Rect) -> Rect {
103-
Rect::new(0, 0, window_area.width, window_area.height - 1)
101+
fn text_area(&self) -> Size {
102+
Size::new(self.terminal_size.width, self.terminal_size.height - 1)
104103
}
105104

106-
fn scroll_to_cursor(&mut self, window_area: Rect) {
105+
fn scroll_to_cursor(&mut self) {
107106
// bring cursor into view
108-
let text_area = self.text_area(window_area);
107+
let text_area = self.text_area();
109108
let left_margin_width = self.left_margin_width();
110109

111110
let max_pos = Position::new(
@@ -337,7 +336,7 @@ impl State {
337336

338337
fn draw_frame(&mut self, frame: &mut Frame) {
339338
let window_area = frame.area();
340-
let text_area = self.text_area(window_area);
339+
let text_area = self.text_area();
341340
let status_area = Rect::new(0, window_area.height - 1, window_area.width, 1);
342341
let left_margin_width = self.left_margin_width();
343342
let cursor = self.cursor;
@@ -378,7 +377,7 @@ impl State {
378377
.enumerate()
379378
.map(render_line),
380379
),
381-
text_area,
380+
Rect::new(0, 0, text_area.width, text_area.height),
382381
);
383382

384383
self.status_text = format!(
@@ -499,17 +498,24 @@ impl State {
499498
}
500499

501500
fn move_to_file_start(&mut self) {
502-
let offset = SeekFrom::Start(0);
503-
self.lines.seek(offset);
501+
self.lines.seek(SeekFrom::Start(0));
504502
self.line_index = self.lines.get_index();
505503
self.cursor.y = 0;
506504
}
507505

508506
fn move_to_file_end(&mut self) {
509-
let offset = SeekFrom::End(0);
510-
self.lines.seek(offset);
507+
self.lines.seek(SeekFrom::End(0));
511508
self.line_index = self.lines.get_index();
512509
self.cursor.y = 0;
510+
511+
// populate lines to fill the window
512+
for _ in 0..self.text_area().height {
513+
self.iter_line_prev();
514+
}
515+
// go to the last line
516+
for _ in 1..self.text_area().height {
517+
self.iter_line_next();
518+
}
513519
}
514520

515521
fn left_margin_width(&self) -> u16 {
@@ -526,7 +532,7 @@ impl State {
526532
fn line_label(loaded_line: &LoadedLine) -> String {
527533
loaded_line
528534
.loaded_loc()
529-
.map(|l| format!("{}", l.loaded_offset))
535+
.map(|l| format!("{:x}", l.loaded_offset))
530536
.unwrap_or("?".to_owned())
531537
}
532538
}

0 commit comments

Comments
 (0)