Fix some clippy lints
This commit is contained in:
parent
6536231dfc
commit
19ae07bd3b
5 changed files with 18 additions and 41 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue