This commit is contained in:
daa84 2017-11-13 12:51:22 +03:00
parent 9f17a8bb09
commit de55aecff0
4 changed files with 25 additions and 14 deletions

View File

@ -63,4 +63,3 @@ impl Cell {
self.dirty = true;
}
}

View File

@ -70,9 +70,12 @@ impl Line {
fn set_cell_to_item(&mut self, new_item: &PangoItemPosition) -> bool {
let start_item_idx = self.cell_to_item(new_item.start_cell);
let start_item_cells_count = if start_item_idx >= 0 {
self.item_line[start_item_idx as usize]
.as_ref()
.map_or(-1, |item| item.cells_count as i32)
self.item_line[start_item_idx as usize].as_ref().map_or(
-1,
|item| {
item.cells_count as i32
},
)
} else {
-1
};
@ -83,8 +86,8 @@ impl Line {
// in case different item length was in previous iteration
// mark all item as dirty
if start_item_idx != new_item.start_cell as i32 ||
new_item.cells_count() != start_item_cells_count || start_item_idx == -1 ||
end_item_idx == -1
new_item.cells_count() != start_item_cells_count ||
start_item_idx == -1 || end_item_idx == -1
{
self.initialize_cell_item(new_item.start_cell, new_item.end_cell, new_item.item);
true
@ -173,7 +176,12 @@ impl Line {
}
pub fn item_len_from_idx(&self, start_idx: usize) -> usize {
debug_assert!(start_idx < self.line.len());
debug_assert!(
start_idx < self.line.len(),
"idx={}, len={}",
start_idx,
self.line.len()
);
let item_idx = self.cell_to_item(start_idx);

View File

@ -70,6 +70,12 @@ impl UiModel {
}
pub fn set_cursor(&mut self, row: usize, col: usize) -> ModelRectVec {
// it is possible in some cases that cursor moved out of visible rect
// see https://github.com/daa84/neovim-gtk/issues/20
if row >= self.model.len() || col >= self.model[row].line.len() {
return ModelRectVec::empty();
}
let mut changed_region = ModelRectVec::new(self.cur_point());
self.cur_row = row;

View File

@ -9,6 +9,10 @@ pub struct ModelRectVec {
}
impl ModelRectVec {
pub fn empty() -> ModelRectVec {
ModelRectVec { list: vec![] }
}
pub fn new(first: ModelRect) -> ModelRectVec {
ModelRectVec { list: vec![first] }
}
@ -257,13 +261,7 @@ impl ModelRect {
)
}
pub fn from_area(
cell_metrics: &CellMetrics,
x1: f64,
y1: f64,
x2: f64,
y2: f64,
) -> ModelRect {
pub fn from_area(cell_metrics: &CellMetrics, x1: f64, y1: f64, x2: f64, y2: f64) -> ModelRect {
let &CellMetrics {
char_width,
line_height,