|
|
@ -19,6 +19,7 @@ pub struct DrawCommand {
|
|
|
|
|
|
|
|
|
|
|
|
pub struct Editor {
|
|
|
|
pub struct Editor {
|
|
|
|
pub grid: Vec<Vec<GridCell>>,
|
|
|
|
pub grid: Vec<Vec<GridCell>>,
|
|
|
|
|
|
|
|
pub dirty: Vec<Vec<bool>>,
|
|
|
|
pub title: String,
|
|
|
|
pub title: String,
|
|
|
|
pub size: (u64, u64),
|
|
|
|
pub size: (u64, u64),
|
|
|
|
pub cursor: Cursor,
|
|
|
|
pub cursor: Cursor,
|
|
|
@ -31,6 +32,7 @@ impl Editor {
|
|
|
|
pub fn new(width: u64, height: u64) -> Editor {
|
|
|
|
pub fn new(width: u64, height: u64) -> Editor {
|
|
|
|
let mut editor = Editor {
|
|
|
|
let mut editor = Editor {
|
|
|
|
grid: Vec::new(),
|
|
|
|
grid: Vec::new(),
|
|
|
|
|
|
|
|
dirty: Vec::new(),
|
|
|
|
title: "Neovide".to_string(),
|
|
|
|
title: "Neovide".to_string(),
|
|
|
|
cursor: Cursor::new(),
|
|
|
|
cursor: Cursor::new(),
|
|
|
|
size: (width, height),
|
|
|
|
size: (width, height),
|
|
|
@ -60,8 +62,8 @@ impl Editor {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn build_draw_commands(&self) -> Vec<DrawCommand> {
|
|
|
|
pub fn build_draw_commands(&mut self) -> Vec<DrawCommand> {
|
|
|
|
self.grid.iter().enumerate().map(|(row_index, row)| {
|
|
|
|
let commands = self.grid.iter().enumerate().map(|(row_index, row)| {
|
|
|
|
let mut draw_commands = Vec::new();
|
|
|
|
let mut draw_commands = Vec::new();
|
|
|
|
let mut command = None;
|
|
|
|
let mut command = None;
|
|
|
|
|
|
|
|
|
|
|
@ -78,14 +80,16 @@ impl Editor {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn add_character(command: &mut Option<DrawCommand>, character: &char, row_index: u64, col_index: u64, style: Style) {
|
|
|
|
fn add_character(command: &mut Option<DrawCommand>, character: &char, dirty: bool, row_index: u64, col_index: u64, style: Style) {
|
|
|
|
match command {
|
|
|
|
match command {
|
|
|
|
Some(command) => command.text.push(character.clone()),
|
|
|
|
Some(command) => command.text.push(character.clone()),
|
|
|
|
None => {
|
|
|
|
None => {
|
|
|
|
|
|
|
|
if dirty {
|
|
|
|
command.replace(DrawCommand::new(character.to_string(), (col_index, row_index), style));
|
|
|
|
command.replace(DrawCommand::new(character.to_string(), (col_index, row_index), style));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (col_index, cell) in row.iter().enumerate() {
|
|
|
|
for (col_index, cell) in row.iter().enumerate() {
|
|
|
|
if let Some((character, new_style)) = cell {
|
|
|
|
if let Some((character, new_style)) = cell {
|
|
|
@ -93,7 +97,7 @@ impl Editor {
|
|
|
|
add_command(&mut draw_commands, command);
|
|
|
|
add_command(&mut draw_commands, command);
|
|
|
|
command = None;
|
|
|
|
command = None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_character(&mut command, &character, row_index as u64, col_index as u64, new_style.clone());
|
|
|
|
add_character(&mut command, &character, self.dirty[row_index][col_index], row_index as u64, col_index as u64, new_style.clone());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
add_command(&mut draw_commands, command);
|
|
|
|
add_command(&mut draw_commands, command);
|
|
|
|
command = None;
|
|
|
|
command = None;
|
|
|
@ -102,7 +106,10 @@ impl Editor {
|
|
|
|
add_command(&mut draw_commands, command);
|
|
|
|
add_command(&mut draw_commands, command);
|
|
|
|
|
|
|
|
|
|
|
|
draw_commands
|
|
|
|
draw_commands
|
|
|
|
}).flatten().collect()
|
|
|
|
}).flatten().collect();
|
|
|
|
|
|
|
|
let (width, height) = self.size;
|
|
|
|
|
|
|
|
self.dirty = vec![vec![false; width as usize]; height as usize];
|
|
|
|
|
|
|
|
commands
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn draw_grid_line_cell(&mut self, row_index: u64, column_pos: &mut u64, cell: GridLineCell) {
|
|
|
|
fn draw_grid_line_cell(&mut self, row_index: u64, column_pos: &mut u64, cell: GridLineCell) {
|
|
|
@ -119,10 +126,12 @@ impl Editor {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let row = self.grid.get_mut(row_index as usize).expect("Grid must have size greater than row_index");
|
|
|
|
let row = self.grid.get_mut(row_index as usize).expect("Grid must have size greater than row_index");
|
|
|
|
|
|
|
|
let dirty_row = &mut self.dirty[row_index as usize];
|
|
|
|
for (i, character) in text.chars().enumerate() {
|
|
|
|
for (i, character) in text.chars().enumerate() {
|
|
|
|
let pointer_index = i + *column_pos as usize;
|
|
|
|
let pointer_index = i + *column_pos as usize;
|
|
|
|
if pointer_index < row.len() {
|
|
|
|
if pointer_index < row.len() {
|
|
|
|
row[pointer_index] = Some((character, style.clone()));
|
|
|
|
row[pointer_index] = Some((character, style.clone()));
|
|
|
|
|
|
|
|
dirty_row[pointer_index] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -149,6 +158,7 @@ impl Editor {
|
|
|
|
fn clear(&mut self) {
|
|
|
|
fn clear(&mut self) {
|
|
|
|
let (width, height) = self.size;
|
|
|
|
let (width, height) = self.size;
|
|
|
|
self.grid = vec![vec![None; width as usize]; height as usize];
|
|
|
|
self.grid = vec![vec![None; width as usize]; height as usize];
|
|
|
|
|
|
|
|
self.dirty = vec![vec![true; width as usize]; height as usize];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn scroll_region(&mut self, top: u64, bot: u64, left: u64, right: u64, rows: i64, cols: i64) {
|
|
|
|
fn scroll_region(&mut self, top: u64, bot: u64, left: u64, right: u64, rows: i64, cols: i64) {
|
|
|
@ -186,9 +196,11 @@ impl Editor {
|
|
|
|
let y = new_top + y as i64;
|
|
|
|
let y = new_top + y as i64;
|
|
|
|
if y >= 0 && y < self.grid.len() as i64 {
|
|
|
|
if y >= 0 && y < self.grid.len() as i64 {
|
|
|
|
let row = &mut self.grid[y as usize];
|
|
|
|
let row = &mut self.grid[y as usize];
|
|
|
|
|
|
|
|
let dirty_row = &mut self.dirty[y as usize];
|
|
|
|
let x = new_left + x as i64;
|
|
|
|
let x = new_left + x as i64;
|
|
|
|
if x >= 0 && x < row.len() as i64 {
|
|
|
|
if x >= 0 && x < row.len() as i64 {
|
|
|
|
row[x as usize] = cell;
|
|
|
|
row[x as usize] = cell;
|
|
|
|
|
|
|
|
dirty_row[x as usize] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|