Do not print extra invisibles on line wraps
This commit is contained in:
parent
95bcd19020
commit
ec725fe399
1 changed files with 16 additions and 4 deletions
|
@ -1714,6 +1714,7 @@ fn layout_highlighted_chunks<'a>(
|
||||||
let mut line = String::new();
|
let mut line = String::new();
|
||||||
let mut invisibles = Vec::new();
|
let mut invisibles = Vec::new();
|
||||||
let mut styles = Vec::new();
|
let mut styles = Vec::new();
|
||||||
|
let mut non_whitespace_added = false;
|
||||||
let mut row = 0;
|
let mut row = 0;
|
||||||
let mut line_exceeded_max_len = false;
|
let mut line_exceeded_max_len = false;
|
||||||
for highlighted_chunk in chunks.chain([HighlightedChunk {
|
for highlighted_chunk in chunks.chain([HighlightedChunk {
|
||||||
|
@ -1732,6 +1733,7 @@ fn layout_highlighted_chunks<'a>(
|
||||||
styles.clear();
|
styles.clear();
|
||||||
row += 1;
|
row += 1;
|
||||||
line_exceeded_max_len = false;
|
line_exceeded_max_len = false;
|
||||||
|
non_whitespace_added = false;
|
||||||
if row == max_line_count {
|
if row == max_line_count {
|
||||||
return layouts;
|
return layouts;
|
||||||
}
|
}
|
||||||
|
@ -1765,16 +1767,26 @@ fn layout_highlighted_chunks<'a>(
|
||||||
underline: text_style.underline,
|
underline: text_style.underline,
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// Line wrap pads its contents with fake whitespaces,
|
||||||
|
// avoid printing them.
|
||||||
|
let inside_wrapped_string = ix > 0;
|
||||||
if highlighted_chunk.is_tab {
|
if highlighted_chunk.is_tab {
|
||||||
invisibles.push(Invisible::Tab {
|
if non_whitespace_added || !inside_wrapped_string {
|
||||||
line_start_offset: line.len(),
|
invisibles.push(Invisible::Tab {
|
||||||
});
|
line_start_offset: line.len(),
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
invisibles.extend(
|
invisibles.extend(
|
||||||
line_chunk
|
line_chunk
|
||||||
.chars()
|
.chars()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|(_, line_char)| line_char.is_whitespace())
|
.filter(|(_, line_char)| {
|
||||||
|
let is_whitespace = line_char.is_whitespace();
|
||||||
|
non_whitespace_added |= !is_whitespace;
|
||||||
|
is_whitespace && (non_whitespace_added || !inside_wrapped_string)
|
||||||
|
})
|
||||||
.map(|(whitespace_index, _)| Invisible::Whitespace {
|
.map(|(whitespace_index, _)| Invisible::Whitespace {
|
||||||
line_offset: line.len() + whitespace_index,
|
line_offset: line.len() + whitespace_index,
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue