Added pageup/pagedown functionality.
This commit is contained in:
parent
4d68a36070
commit
eb035b66c7
|
@ -148,4 +148,52 @@ impl Editor {
|
||||||
|
|
||||||
self.move_view_to_cursor();
|
self.move_view_to_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn page_up(&mut self) {
|
||||||
|
if self.view_pos.0 > 0 {
|
||||||
|
let move_amount = self.view_dim.0 - (self.view_dim.0 / 8);
|
||||||
|
if self.view_pos.0 >= move_amount {
|
||||||
|
if self.cursor.0 >= move_amount {
|
||||||
|
self.cursor.0 -= move_amount;
|
||||||
|
}
|
||||||
|
self.view_pos.0 -= move_amount;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if self.cursor.0 >= self.view_pos.0 {
|
||||||
|
self.cursor.0 -= self.view_pos.0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.cursor = (0, 0);
|
||||||
|
}
|
||||||
|
self.view_pos.0 = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.cursor = (0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn page_down(&mut self) {
|
||||||
|
let nlc = self.buffer.newline_count();
|
||||||
|
|
||||||
|
if self.view_pos.0 < nlc {
|
||||||
|
let move_amount = self.view_dim.0 - (self.view_dim.0 / 8);
|
||||||
|
let max_move = nlc - self.view_pos.0;
|
||||||
|
let cursor_max_move = nlc - self.cursor.0;
|
||||||
|
|
||||||
|
if max_move >= move_amount {
|
||||||
|
self.view_pos.0 += move_amount;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.view_pos.0 += max_move;
|
||||||
|
}
|
||||||
|
|
||||||
|
if cursor_max_move >= move_amount {
|
||||||
|
self.cursor.0 += move_amount;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.cursor = self.buffer.pos_1d_to_closest_2d(self.buffer.len()+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,12 @@ const K_ENTER: u16 = 13;
|
||||||
const K_TAB: u16 = 9;
|
const K_TAB: u16 = 9;
|
||||||
const K_SPACE: u16 = 32;
|
const K_SPACE: u16 = 32;
|
||||||
const K_BACKSPACE: u16 = 127;
|
const K_BACKSPACE: u16 = 127;
|
||||||
|
const K_PAGEUP: u16 = 65519;
|
||||||
|
const K_PAGEDOWN: u16 = 65518;
|
||||||
|
const K_UP: u16 = 65517;
|
||||||
const K_DOWN: u16 = 65516;
|
const K_DOWN: u16 = 65516;
|
||||||
const K_LEFT: u16 = 65515;
|
const K_LEFT: u16 = 65515;
|
||||||
const K_RIGHT: u16 = 65514;
|
const K_RIGHT: u16 = 65514;
|
||||||
const K_UP: u16 = 65517;
|
|
||||||
const K_ESC: u16 = 27;
|
const K_ESC: u16 = 27;
|
||||||
const K_CTRL_Q: u16 = 17;
|
const K_CTRL_Q: u16 = 17;
|
||||||
const K_CTRL_S: u16 = 19;
|
const K_CTRL_S: u16 = 19;
|
||||||
|
@ -64,7 +66,7 @@ impl TermUI {
|
||||||
let mut e = self.rb.poll_event(); // Block until we get an event
|
let mut e = self.rb.poll_event(); // Block until we get an event
|
||||||
loop {
|
loop {
|
||||||
match e {
|
match e {
|
||||||
Ok(rustbox::Event::KeyEvent(_, key, character)) => {
|
Ok(rustbox::Event::KeyEvent(modifier, key, character)) => {
|
||||||
//println!(" {} {} {}", modifier, key, character);
|
//println!(" {} {} {}", modifier, key, character);
|
||||||
match key {
|
match key {
|
||||||
K_CTRL_Q | K_ESC => {
|
K_CTRL_Q | K_ESC => {
|
||||||
|
@ -76,6 +78,14 @@ impl TermUI {
|
||||||
self.editor.save_if_dirty();
|
self.editor.save_if_dirty();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
K_PAGEUP => {
|
||||||
|
self.editor.page_up();
|
||||||
|
},
|
||||||
|
|
||||||
|
K_PAGEDOWN => {
|
||||||
|
self.editor.page_down();
|
||||||
|
},
|
||||||
|
|
||||||
K_UP => {
|
K_UP => {
|
||||||
self.editor.cursor_up();
|
self.editor.cursor_up();
|
||||||
},
|
},
|
||||||
|
|
1
todo.md
1
todo.md
|
@ -1,4 +1,3 @@
|
||||||
- Page up / page down
|
|
||||||
- Proper handling of tab characters
|
- Proper handling of tab characters
|
||||||
- Line number display
|
- Line number display
|
||||||
- Editor info display (filename, current line/column, indentation style, etc.)
|
- Editor info display (filename, current line/column, indentation style, etc.)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user