fix(compatibility): handle deleting chars in lines with widechars (#965)

* fix(compatibility): handle deleting chars in lines with widechars

* style(fmt): make rustfmt happy
This commit is contained in:
Aram Drevekenin 2021-12-22 17:57:59 +01:00 committed by GitHub
parent 827db866e7
commit ec4649c7c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 4 deletions

1
src/tests/fixtures/wide-chars-delete-middle vendored Executable file
View File

@ -0,0 +1 @@
[?2004h[aram@green zellij]$ [aram@green zellij]$ 🏠🏠 abc5~dabceabcfabc abc[1@x

View File

@ -0,0 +1 @@
[?2004h[aram@green zellij]$ [aram@green zellij]$ 🏠🏠🏠🏠🏠🏠a🏠🏠

View File

@ -2249,8 +2249,7 @@ impl Row {
}
}
pub fn insert_character_at(&mut self, terminal_character: TerminalCharacter, x: usize) {
let width_offset = self.excess_width_until(x);
let insert_position = x.saturating_sub(width_offset);
let insert_position = self.absolute_character_index(x);
match self.columns.len().cmp(&insert_position) {
Ordering::Equal => self.columns.push_back(terminal_character),
Ordering::Less => {
@ -2368,8 +2367,9 @@ impl Row {
self.columns.is_empty()
}
pub fn delete_and_return_character(&mut self, x: usize) -> Option<TerminalCharacter> {
if x < self.columns.len() {
Some(self.columns.remove(x).unwrap()) // TODO: just return the remove part?
let erase_position = self.absolute_character_index(x);
if erase_position < self.columns.len() {
Some(self.columns.remove(erase_position).unwrap()) // TODO: just return the remove part?
} else {
None
}

View File

@ -432,6 +432,30 @@ fn insert_character_in_line_with_wide_character() {
assert_snapshot!(format!("{:?}", grid));
}
#[test]
fn delete_char_in_middle_of_line_with_widechar() {
let mut vte_parser = vte::Parser::new();
let mut grid = Grid::new(21, 104, Palette::default());
let fixture_name = "wide-chars-delete-middle";
let content = read_fixture(fixture_name);
for byte in content {
vte_parser.advance(&mut grid, byte);
}
assert_snapshot!(format!("{:?}", grid));
}
#[test]
fn delete_char_in_middle_of_line_with_multiple_widechars() {
let mut vte_parser = vte::Parser::new();
let mut grid = Grid::new(21, 104, Palette::default());
let fixture_name = "wide-chars-delete-middle-after-multi";
let content = read_fixture(fixture_name);
for byte in content {
vte_parser.advance(&mut grid, byte);
}
assert_snapshot!(format!("{:?}", grid));
}
#[test]
fn fish_wide_characters_override_clock() {
let mut vte_parser = vte::Parser::new();

View File

@ -0,0 +1,7 @@
---
source: zellij-server/src/panes/./unit/grid_tests.rs
expression: "format!(\"{:?}\", grid)"
---
00 (C): [aram@green zellij]$ 🏠🏠🏠

View File

@ -0,0 +1,7 @@
---
source: zellij-server/src/panes/./unit/grid_tests.rs
expression: "format!(\"{:?}\", grid)"
---
00 (C): [aram@green zellij]$ 🏠 def abc