From 53d431a128c9083807a53c53d0a7d577aef0fd42 Mon Sep 17 00:00:00 2001 From: metiftikci Date: Sat, 21 Oct 2023 15:51:01 +0300 Subject: [PATCH] fix(screen): clear area before print buffer --- src/screen.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/screen.rs b/src/screen.rs index d1bc25f..9657b2c 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -1,6 +1,6 @@ use crate::{ buffer::{mode::BufferMode, Buffer}, - core::{Point, Size}, + core::{Point, Rectangle, Size}, editor::Editor, terminal::CursorStyle, theme::{Color, THEME_ONE as T, WHITE}, @@ -178,6 +178,8 @@ impl Screen { } pub fn print_buffer(&mut self, buffer: &Buffer) { + self.clear_square(buffer.area.clone()); + for y in 0..buffer.area.height { let row_index = buffer.scroll.y + y as usize; match buffer.get_line_visible_text(row_index) { @@ -257,4 +259,20 @@ impl Screen { } } } + + pub fn clear_square(&mut self, area: Rectangle) { + for row in 0..area.height { + for column in 0..area.width { + let cell = self + .rows + .get_mut((area.y + row) as usize) + .unwrap() + .get_mut((area.x + column) as usize) + .unwrap(); + + cell.background_color = T.bg; + cell.char = ' '; + } + } + } }