From 9af24d9dc020f419c7b60753680e4edc6d8428b7 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 7 Dec 2019 06:37:29 -0500 Subject: fix positioning cursor past end of line when there are wide characters --- src/grid.rs | 28 ++++++++++++++++------------ tests/data/fixtures/wrap.in | 1 + tests/data/fixtures/wrap/29.json | 20 ++++++++++++++++++++ tests/data/fixtures/wrap/29.typescript | 2 ++ 4 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 tests/data/fixtures/wrap/29.json create mode 100644 tests/data/fixtures/wrap/29.typescript 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デ -- cgit v1.2.3