From: Simon Tatham Date: Fri, 5 Jan 2024 10:13:35 +0000 (+0000) Subject: Fix last-column glitch in post composition. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=eaae90b7f4501500471a8c223951d27ed004dd02;p=mastodonochrome.git Fix last-column glitch in post composition. --- diff --git a/src/editor.rs b/src/editor.rs index 6135de7..aac14ba 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -918,6 +918,12 @@ impl Composer { } fn layout(&self, width: usize) -> Vec { + // Leave the last column blank, if possible. Partly because of + // Monochrome tradition, but also, that's a convenient place + // to put _just the cursor_ when it's on the newline at the + // end of an (n-1)-char line that hasn't wrapped yet. + let width = width.saturating_sub(1); + let mut cells = Vec::new(); let mut pos = 0; let mut x = 0; @@ -1325,7 +1331,7 @@ fn test_layout() { assert_eq!(composer.layout(10), (0..=3).map(|i| ComposeLayoutCell { pos: i, x: i, y: 0 }) .collect::>()); - assert_eq!(composer.layout(3), + assert_eq!(composer.layout(4), (0..=3).map(|i| ComposeLayoutCell { pos: i, x: i, y: 0 }) .collect::>()); @@ -1338,11 +1344,11 @@ fn test_layout() { .collect::>()); // An overlong line, which has to wrap via the fallback - // hard_wrap_pos system, so we get the full 10 characters on the - // first line + // hard_wrap_pos system, so we get the full 10 characters (as + // usual, omitting the last column) on the first line let composer = Composer::test_new(conf.clone(), "abcxdefxghixjkl"); assert_eq!( - composer.layout(10), + composer.layout(11), (0..=9).map(|i| ComposeLayoutCell { pos: i, x: i, y: 0 }).chain( (0..=5).map(|i| ComposeLayoutCell { pos: i+10, x: i, y: 1 })) .collect::>()); @@ -1367,14 +1373,14 @@ fn test_layout() { // rather than on a character. let composer = Composer::test_new(conf.clone(), "abc def "); assert_eq!( - composer.layout(8), + composer.layout(9), (0..=8).map(|i| ComposeLayoutCell { pos: i, x: i, y: 0 }) .collect::>()); // Now we type the next character, and it should wrap on to the // next line. let composer = Composer::test_new(conf.clone(), "abc def g"); assert_eq!( - composer.layout(8), + composer.layout(9), (0..=7).map(|i| ComposeLayoutCell { pos: i, x: i, y: 0 }).chain( (0..=1).map(|i| ComposeLayoutCell { pos: i+8, x: i, y: 1 })) .collect::>());