Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incongruent direction indentation #3

Merged
merged 4 commits into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions src/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,14 +1079,24 @@ impl ShapeLine {
}
word_range_width += word_width;
continue;
} else if wrap == Wrap::Glyph
// Make sure that the word is able to fit on it's own line, if not, fall back to Glyph wrapping.
}

let on_first_line = visual_lines.is_empty();
let word_fits_on_current_line =
current_visual_line.w + word_width <= line_width;

if wrap == Wrap::Glyph
// Make sure that the word is able to fit on its own line, if not, fall back to Glyph wrapping.
|| (wrap == Wrap::WordOrGlyph && word_width > line_width)
// If we're on the first line and can't fit the word on its own
|| (wrap == Wrap::WordOrGlyph && on_first_line && !word_fits_on_current_line)
{
// Commit the current line so that the word starts on the next line.
if word_range_width > 0.
&& wrap == Wrap::WordOrGlyph
&& word_width > line_width
&& ((wrap == Wrap::WordOrGlyph && word_width > line_width)
|| (wrap == Wrap::WordOrGlyph
&& on_first_line
&& !word_fits_on_current_line))
{
add_to_visual_line(
&mut current_visual_line,
Expand Down Expand Up @@ -1207,18 +1217,22 @@ impl ShapeLine {
continue;
}

let on_first_line = visual_lines.is_empty();
let word_fits_on_current_line =
current_visual_line.w + word_width <= line_width;

if wrap == Wrap::Glyph
// Make sure that the word is able to fit on it's own line, if not, fall back to Glyph wrapping.
|| (wrap == Wrap::WordOrGlyph && word_width > line_width)
// If we're on the first line
|| (wrap == Wrap::WordOrGlyph && visual_lines.len() == 0 &&
// and we can't fit the rest of this word on the line
(current_visual_line.w + word_width > line_width))
// If we're on the first line and can't fit the word on its own
|| (wrap == Wrap::WordOrGlyph && on_first_line && !word_fits_on_current_line)
{
// Commit the current line so that the word starts on the next line.
if word_range_width > 0.
&& wrap == Wrap::WordOrGlyph
&& word_width > line_width
&& ((wrap == Wrap::WordOrGlyph && word_width > line_width)
|| (wrap == Wrap::WordOrGlyph
&& on_first_line
&& !word_fits_on_current_line))
{
add_to_visual_line(
&mut current_visual_line,
Expand Down