linebender / linebender/parley

Unexpected line break with `TextWrapMode::NoWrap` for text beginning with a space

Open
#638 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug C-parley
Dominant language
Rust
Stars
736
Forks
120
Avg merge
1d 3h
Merged PRs (30d)
53

Description

I would expect the following snippet to return a `height` corresponding to a single line of text:
```rust
let text = " !";
let mut layout_ctx: LayoutContext>> = LayoutContext::new();
let mut font_ctx = FontContext::new();
let mut builder = layout_ctx.ranged_builder(&mut font_ctx, text, 1.0, true);

builder.push_default(StyleProperty::FontSize(12f32));
builder.push_default(StyleProperty::TextWrapMode(TextWrapMode::NoWrap));

let mut layout = builder.build(text);
layout.break_all_lines(Some(0f32));

println!("{:?}", layout.height());
for (idx, line) in layout.lines().enumerate() {
println!("line {idx}: {:?}", &text[line.text_range()]);
}
```
However, for me it returns a height of about `32` and two lines (`" "` and `"!"`). In contrast, if `text` is `"!!"`, it works as I would expect it to. This only happens if the first character is a space (`' '`), not a tab character or similar. I don't know if this is intended behaviour, if so, is there a way to ensure a line starting with a space character is not wrapped?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Rust snippet with `TextWrapMode::NoWrap`, comparing text beginning with a space (`" !"`) against `"!!"`, and inspect the behavior reached through `layout.break_all_lines(Some(0f32))`. Done means leading-space text remains on one line under `NoWrap`, with a single-line height, or the intended behavior and a way to achieve it are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.