From e13049c91c036354b311bc529b0b258aa4b61952 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 6 Dec 2019 22:15:49 -0500 Subject: fix contents when a wrapped row is followed by an empty row --- src/grid.rs | 4 +++- src/row.rs | 4 ++++ src/screen.rs | 2 +- tests/data/fixtures/il_dl/16.json | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/grid.rs b/src/grid.rs index b29668f..07bcd6f 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -183,11 +183,13 @@ impl Grid { } pub fn write_contents(&self, contents: &mut String) { + let mut wrapping = false; for row in self.visible_rows() { - row.write_contents(contents, 0, self.size.cols); + row.write_contents(contents, 0, self.size.cols, wrapping); if !row.wrapped() { contents.push_str("\n"); } + wrapping = row.wrapped(); } while contents.ends_with('\n') { diff --git a/src/row.rs b/src/row.rs index a0d44a4..b8da987 100644 --- a/src/row.rs +++ b/src/row.rs @@ -85,6 +85,7 @@ impl Row { contents: &mut String, start: u16, width: u16, + wrapping: bool, ) { let mut prev_was_wide = false; @@ -112,6 +113,9 @@ impl Row { prev_col += if cell.is_wide() { 2 } else { 1 }; } } + if prev_col == start && wrapping { + contents.push('\n'); + } } pub fn write_contents_formatted( diff --git a/src/screen.rs b/src/screen.rs index afe50b8..7141c07 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -164,7 +164,7 @@ impl Screen { ) -> impl Iterator + '_ { self.grid().visible_rows().map(move |row| { let mut contents = String::new(); - row.write_contents(&mut contents, start, width); + row.write_contents(&mut contents, start, width, false); contents }) } diff --git a/tests/data/fixtures/il_dl/16.json b/tests/data/fixtures/il_dl/16.json index 102c2f1..2586781 100644 --- a/tests/data/fixtures/il_dl/16.json +++ b/tests/data/fixtures/il_dl/16.json @@ -1,5 +1,5 @@ { - "contents": " a\nb", + "contents": " a\n\nb", "cells": { "0,79": { "contents": "a" -- cgit v1.2.3-54-g00ecf