aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-12-07 06:37:29 -0500
committerJesse Luehrs <doy@tozt.net>2019-12-07 06:37:29 -0500
commit9af24d9dc020f419c7b60753680e4edc6d8428b7 (patch)
treeee559845132c2a9cc39b3ddc712bfab871d0caa1
parent6f5d88a4835615063e7e6dbdbaceee6494bc0675 (diff)
downloadvt100-rust-9af24d9dc020f419c7b60753680e4edc6d8428b7.tar.gz
vt100-rust-9af24d9dc020f419c7b60753680e4edc6d8428b7.zip
fix positioning cursor past end of line when there are wide characters
-rw-r--r--src/grid.rs28
-rw-r--r--tests/data/fixtures/wrap.in1
-rw-r--r--tests/data/fixtures/wrap/29.json20
-rw-r--r--tests/data/fixtures/wrap/29.typescript2
4 files changed, 39 insertions, 12 deletions
diff --git a/src/grid.rs b/src/grid.rs
index 88c33eb..858f646 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -231,13 +231,10 @@ impl Grid {
if prev_pos != self.pos && self.pos.col >= self.size.cols {
let mut pos = Pos {
row: self.pos.row,
- col: self.size.cols - 2,
+ col: self.size.cols - 1,
};
- if !self.visible_cell(pos).unwrap().is_wide() {
- pos = Pos {
- row: self.pos.row,
- col: self.size.cols - 1,
- };
+ if self.visible_cell(pos).unwrap().is_wide_continuation() {
+ pos.col = self.size.cols - 2;
}
let cell = self.visible_cell(pos).unwrap();
if cell.has_contents() {
@@ -257,6 +254,11 @@ impl Grid {
let mut found = false;
for i in (0..orig_row).rev() {
pos.row = i;
+ pos.col = self.size.cols - 1;
+ if self.visible_cell(pos).unwrap().is_wide_continuation()
+ {
+ pos.col = self.size.cols - 2;
+ }
let cell = self.visible_cell(pos).unwrap();
if cell.has_contents() {
if prev_pos.row != i || prev_pos.col < self.size.cols
@@ -333,13 +335,10 @@ impl Grid {
if prev_pos != self.pos && self.pos.col >= self.size.cols {
let mut pos = Pos {
row: self.pos.row,
- col: self.size.cols - 2,
+ col: self.size.cols - 1,
};
- if !self.visible_cell(pos).unwrap().is_wide() {
- pos = Pos {
- row: self.pos.row,
- col: self.size.cols - 1,
- };
+ if self.visible_cell(pos).unwrap().is_wide_continuation() {
+ pos.col = self.size.cols - 2;
}
let cell = self.visible_cell(pos).unwrap();
if cell.has_contents() {
@@ -359,6 +358,11 @@ impl Grid {
let mut found = false;
for i in (0..orig_row).rev() {
pos.row = i;
+ pos.col = self.size.cols - 1;
+ if self.visible_cell(pos).unwrap().is_wide_continuation()
+ {
+ pos.col = self.size.cols - 2;
+ }
let cell = self.visible_cell(pos).unwrap();
if cell.has_contents() {
if prev_pos.row != i || prev_pos.col < self.size.cols
diff --git a/tests/data/fixtures/wrap.in b/tests/data/fixtures/wrap.in
index f079817..1c85cb2 100644
--- a/tests/data/fixtures/wrap.in
+++ b/tests/data/fixtures/wrap.in
@@ -26,3 +26,4 @@ a
\x1bc\x1b[1;79Habcd
\x1b[H\x1b[@
\x1bc\x1b[1;80Haa\x1b[T\x1b[@
+\x1bc\na\x1b[1;79Hデ\n
diff --git a/tests/data/fixtures/wrap/29.json b/tests/data/fixtures/wrap/29.json
new file mode 100644
index 0000000..7c0324d
--- /dev/null
+++ b/tests/data/fixtures/wrap/29.json
@@ -0,0 +1,20 @@
+{
+ "contents": " デ\na",
+ "cells": {
+ "0,78": {
+ "contents": "デ",
+ "is_wide": true
+ },
+ "0,79": {
+ "contents": "",
+ "is_wide_continuation": true
+ },
+ "1,0": {
+ "contents": "a"
+ }
+ },
+ "cursor_position": [
+ 1,
+ 80
+ ]
+} \ No newline at end of file
diff --git a/tests/data/fixtures/wrap/29.typescript b/tests/data/fixtures/wrap/29.typescript
new file mode 100644
index 0000000..2248a91
--- /dev/null
+++ b/tests/data/fixtures/wrap/29.typescript
@@ -0,0 +1,2 @@
+c
+aデ