Skip to content

Commit

Permalink
fix(compatibility): handle inserting characters after wide character (#…
Browse files Browse the repository at this point in the history
…964)

* fix(compatibility): handle inserting characters in the middle of a line after a wide character

* style(fmt): make rustfmt happy
  • Loading branch information
imsnif authored Dec 22, 2021
1 parent be54e2b commit 52977a7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/tests/fixtures/wide_characters_middle_line_insert
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[?2004h[aram@green zellij]$ [aram@green zellij]$ 🏠🏠 abcdabceabcfabc abc[1@x
Expand Down
9 changes: 6 additions & 3 deletions zellij-server/src/panes/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2249,14 +2249,17 @@ impl Row {
}
}
pub fn insert_character_at(&mut self, terminal_character: TerminalCharacter, x: usize) {
match self.columns.len().cmp(&x) {
let width_offset = self.excess_width_until(x);
let insert_position = x.saturating_sub(width_offset);
match self.columns.len().cmp(&insert_position) {
Ordering::Equal => self.columns.push_back(terminal_character),
Ordering::Less => {
self.columns.resize(x, EMPTY_TERMINAL_CHARACTER);
self.columns
.resize(insert_position, EMPTY_TERMINAL_CHARACTER);
self.columns.push_back(terminal_character);
}
Ordering::Greater => {
self.columns.insert(x, terminal_character);
self.columns.insert(insert_position, terminal_character);
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions zellij-server/src/panes/unit/grid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,18 @@ fn wide_characters_line_wrap() {
assert_snapshot!(format!("{:?}", grid));
}

#[test]
fn insert_character_in_line_with_wide_character() {
let mut vte_parser = vte::Parser::new();
let mut grid = Grid::new(21, 104, Palette::default());
let fixture_name = "wide_characters_middle_line_insert";
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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: zellij-server/src/panes/./unit/grid_tests.rs
expression: "format!(\"{:?}\", grid)"

---
00 (C): [aram@green zellij]$ 🏠 xdef abc

0 comments on commit 52977a7

Please sign in to comment.