Use char count instead of byte count to determine longest row

This commit is contained in:
Antonio Scandurra 2021-11-18 11:01:12 +01:00
parent b80887dabe
commit 08e0444ee4
2 changed files with 10 additions and 5 deletions

View file

@ -528,16 +528,14 @@ impl BlockSnapshot {
pub fn longest_row(&self) -> u32 {
let input_row = self.wrap_snapshot.longest_row();
let input_row_len = self.wrap_snapshot.line_len(input_row);
let input_row_chars = self.wrap_snapshot.line_char_count(input_row);
let TransformSummary {
longest_row_in_block: block_row,
longest_row_in_block_chars: block_row_len,
longest_row_in_block_chars: block_row_chars,
..
} = &self.transforms.summary();
dbg!(block_row, block_row_len, input_row, input_row_len);
if *block_row_len > input_row_len {
if *block_row_chars > input_row_chars {
*block_row
} else {
self.to_block_point(WrapPoint::new(input_row, 0)).row

View file

@ -674,6 +674,13 @@ impl Snapshot {
len as u32
}
pub fn line_char_count(&self, row: u32) -> u32 {
self.text_chunks(row)
.flat_map(|c| c.chars())
.take_while(|c| *c != '\n')
.count() as u32
}
pub fn soft_wrap_indent(&self, row: u32) -> Option<u32> {
let mut cursor = self.transforms.cursor::<WrapPoint>();
cursor.seek(&WrapPoint::new(row + 1, 0), Bias::Right, &());