diff --git a/ui/src/components/mod.rs b/ui/src/components/mod.rs index 5b9218463..b7bb6b4a6 100644 --- a/ui/src/components/mod.rs +++ b/ui/src/components/mod.rs @@ -84,11 +84,34 @@ pub trait Component { } } + +// TODO: word break. pub fn copy_area_with_break(grid_dest: &mut CellBuffer, grid_src: &CellBuffer, dest: Area, src: Area) { + if !is_valid_area!(dest) || !is_valid_area!(src) { + eprintln!("BUG: Invalid areas in copy_area:\n src: {:?}\n dest: {:?}", src, dest); + return; + } + let mut src_x = get_x(upper_left!(src)); + let mut src_y = get_y(upper_left!(src)); - + 'y_: for y in get_y(upper_left!(dest))..=get_y(bottom_right!(dest)) { + 'x_: for x in get_x(upper_left!(dest))..=get_x(bottom_right!(dest)) { + grid_dest[(x,y)] = grid_src[(src_x, src_y)]; + if src_x == get_x(bottom_right!(src)) { + src_y += 1; + src_x = 0; + if src_y == get_y(bottom_right!(src)) { + //clear_area(grid_dest, ((get_x(upper_left!(dest)), y), bottom_right!(dest))); + break 'y_; + } + break 'x_; + } + src_x += 1; + } + } } + /// Copy a source `Area` to a destination. pub fn copy_area(grid_dest: &mut CellBuffer, grid_src: &CellBuffer, dest: Area, src: Area) { if !is_valid_area!(dest) || !is_valid_area!(src) { diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index 264ece737..70a23b50b 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -257,7 +257,7 @@ impl Component for Pager { //let pager_stop: bool = context.settings.pager.pager_stop; //let rows = y(bottom_right) - y(upper_left); //let page_length = rows / self.height; - copy_area(grid, &self.content, area, ((0, self.cursor_pos), (self.width - 1, self.height - 1))); + copy_area_with_break(grid, &self.content, area, ((0, self.cursor_pos), (self.width - 1, self.height - 1))); context.dirty_areas.push_back(area); } fn process_event(&mut self, event: &UIEvent, _context: &mut Context) {