chiark / gitweb /
Fix last-column glitch in post composition.
authorSimon Tatham <anakin@pobox.com>
Fri, 5 Jan 2024 10:13:35 +0000 (10:13 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 5 Jan 2024 10:30:49 +0000 (10:30 +0000)
src/editor.rs

index 6135de7327ffd50fbd8fc7fef70f4870c7576147..aac14baf0740f358fa8b6a1f6e5d1e902436227e 100644 (file)
@@ -918,6 +918,12 @@ impl Composer {
     }
 
     fn layout(&self, width: usize) -> Vec<ComposeLayoutCell> {
+        // 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::<Vec<_>>());
-    assert_eq!(composer.layout(3),
+    assert_eq!(composer.layout(4),
                (0..=3).map(|i| ComposeLayoutCell { pos: i, x: i, y: 0 })
                .collect::<Vec<_>>());
 
@@ -1338,11 +1344,11 @@ fn test_layout() {
             .collect::<Vec<_>>());
 
     // 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::<Vec<_>>());
@@ -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::<Vec<_>>());
     // 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::<Vec<_>>());