Wrap model on insert single char

This commit is contained in:
daa 2018-03-19 00:40:18 +03:00
parent c339a27481
commit 4cd6cf46dd
2 changed files with 17 additions and 0 deletions

View File

@ -174,6 +174,15 @@ impl UiModel {
ModelRect::new(top as usize, bot as usize, left, right) ModelRect::new(top as usize, bot as usize, left, right)
} }
/// Move down all lines except first one
pub fn move_down(&mut self) {
let right = self.columns + 1;
for row in (1..self.rows + 1).rev() {
self.copy_row(row as i64, 1, 0, right);
}
}
pub fn clear(&mut self) { pub fn clear(&mut self) {
let (rows, columns) = (self.rows, self.columns); let (rows, columns) = (self.rows, self.columns);
self.clear_region(0, rows - 1, 0, columns - 1); self.clear_region(0, rows - 1, 0, columns - 1);

View File

@ -65,6 +65,14 @@ impl ModelLayout {
if shift { if shift {
//TODO: insert special char //TODO: insert special char
if self.cols_filled + 1 >= self.model.columns {
let rows_filled = self.rows_filled + 1;
self.check_model_size(rows_filled);
self.model.move_down();
self.rows_filled = rows_filled;
}
} else { } else {
self.model.put(c.chars().next().unwrap(), false, None); self.model.put(c.chars().next().unwrap(), false, None);
} }