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
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
use alloc::{
|
use alloc::{string::String, vec::Vec};
|
||||||
string::{String, ToString},
|
|
||||||
vec::Vec,
|
|
||||||
};
|
|
||||||
use core::{cmp, fmt};
|
use core::{cmp, fmt};
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
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.
|
/// 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 {
|
pub enum Affinity {
|
||||||
|
#[default]
|
||||||
Before,
|
Before,
|
||||||
After,
|
After,
|
||||||
}
|
}
|
||||||
|
|
@ -86,12 +84,6 @@ impl Affinity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Affinity {
|
|
||||||
fn default() -> Self {
|
|
||||||
Affinity::Before
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The position of a cursor within a [`Buffer`].
|
/// The position of a cursor within a [`Buffer`].
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct LayoutCursor {
|
pub struct LayoutCursor {
|
||||||
|
|
|
||||||
|
|
@ -613,8 +613,7 @@ impl Edit for Editor {
|
||||||
let line = &self.buffer.lines[self.cursor.line];
|
let line = &self.buffer.lines[self.cursor.line];
|
||||||
self.cursor.index = line.text()[..self.cursor.index]
|
self.cursor.index = line.text()[..self.cursor.index]
|
||||||
.char_indices()
|
.char_indices()
|
||||||
.rev()
|
.next_back()
|
||||||
.next()
|
|
||||||
.map_or(0, |(i, _)| i);
|
.map_or(0, |(i, _)| i);
|
||||||
} else if self.cursor.line > 0 {
|
} else if self.cursor.line > 0 {
|
||||||
// Move cursor to previous line
|
// Move cursor to previous line
|
||||||
|
|
@ -719,15 +718,10 @@ impl Edit for Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust selection
|
// Adjust selection
|
||||||
match self.select_opt {
|
if let Some(ref mut select) = self.select_opt {
|
||||||
Some(ref mut select) => {
|
if select.line == line_i && select.index >= after_whitespace {
|
||||||
if select.line == line_i {
|
select.index += required_indent;
|
||||||
if select.index >= after_whitespace {
|
|
||||||
select.index += required_indent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request redraw
|
// Request redraw
|
||||||
|
|
@ -786,22 +780,15 @@ impl Edit for Editor {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Adjust cursor
|
// Adjust cursor
|
||||||
if self.cursor.line == line_i {
|
if self.cursor.line == line_i && self.cursor.index > last_indent {
|
||||||
if self.cursor.index > last_indent {
|
self.cursor.index -= after_whitespace - last_indent;
|
||||||
self.cursor.index -= after_whitespace - last_indent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust selection
|
// Adjust selection
|
||||||
match self.select_opt {
|
if let Some(ref mut select) = self.select_opt {
|
||||||
Some(ref mut select) => {
|
if select.line == line_i && select.index > last_indent {
|
||||||
if select.line == line_i {
|
select.index -= after_whitespace - last_indent;
|
||||||
if select.index > last_indent {
|
|
||||||
select.index -= after_whitespace - last_indent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request redraw
|
// Request redraw
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ pub trait Edit {
|
||||||
/// Get the current tab width
|
/// Get the current tab width
|
||||||
fn tab_width(&self) -> usize;
|
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);
|
fn set_tab_width(&mut self, tab_width: usize);
|
||||||
|
|
||||||
/// Shape lines until scroll, after adjusting scroll if the cursor moved
|
/// Shape lines until scroll, after adjusting scroll if the cursor moved
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,10 @@
|
||||||
#![allow(clippy::new_without_default)]
|
#![allow(clippy::new_without_default)]
|
||||||
// TODO: address occurrences and then deny
|
// 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
|
// Indexing a slice can cause panics and that is something we always want to avoid
|
||||||
#![allow(clippy::indexing_slicing)]
|
#![allow(clippy::indexing_slicing)]
|
||||||
// Overflows can produce unpredictable results and are only checked in debug builds
|
|
||||||
#![allow(clippy::integer_arithmetic)]
|
|
||||||
// Soundness issues
|
// Soundness issues
|
||||||
//
|
//
|
||||||
// Dereferencing unaligned pointers may be undefined behavior
|
// Dereferencing unaligned pointers may be undefined behavior
|
||||||
|
|
|
||||||
|
|
@ -1251,12 +1251,10 @@ impl ShapeLine {
|
||||||
layout_lines.push(LayoutLine {
|
layout_lines.push(LayoutLine {
|
||||||
w: if align != Align::Justified {
|
w: if align != Align::Justified {
|
||||||
visual_line.w
|
visual_line.w
|
||||||
|
} else if self.rtl {
|
||||||
|
start_x - x
|
||||||
} else {
|
} else {
|
||||||
if self.rtl {
|
x
|
||||||
start_x - x
|
|
||||||
} else {
|
|
||||||
x
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
max_ascent: max_ascent * font_size,
|
max_ascent: max_ascent * font_size,
|
||||||
max_descent: max_descent * font_size,
|
max_descent: max_descent * font_size,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue