chiark / gitweb /
Fix handling of newlines in is_char_boundary.
authorSimon Tatham <anakin@pobox.com>
Tue, 2 Jan 2024 17:09:30 +0000 (17:09 +0000)
committerSimon Tatham <anakin@pobox.com>
Tue, 2 Jan 2024 17:30:18 +0000 (17:30 +0000)
Newlines have width 0, so we were mis-classifying them as a combining
character, causing the point just before one to be considered not a
character boundary!

src/editor.rs

index bbda7c36c501fa28d4bbf4e92f2187c5f3ecbcdf..b692e624cf1f400b0de9e05896cbe532ed8ff5d6 100644 (file)
@@ -27,7 +27,8 @@ impl EditorCore {
                 None => true, // end of string
 
                 // not just before a combining character
-                Some(c) => UnicodeWidthChar::width(c).unwrap_or(0) > 0,
+                Some(c) => c == '\n' ||
+                    UnicodeWidthChar::width(c).unwrap_or(0) > 0,
             }
         }
     }
@@ -1223,6 +1224,13 @@ fn test_layout() {
         ComposeLayoutCell { pos: 0, x: 0, y: 0 },
         ComposeLayoutCell { pos: 1, x: 0, y: 1 }});
 
+    // And now two newlines
+    let composer = Composer::test_new(conf.clone(), "\n\n");
+    assert_eq!(composer.layout(10), vec!{
+        ComposeLayoutCell { pos: 0, x: 0, y: 0 },
+        ComposeLayoutCell { pos: 1, x: 0, y: 1 },
+        ComposeLayoutCell { pos: 2, x: 0, y: 2 }});
+
     // Watch what happens just as we type text across a wrap boundary.
     // At 8 characters, this should be fine as it is, since the wrap
     // width is 1 less than the physical screen width and the cursor