}
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;
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<_>>());
.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<_>>());
// 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<_>>());