Fixed remaining cursor navigation bugs (I think...?).
This commit is contained in:
parent
bde11e6c7b
commit
f222cd6a54
|
@ -54,6 +54,11 @@ impl<T: LineFormatter> Buffer<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn dimensions(&self) -> (usize, usize) {
|
||||||
|
self.text.vis_dim
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
// Editing operations
|
// Editing operations
|
||||||
|
|
|
@ -4,7 +4,7 @@ use buffer::Buffer;
|
||||||
use buffer::line_formatter::LineFormatter;
|
use buffer::line_formatter::LineFormatter;
|
||||||
use buffer::line_formatter::RoundingBehavior::*;
|
use buffer::line_formatter::RoundingBehavior::*;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::cmp::min;
|
use std::cmp::{min, max};
|
||||||
use files::{load_file_to_buffer, save_buffer_to_file};
|
use files::{load_file_to_buffer, save_buffer_to_file};
|
||||||
use string_utils::grapheme_count;
|
use string_utils::grapheme_count;
|
||||||
use self::cursor::CursorSet;
|
use self::cursor::CursorSet;
|
||||||
|
@ -471,10 +471,11 @@ impl<T: LineFormatter> Editor<T> {
|
||||||
|
|
||||||
pub fn cursor_up(&mut self, n: usize) {
|
pub fn cursor_up(&mut self, n: usize) {
|
||||||
for c in self.cursors.iter_mut() {
|
for c in self.cursors.iter_mut() {
|
||||||
|
let vmove = n * self.buffer.formatter.single_line_height();
|
||||||
let (v, _) = self.buffer.index_to_v2d(c.range.0);
|
let (v, _) = self.buffer.index_to_v2d(c.range.0);
|
||||||
|
|
||||||
if v >= n {
|
if vmove <= v {
|
||||||
c.range.0 = self.buffer.v2d_to_index((v - n, c.vis_start), (Floor, Floor));
|
c.range.0 = self.buffer.v2d_to_index((v - vmove, c.vis_start), (Floor, Floor));
|
||||||
c.range.1 = c.range.0;
|
c.range.1 = c.range.0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -489,10 +490,12 @@ impl<T: LineFormatter> Editor<T> {
|
||||||
|
|
||||||
pub fn cursor_down(&mut self, n: usize) {
|
pub fn cursor_down(&mut self, n: usize) {
|
||||||
for c in self.cursors.iter_mut() {
|
for c in self.cursors.iter_mut() {
|
||||||
|
let vmove = n * self.buffer.formatter.single_line_height();
|
||||||
let (v, _) = self.buffer.index_to_v2d(c.range.0);
|
let (v, _) = self.buffer.index_to_v2d(c.range.0);
|
||||||
|
let (h, _) = self.buffer.dimensions();
|
||||||
|
|
||||||
if v < (self.buffer.line_count() - n) {
|
if vmove < (h - v) {
|
||||||
c.range.0 = self.buffer.v2d_to_index((v + n, c.vis_start), (Floor, Floor));
|
c.range.0 = self.buffer.v2d_to_index((v + vmove, c.vis_start), (Floor, Floor));
|
||||||
c.range.1 = c.range.0;
|
c.range.1 = c.range.0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -507,20 +510,18 @@ impl<T: LineFormatter> Editor<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn page_up(&mut self) {
|
pub fn page_up(&mut self) {
|
||||||
|
let move_amount = self.view_dim.0 - max((self.view_dim.0 / 8), self.buffer.formatter.single_line_height());
|
||||||
|
|
||||||
if self.view_pos.0 > 0 {
|
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.view_pos.0 >= move_amount {
|
||||||
self.view_pos.0 -= move_amount;
|
self.view_pos.0 -= move_amount;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.view_pos.0 = 0;
|
self.view_pos.0 = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.cursor_up(move_amount);
|
self.cursor_up(move_amount);
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.cursor_to_beginning_of_buffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adjust view
|
// Adjust view
|
||||||
self.move_view_to_cursor();
|
self.move_view_to_cursor();
|
||||||
|
@ -528,9 +529,9 @@ impl<T: LineFormatter> Editor<T> {
|
||||||
|
|
||||||
pub fn page_down(&mut self) {
|
pub fn page_down(&mut self) {
|
||||||
let nlc = self.buffer.line_count() - 1;
|
let nlc = self.buffer.line_count() - 1;
|
||||||
|
let move_amount = self.view_dim.0 - max((self.view_dim.0 / 8), self.buffer.formatter.single_line_height());
|
||||||
|
|
||||||
if self.view_pos.0 < nlc {
|
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 max_move = nlc - self.view_pos.0;
|
||||||
|
|
||||||
if max_move >= move_amount {
|
if max_move >= move_amount {
|
||||||
|
@ -540,11 +541,9 @@ impl<T: LineFormatter> Editor<T> {
|
||||||
self.view_pos.0 += max_move;
|
self.view_pos.0 += max_move;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
self.cursor_down(move_amount);
|
self.cursor_down(move_amount);
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.cursor_to_end_of_buffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adjust view
|
// Adjust view
|
||||||
self.move_view_to_cursor();
|
self.move_view_to_cursor();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user