mirror of
https://github.com/typst/typst
synced 2025-05-30 00:36:24 +08:00
Fix improper line wrapping in the presence of medial newlines (#2056)
Fixes #2019.
This commit is contained in:
parent
ba043a8d70
commit
499c5f2444
@ -1,3 +1,5 @@
|
|||||||
|
use std::iter::Peekable;
|
||||||
|
|
||||||
use icu_properties::{maps::CodePointMapData, LineBreak};
|
use icu_properties::{maps::CodePointMapData, LineBreak};
|
||||||
use icu_provider::AsDeserializingBufferProvider;
|
use icu_provider::AsDeserializingBufferProvider;
|
||||||
use icu_provider_adapters::fork::ForkByKeyProvider;
|
use icu_provider_adapters::fork::ForkByKeyProvider;
|
||||||
@ -933,18 +935,6 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec<L
|
|||||||
// Layout the line.
|
// Layout the line.
|
||||||
let start = pred.line.end;
|
let start = pred.line.end;
|
||||||
|
|
||||||
// Fix for https://github.com/unicode-org/icu4x/issues/3811
|
|
||||||
if i > 0 {
|
|
||||||
if let Some(s_pred) = table.get(i + 1) {
|
|
||||||
let next_start = s_pred.line.end;
|
|
||||||
if !p.bidi.text[start..next_start]
|
|
||||||
.contains(|c: char| !c.is_whitespace())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let attempt = line(vt, p, start..end, mandatory, hyphen);
|
let attempt = line(vt, p, start..end, mandatory, hyphen);
|
||||||
|
|
||||||
// Determine how much the line's spaces would need to be stretched
|
// Determine how much the line's spaces would need to be stretched
|
||||||
@ -1103,7 +1093,7 @@ fn breakpoints<'a>(p: &'a Preparation<'a>) -> Breakpoints<'a> {
|
|||||||
linebreaks.next();
|
linebreaks.next();
|
||||||
Breakpoints {
|
Breakpoints {
|
||||||
p,
|
p,
|
||||||
linebreaks,
|
linebreaks: linebreaks.peekable(),
|
||||||
syllables: None,
|
syllables: None,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
suffix: 0,
|
suffix: 0,
|
||||||
@ -1117,7 +1107,7 @@ struct Breakpoints<'a> {
|
|||||||
/// The paragraph's items.
|
/// The paragraph's items.
|
||||||
p: &'a Preparation<'a>,
|
p: &'a Preparation<'a>,
|
||||||
/// The inner iterator over the unicode line break opportunities.
|
/// The inner iterator over the unicode line break opportunities.
|
||||||
linebreaks: LineBreakIteratorUtf8<'a, 'a>,
|
linebreaks: Peekable<LineBreakIteratorUtf8<'a, 'a>>,
|
||||||
/// Iterator over syllables of the current word.
|
/// Iterator over syllables of the current word.
|
||||||
syllables: Option<hypher::Syllables<'a>>,
|
syllables: Option<hypher::Syllables<'a>>,
|
||||||
/// The current text offset.
|
/// The current text offset.
|
||||||
@ -1179,6 +1169,20 @@ impl Iterator for Breakpoints<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fix for https://github.com/unicode-org/icu4x/issues/3811
|
||||||
|
if !self.mandatory {
|
||||||
|
while let Some(&next) = self.linebreaks.peek() {
|
||||||
|
if !self.p.bidi.text[self.end..next]
|
||||||
|
.contains(|c: char| !c.is_whitespace())
|
||||||
|
{
|
||||||
|
self.end = next;
|
||||||
|
self.linebreaks.next();
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.offset = self.end;
|
self.offset = self.end;
|
||||||
Some((self.end, self.mandatory, false))
|
Some((self.end, self.mandatory, false))
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 51 KiB |
@ -50,3 +50,16 @@ This text can be fitted in one line.
|
|||||||
lorem ipsum 1234, lorem ipsum dolor sit amet
|
lorem ipsum 1234, lorem ipsum dolor sit amet
|
||||||
|
|
||||||
#" leading whitespace should still be displayed"
|
#" leading whitespace should still be displayed"
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test that justification doesn't break code blocks
|
||||||
|
|
||||||
|
#set par(justify: true)
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
int main() {
|
||||||
|
printf("Hello world\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user