From: Simon Tatham Date: Tue, 2 Jan 2024 17:09:30 +0000 (+0000) Subject: Fix handling of newlines in is_char_boundary. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=050e297269134eb2ec2c879eef2be5fcf9680e95;p=mastodonochrome.git Fix handling of newlines in is_char_boundary. 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! --- diff --git a/src/editor.rs b/src/editor.rs index bbda7c3..b692e62 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -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