From e6b26a5f6ac8f79f0fd26da4fe285fa3c33da21c Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 6 Dec 2019 23:27:51 -0500 Subject: more line wrapping fixes --- src/grid.rs | 1 - src/row.rs | 32 ++++++++++++++++++++++++++++++++ tests/data/fixtures/wrap.in | 5 +++++ tests/data/fixtures/wrap/24.json | 21 +++++++++++++++++++++ tests/data/fixtures/wrap/24.typescript | 1 + tests/data/fixtures/wrap/25.json | 18 ++++++++++++++++++ tests/data/fixtures/wrap/25.typescript | 1 + tests/data/fixtures/wrap/26.json | 21 +++++++++++++++++++++ tests/data/fixtures/wrap/26.typescript | 1 + tests/data/fixtures/wrap/27.json | 18 ++++++++++++++++++ tests/data/fixtures/wrap/27.typescript | 1 + tests/data/fixtures/wrap/28.json | 12 ++++++++++++ tests/data/fixtures/wrap/28.typescript | 1 + 13 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 tests/data/fixtures/wrap/24.json create mode 100644 tests/data/fixtures/wrap/24.typescript create mode 100644 tests/data/fixtures/wrap/25.json create mode 100644 tests/data/fixtures/wrap/25.typescript create mode 100644 tests/data/fixtures/wrap/26.json create mode 100644 tests/data/fixtures/wrap/26.typescript create mode 100644 tests/data/fixtures/wrap/27.json create mode 100644 tests/data/fixtures/wrap/27.typescript create mode 100644 tests/data/fixtures/wrap/28.json create mode 100644 tests/data/fixtures/wrap/28.typescript diff --git a/src/grid.rs b/src/grid.rs index 07bcd6f..b12216c 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -428,7 +428,6 @@ impl Grid { let size = self.size; let pos = self.pos; let row = self.current_row_mut(); - row.wrap(false); for col in pos.col..size.cols { row.erase(col as usize, attrs); } diff --git a/src/row.rs b/src/row.rs index b8da987..090619d 100644 --- a/src/row.rs +++ b/src/row.rs @@ -40,24 +40,31 @@ impl Row { pub fn insert(&mut self, i: usize, cell: crate::cell::Cell) { self.cells.insert(i, cell); + self.wrapped = false; } pub fn remove(&mut self, i: usize) { self.clear_wide(i.try_into().unwrap()); self.cells.remove(i); + self.wrapped = false; } pub fn erase(&mut self, i: usize, attrs: crate::attrs::Attrs) { self.clear_wide(i.try_into().unwrap()); self.cells.get_mut(i).unwrap().clear(attrs); + if i == self.cols() as usize - 1 { + self.wrapped = false; + } } pub fn truncate(&mut self, len: usize) { self.cells.truncate(len); + self.wrapped = false; } pub fn resize(&mut self, len: usize, cell: crate::cell::Cell) { self.cells.resize(len, cell); + self.wrapped = false; } pub fn wrap(&mut self, wrap: bool) { @@ -381,6 +388,31 @@ impl Row { crate::term::ClearRowForward::default().write_buf(contents); } + if prev.wrapped && !self.wrapped { + let end_pos = if self + .get(self.cols() - 1) + .unwrap() + .is_wide_continuation() + { + crate::grid::Pos { + row, + col: self.cols() - 2, + } + } else { + crate::grid::Pos { + row, + col: self.cols() - 1, + } + }; + crate::term::MoveFromTo::new(prev_pos, end_pos) + .write_buf(contents); + prev_pos = end_pos; + crate::term::EraseChar::new(1).write_buf(contents); + let end_cell = self.get(end_pos.col).unwrap(); + contents.extend(end_cell.contents().as_bytes()); + prev_pos.col += if end_cell.is_wide() { 2 } else { 1 }; + } + (prev_pos, prev_attrs) } } diff --git a/tests/data/fixtures/wrap.in b/tests/data/fixtures/wrap.in index 4b1bea2..f079817 100644 --- a/tests/data/fixtures/wrap.in +++ b/tests/data/fixtures/wrap.in @@ -21,3 +21,8 @@ a \x1b[H\x1b[J ネa\x1b[L\x1b[1;79Hbcd +\x1bc\x1b[1;79Habcd +\x1b[1;80H\x1b[X +\x1bc\x1b[1;79Habcd +\x1b[H\x1b[@ +\x1bc\x1b[1;80Haa\x1b[T\x1b[@ diff --git a/tests/data/fixtures/wrap/24.json b/tests/data/fixtures/wrap/24.json new file mode 100644 index 0000000..a4d8d68 --- /dev/null +++ b/tests/data/fixtures/wrap/24.json @@ -0,0 +1,21 @@ +{ + "contents": " abcd", + "cells": { + "0,78": { + "contents": "a" + }, + "0,79": { + "contents": "b" + }, + "1,0": { + "contents": "c" + }, + "1,1": { + "contents": "d" + } + }, + "cursor_position": [ + 1, + 2 + ] +} \ No newline at end of file diff --git a/tests/data/fixtures/wrap/24.typescript b/tests/data/fixtures/wrap/24.typescript new file mode 100644 index 0000000..9e7bc48 --- /dev/null +++ b/tests/data/fixtures/wrap/24.typescript @@ -0,0 +1 @@ +cabcd \ No newline at end of file diff --git a/tests/data/fixtures/wrap/25.json b/tests/data/fixtures/wrap/25.json new file mode 100644 index 0000000..3f7250b --- /dev/null +++ b/tests/data/fixtures/wrap/25.json @@ -0,0 +1,18 @@ +{ + "contents": " a\ncd", + "cells": { + "0,78": { + "contents": "a" + }, + "1,0": { + "contents": "c" + }, + "1,1": { + "contents": "d" + } + }, + "cursor_position": [ + 0, + 79 + ] +} \ No newline at end of file diff --git a/tests/data/fixtures/wrap/25.typescript b/tests/data/fixtures/wrap/25.typescript new file mode 100644 index 0000000..582fae1 --- /dev/null +++ b/tests/data/fixtures/wrap/25.typescript @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/data/fixtures/wrap/26.json b/tests/data/fixtures/wrap/26.json new file mode 100644 index 0000000..a4d8d68 --- /dev/null +++ b/tests/data/fixtures/wrap/26.json @@ -0,0 +1,21 @@ +{ + "contents": " abcd", + "cells": { + "0,78": { + "contents": "a" + }, + "0,79": { + "contents": "b" + }, + "1,0": { + "contents": "c" + }, + "1,1": { + "contents": "d" + } + }, + "cursor_position": [ + 1, + 2 + ] +} \ No newline at end of file diff --git a/tests/data/fixtures/wrap/26.typescript b/tests/data/fixtures/wrap/26.typescript new file mode 100644 index 0000000..9e7bc48 --- /dev/null +++ b/tests/data/fixtures/wrap/26.typescript @@ -0,0 +1 @@ +cabcd \ No newline at end of file diff --git a/tests/data/fixtures/wrap/27.json b/tests/data/fixtures/wrap/27.json new file mode 100644 index 0000000..ac07fa2 --- /dev/null +++ b/tests/data/fixtures/wrap/27.json @@ -0,0 +1,18 @@ +{ + "contents": " a\ncd", + "cells": { + "0,79": { + "contents": "a" + }, + "1,0": { + "contents": "c" + }, + "1,1": { + "contents": "d" + } + }, + "cursor_position": [ + 0, + 0 + ] +} \ No newline at end of file diff --git a/tests/data/fixtures/wrap/27.typescript b/tests/data/fixtures/wrap/27.typescript new file mode 100644 index 0000000..f6122a6 --- /dev/null +++ b/tests/data/fixtures/wrap/27.typescript @@ -0,0 +1 @@ +[@ \ No newline at end of file diff --git a/tests/data/fixtures/wrap/28.json b/tests/data/fixtures/wrap/28.json new file mode 100644 index 0000000..a505566 --- /dev/null +++ b/tests/data/fixtures/wrap/28.json @@ -0,0 +1,12 @@ +{ + "contents": "\n\na", + "cells": { + "2,0": { + "contents": "a" + } + }, + "cursor_position": [ + 1, + 1 + ] +} \ No newline at end of file diff --git a/tests/data/fixtures/wrap/28.typescript b/tests/data/fixtures/wrap/28.typescript new file mode 100644 index 0000000..f760735 --- /dev/null +++ b/tests/data/fixtures/wrap/28.typescript @@ -0,0 +1 @@ +caa[@ \ No newline at end of file -- cgit v1.2.3