diff --git a/src/buffer.rs b/src/buffer.rs index 9d23f63..c67547c 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -1,10 +1,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 #[cfg(not(feature = "std"))] -use alloc::{ - string::{String, ToString}, - vec::Vec, -}; +use alloc::{string::String, vec::Vec}; use core::{cmp, fmt}; use unicode_segmentation::UnicodeSegmentation; @@ -54,8 +51,9 @@ impl Cursor { } /// Whether to associate cursors placed at a boundary between runs with the run before or after it. -#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] +#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd)] pub enum Affinity { + #[default] Before, After, } @@ -86,12 +84,6 @@ impl Affinity { } } -impl Default for Affinity { - fn default() -> Self { - Affinity::Before - } -} - /// The position of a cursor within a [`Buffer`]. #[derive(Debug)] pub struct LayoutCursor { diff --git a/src/edit/editor.rs b/src/edit/editor.rs index a7693af..357ff29 100644 --- a/src/edit/editor.rs +++ b/src/edit/editor.rs @@ -613,8 +613,7 @@ impl Edit for Editor { let line = &self.buffer.lines[self.cursor.line]; self.cursor.index = line.text()[..self.cursor.index] .char_indices() - .rev() - .next() + .next_back() .map_or(0, |(i, _)| i); } else if self.cursor.line > 0 { // Move cursor to previous line @@ -719,15 +718,10 @@ impl Edit for Editor { } // Adjust selection - match self.select_opt { - Some(ref mut select) => { - if select.line == line_i { - if select.index >= after_whitespace { - select.index += required_indent; - } - } + if let Some(ref mut select) = self.select_opt { + if select.line == line_i && select.index >= after_whitespace { + select.index += required_indent; } - None => {} } // Request redraw @@ -786,22 +780,15 @@ impl Edit for Editor { ); // Adjust cursor - if self.cursor.line == line_i { - if self.cursor.index > last_indent { - self.cursor.index -= after_whitespace - last_indent; - } + if self.cursor.line == line_i && self.cursor.index > last_indent { + self.cursor.index -= after_whitespace - last_indent; } // Adjust selection - match self.select_opt { - Some(ref mut select) => { - if select.line == line_i { - if select.index > last_indent { - select.index -= after_whitespace - last_indent; - } - } + if let Some(ref mut select) = self.select_opt { + if select.line == line_i && select.index > last_indent { + select.index -= after_whitespace - last_indent; } - None => {} } // Request redraw diff --git a/src/edit/mod.rs b/src/edit/mod.rs index fbe66c2..be93795 100644 --- a/src/edit/mod.rs +++ b/src/edit/mod.rs @@ -167,7 +167,7 @@ pub trait Edit { /// Get the current tab width fn tab_width(&self) -> usize; - /// Set the current tab width. A tab_width of 0 is not allowed, and will be ignored + /// Set the current tab width. A `tab_width` of 0 is not allowed, and will be ignored fn set_tab_width(&mut self, tab_width: usize); /// Shape lines until scroll, after adjusting scroll if the cursor moved diff --git a/src/lib.rs b/src/lib.rs index ac684b9..52b48f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,10 +61,10 @@ #![allow(clippy::new_without_default)] // TODO: address occurrences and then deny // +// Overflows can produce unpredictable results and are only checked in debug builds +#![allow(clippy::arithmetic_side_effects)] // Indexing a slice can cause panics and that is something we always want to avoid #![allow(clippy::indexing_slicing)] -// Overflows can produce unpredictable results and are only checked in debug builds -#![allow(clippy::integer_arithmetic)] // Soundness issues // // Dereferencing unaligned pointers may be undefined behavior diff --git a/src/shape.rs b/src/shape.rs index 53cba57..e4e5f99 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -1251,12 +1251,10 @@ impl ShapeLine { layout_lines.push(LayoutLine { w: if align != Align::Justified { visual_line.w + } else if self.rtl { + start_x - x } else { - if self.rtl { - start_x - x - } else { - x - } + x }, max_ascent: max_ascent * font_size, max_descent: max_descent * font_size,