Repository navigation
Adjust CJK punctuation spacing correctly with indents - #8570
Conversation
|
I considered applying the same logic to the end of lines for consistency, but since indents shouldn't appear at line ends, I'm putting that on hold for now. |
| pub fn leading_visible_text_mut(&mut self) -> Option<&mut ShapedText<'a>> { | ||
| self.0 | ||
| .iter_mut() | ||
| .find(|(_, item)| matches!(**item, Item::Text(_)))? |
There was a problem hiding this comment.
This will skip over anything, including e.g. a box, which could be surprising. In the context of this PR I think it works because it's only called if text.trim_start().starts_with(BEGIN_PUNCT_PAT) and the box will not trigger that, but it's still problematic.
Is the idea here to skip over spacing? Perhaps that could be done more directly by filtering out Item::Absolute and potentially Fractional (note though that it can also contain a fractional-width box). We would also need to decide how weak and fractional spacing should interact with this adjustment. It is hard for me to judge.
There was a problem hiding this comment.
Note also that this part of the code has been refactored on main, so it would be worthwhile to rebase before updating things here.
| fn adjust_cj_at_line_start(p: &Preparation, items: &mut Items) { | ||
| let Some(shaped) = items.leading_text_mut() else { return }; | ||
| let Some(shaped) = items.leading_visible_text_mut() else { | ||
| return; |
There was a problem hiding this comment.
If you drop the ;, this formats more nicely.
| let text = &p.text[range]; | ||
|
|
||
| if text.starts_with(BEGIN_PUNCT_PAT) | ||
| // Ignore leading whitespace (e.g., indents) to properly detect beginning punctuation. |
There was a problem hiding this comment.
Also worth mentioning that a box(width: 1fr, ..) will also be represented as a space in the text.
d804046 to
16fc5bd
Compare
|
Thanks for the review! In the end, instead of deciding separately whether As part of this change, I also avoided using a broad I also think that keeping paragraph indentation explicitly distinct from other inline items provides a useful foundation for addressing cases such as #4011 in the future. |
Co-Authored-By: TiggeZaki <[email protected]>
16fc5bd to
2c8463f
Compare
|
Thanks! The I opened and merged #8988 first because it allows us to get rid of the string-based checks entirely, significantly simplifying this. |


related to #2348
When adjusting at line boundaries, I updated the process to ignore whitespaces created by initial indents. As a result, proper spacing adjustments are now applied to CJK punctuation even when an indent is present.