- 
                Notifications
    You must be signed in to change notification settings 
- Fork 51
Open
Description
If I set the editor example to use Alignment::Justify, the selection rectangles are shorter than they should, for all lines except the first and the last:
 
I found a fix following this thought process: in Selection::geometry_with, the non-first and non-last lines go through a different path:
if line_ix == line_start_ix || line_ix == line_end_ix {
                // We only need to run the expensive logic on the first and
                // last lines
                // ...
            } else {
                let x = metrics.offset as f64;
                let width = metrics.advance as f64;
                f(
                    Rect::new(x, line_min, x + width + newline_whitespace, line_max),
                    line_ix,
                );
            }The logic makes sense, so metrics.advance is probably not right for justified text.
In align_impl in alignment.rs, the line metrics are modified based on the requested alignment. For Justify, an adjustment is calculated and added to the advance of the clusters:
                            if cluster.info.whitespace().is_space_or_nbsp() {
                                cluster.advance += adjustment;
                                applied += 1;
                            }Adding this adjustment to the advance of the whole line as well seems to fix the issue.
                            if cluster.info.whitespace().is_space_or_nbsp() {
                                cluster.advance += adjustment;
                                line.metrics.advance += adjustment;
                                applied += 1;
                            }
DJMcNab
Metadata
Metadata
Assignees
Labels
No labels