From cb958c63f83776a64defd41971173681c9bb3bfd Mon Sep 17 00:00:00 2001 From: Hojjat Date: Fri, 16 Dec 2022 19:15:04 -0700 Subject: [PATCH] Clean up --- src/edit/vi.rs | 4 ++-- src/shape.rs | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/edit/vi.rs b/src/edit/vi.rs index 155aa0d..1b38f00 100644 --- a/src/edit/vi.rs +++ b/src/edit/vi.rs @@ -358,7 +358,7 @@ impl<'a> Edit<'a> for ViEditor<'a> { let (start_x, end_x) = match run.glyphs.get(cursor_glyph) { Some(glyph) => { // Start of detected glyph - if glyph.rtl { + if glyph.level.is_rtl() { ( (glyph.x + glyph.w - cursor_glyph_offset) as i32, (glyph.x + glyph.w - cursor_glyph_offset - cursor_glyph_width) as i32, @@ -373,7 +373,7 @@ impl<'a> Edit<'a> for ViEditor<'a> { None => match run.glyphs.last() { Some(glyph) => { // End of last glyph - if glyph.rtl { + if glyph.level.is_rtl() { ( glyph.x as i32, (glyph.x - cursor_glyph_width) as i32 diff --git a/src/shape.rs b/src/shape.rs index 76c4749..5b942bf 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -498,10 +498,9 @@ impl ShapeLine { // Reset some whitespace chars to paragraph level. // - let line_str: &str = &text[..]; let mut reset_from: Option = Some(0); let mut reset_to: Option = None; - for (i, c) in line_str.char_indices() { + for (i, c) in text.char_indices() { match line_classes[i] { // Ignored by X9 RLE | LRE | RLO | LRO | PDF | BN => {} @@ -509,13 +508,13 @@ impl ShapeLine { B | S => { assert_eq!(reset_to, None); reset_to = Some(i + c.len_utf8()); - if reset_from == None { + if reset_from.is_none() { reset_from = Some(i); } } // Whitespace, isolate formatting WS | FSI | LRI | RLI | PDI => { - if reset_from == None { + if reset_from.is_none() { reset_from = Some(i); } } @@ -540,7 +539,7 @@ impl ShapeLine { } // A modified version of second part of unicode_bidi::bidi_info::visual run - fn reorder(&self, line_range: &Vec<(usize, Range)>) -> Vec> { + fn reorder(&self, line_range: &[(usize, Range)]) -> Vec> { let line : Vec = line_range.iter().map(|(span_index, _)| self.spans[*span_index].level).collect(); // Find consecutive level runs. let mut runs = Vec::new(); @@ -744,13 +743,13 @@ impl ShapeLine { } } - if current_visual_line.len() > 0 { + if !current_visual_line.is_empty() { vl_range_of_spans.push(current_visual_line); } for visual_line in &vl_range_of_spans { - let new_order = self.reorder(&visual_line); + let new_order = self.reorder(visual_line); let mut glyphs = Vec::with_capacity(1); x = start_x; y = 0.; @@ -807,7 +806,7 @@ impl ShapeLine { } if push_line { - layout_lines.push(LayoutLine { w: 0.0 , glyphs: vec![] }); + layout_lines.push(LayoutLine { w: 0.0 , glyphs: Default::default() }); } layout_lines