cargo clippy ran

This commit is contained in:
Priec
2025-08-18 19:42:31 +02:00
parent 7b2f021509
commit c915b3287b
25 changed files with 224 additions and 993 deletions

View File

@@ -19,7 +19,7 @@ impl CursorManager {
#[cfg(feature = "textmode-normal")]
{
let style = SetCursorStyle::SteadyBar;
return execute!(io::stdout(), style);
execute!(io::stdout(), style)
}
// Default (not normal): original mapping

View File

@@ -486,7 +486,7 @@ fn render_field_labels<T: CanvasTheme>(
) {
for (i, field) in fields.iter().enumerate() {
let label = Paragraph::new(Line::from(Span::styled(
format!("{}:", field),
format!("{field}:"),
Style::default().fg(theme.fg()),
)));
f.render_widget(
@@ -595,50 +595,48 @@ fn apply_characterwise_highlighting<'a, T: CanvasTheme>(
Span::styled(highlighted, highlight_style),
Span::styled(after, normal_style),
])
} else {
if field_index == anchor_field {
if anchor_field < *current_field_idx {
let clamped_start = anchor_char.min(text_len);
let before: String = text.chars().take(clamped_start).collect();
let highlighted: String = text.chars().skip(clamped_start).collect();
} else if field_index == anchor_field {
if anchor_field < *current_field_idx {
let clamped_start = anchor_char.min(text_len);
let before: String = text.chars().take(clamped_start).collect();
let highlighted: String = text.chars().skip(clamped_start).collect();
Line::from(vec![
Span::styled(before, normal_style),
Span::styled(highlighted, highlight_style),
])
} else {
let clamped_end = anchor_char.min(text_len);
let highlighted: String = text.chars().take(clamped_end + 1).collect();
let after: String = text.chars().skip(clamped_end + 1).collect();
Line::from(vec![
Span::styled(highlighted, highlight_style),
Span::styled(after, normal_style),
])
}
} else if field_index == *current_field_idx {
if anchor_field < *current_field_idx {
let clamped_end = current_cursor_pos.min(text_len);
let highlighted: String = text.chars().take(clamped_end + 1).collect();
let after: String = text.chars().skip(clamped_end + 1).collect();
Line::from(vec![
Span::styled(highlighted, highlight_style),
Span::styled(after, normal_style),
])
} else {
let clamped_start = current_cursor_pos.min(text_len);
let before: String = text.chars().take(clamped_start).collect();
let highlighted: String = text.chars().skip(clamped_start).collect();
Line::from(vec![
Span::styled(before, normal_style),
Span::styled(highlighted, highlight_style),
])
}
Line::from(vec![
Span::styled(before, normal_style),
Span::styled(highlighted, highlight_style),
])
} else {
Line::from(Span::styled(text, highlight_style))
let clamped_end = anchor_char.min(text_len);
let highlighted: String = text.chars().take(clamped_end + 1).collect();
let after: String = text.chars().skip(clamped_end + 1).collect();
Line::from(vec![
Span::styled(highlighted, highlight_style),
Span::styled(after, normal_style),
])
}
} else if field_index == *current_field_idx {
if anchor_field < *current_field_idx {
let clamped_end = current_cursor_pos.min(text_len);
let highlighted: String = text.chars().take(clamped_end + 1).collect();
let after: String = text.chars().skip(clamped_end + 1).collect();
Line::from(vec![
Span::styled(highlighted, highlight_style),
Span::styled(after, normal_style),
])
} else {
let clamped_start = current_cursor_pos.min(text_len);
let before: String = text.chars().take(clamped_start).collect();
let highlighted: String = text.chars().skip(clamped_start).collect();
Line::from(vec![
Span::styled(before, normal_style),
Span::styled(highlighted, highlight_style),
])
}
} else {
Line::from(Span::styled(text, highlight_style))
}
} else {
Line::from(Span::styled(text, normal_style))
@@ -710,6 +708,6 @@ pub fn render_canvas_default<D: DataProvider>(
area: Rect,
editor: &FormEditor<D>,
) -> Option<Rect> {
let theme = DefaultCanvasTheme::default();
let theme = DefaultCanvasTheme;
render_canvas(f, area, editor, &theme)
}

View File

@@ -2,14 +2,11 @@
// canvas/src/modes/highlight.rs
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Default)]
pub enum HighlightState {
#[default]
Off,
Characterwise { anchor: (usize, usize) }, // (field_index, char_position)
Linewise { anchor_line: usize }, // field_index
}
impl Default for HighlightState {
fn default() -> Self {
HighlightState::Off
}
}

View File

@@ -39,7 +39,7 @@ impl ModeManager {
#[cfg(feature = "textmode-normal")]
{
// Always force Edit in normalmode
return Ok(AppMode::Edit);
Ok(AppMode::Edit)
}
#[cfg(not(feature = "textmode-normal"))]

View File

@@ -25,7 +25,6 @@ impl<D: DataProvider> FormEditor<D> {
{
let _ = CursorManager::update_for_mode(AppMode::Edit);
}
return;
}
// Default (not normal): original vim behavior
@@ -119,7 +118,7 @@ impl<D: DataProvider> FormEditor<D> {
{
self.close_suggestions();
}
return Ok(());
Ok(())
}
// Default (not normal): original vim behavior
@@ -155,7 +154,6 @@ impl<D: DataProvider> FormEditor<D> {
{
let _ = CursorManager::update_for_mode(AppMode::Edit);
}
return;
}
// Default (not normal): vim behavior
@@ -169,7 +167,6 @@ impl<D: DataProvider> FormEditor<D> {
// NORMALMODE: ignore request (stay in Edit)
#[cfg(feature = "textmode-normal")]
{
return;
}
// Default (not normal): original vim
@@ -193,7 +190,6 @@ impl<D: DataProvider> FormEditor<D> {
// NORMALMODE: ignore
#[cfg(feature = "textmode-normal")]
{
return;
}
// Default (not normal): original vim
@@ -216,7 +212,6 @@ impl<D: DataProvider> FormEditor<D> {
// NORMALMODE: ignore
#[cfg(feature = "textmode-normal")]
{
return;
}
// Default (not normal): original vim
@@ -237,7 +232,7 @@ impl<D: DataProvider> FormEditor<D> {
pub fn is_highlight_mode(&self) -> bool {
#[cfg(feature = "textmode-normal")]
{
return false;
false
}
#[cfg(not(feature = "textmode-normal"))]
{

View File

@@ -46,12 +46,11 @@ impl<D: DataProvider> FormEditor<D> {
}
}
if !moved {
if self.ui_state.cursor_pos > 0 {
if !moved
&& self.ui_state.cursor_pos > 0 {
self.ui_state.cursor_pos -= 1;
self.ui_state.ideal_cursor_column = self.ui_state.cursor_pos;
}
}
Ok(())
}
@@ -141,7 +140,7 @@ impl<D: DataProvider> FormEditor<D> {
// Successfully moved to next field, try to find first word
let new_text = self.current_text();
if !new_text.is_empty() {
let first_word_pos = if new_text.chars().next().map_or(false, |c| !c.is_whitespace()) {
let first_word_pos = if new_text.chars().next().is_some_and(|c| !c.is_whitespace()) {
// Field starts with non-whitespace, go to position 0
0
} else {
@@ -177,7 +176,7 @@ impl<D: DataProvider> FormEditor<D> {
self.ui_state.ideal_cursor_column = 0;
} else {
// Find first word in new field
let first_word_pos = if new_text.chars().next().map_or(false, |c| !c.is_whitespace()) {
let first_word_pos = if new_text.chars().next().is_some_and(|c| !c.is_whitespace()) {
// Field starts with non-whitespace, go to position 0
0
} else {
@@ -419,7 +418,7 @@ impl<D: DataProvider> FormEditor<D> {
// Successfully moved to next field, try to find first big_word
let new_text = self.current_text();
if !new_text.is_empty() {
let first_big_word_pos = if new_text.chars().next().map_or(false, |c| !c.is_whitespace()) {
let first_big_word_pos = if new_text.chars().next().is_some_and(|c| !c.is_whitespace()) {
// Field starts with non-whitespace, go to position 0
0
} else {
@@ -455,7 +454,7 @@ impl<D: DataProvider> FormEditor<D> {
self.ui_state.ideal_cursor_column = 0;
} else {
// Find first big_word in new field
let first_big_word_pos = if new_text.chars().next().map_or(false, |c| !c.is_whitespace()) {
let first_big_word_pos = if new_text.chars().next().is_some_and(|c| !c.is_whitespace()) {
// Field starts with non-whitespace, go to position 0
0
} else {
@@ -644,8 +643,8 @@ impl<D: DataProvider> FormEditor<D> {
if current_text.is_empty() {
let current_field = self.ui_state.current_field;
if self.move_up().is_ok() {
if self.ui_state.current_field != current_field {
if self.move_up().is_ok()
&& self.ui_state.current_field != current_field {
let new_text = self.current_text();
if !new_text.is_empty() {
// Find first big_word end in new field
@@ -654,7 +653,6 @@ impl<D: DataProvider> FormEditor<D> {
self.ui_state.ideal_cursor_column = last_big_word_end;
}
}
}
return;
}
@@ -664,8 +662,8 @@ impl<D: DataProvider> FormEditor<D> {
// Only try to cross fields if we didn't move at all (stayed at same position)
if new_pos == current_pos {
let current_field = self.ui_state.current_field;
if self.move_up().is_ok() {
if self.ui_state.current_field != current_field {
if self.move_up().is_ok()
&& self.ui_state.current_field != current_field {
let new_text = self.current_text();
if !new_text.is_empty() {
let last_big_word_end = find_big_word_end(new_text, 0);
@@ -673,7 +671,6 @@ impl<D: DataProvider> FormEditor<D> {
self.ui_state.ideal_cursor_column = last_big_word_end;
}
}
}
} else {
// Normal big_word movement within current field
let is_edit_mode = self.ui_state.current_mode == AppMode::Edit;

View File

@@ -149,8 +149,8 @@ fn calculate_dropdown_position(
if dropdown_area.right() > frame_area.width {
dropdown_area.x = frame_area.width.saturating_sub(dropdown_width);
}
dropdown_area.x = dropdown_area.x.max(0);
dropdown_area.y = dropdown_area.y.max(0);
dropdown_area.x = dropdown_area.x;
dropdown_area.y = dropdown_area.y;
dropdown_area
}

View File

@@ -355,7 +355,7 @@ impl TextAreaState {
#[cfg(feature = "gui")]
pub fn cursor(&self, area: Rect, block: Option<&Block<'_>>) -> (u16, u16) {
let inner = if let Some(b) = block { b.inner(area) } else { area };
let line_idx = self.current_field() as usize;
let line_idx = self.current_field();
match self.overflow_mode {
TextOverflowMode::Wrap => {
@@ -375,7 +375,7 @@ impl TextAreaState {
let col_chars = self.display_cursor_position();
let (subrow, x_cols) = wrapped_rows_to_cursor_indented(
&current_line,
current_line,
width,
indent,
col_chars,
@@ -478,7 +478,7 @@ impl TextAreaState {
}
let indent = self.wrap_indent_cols;
let line_idx = self.current_field() as usize;
let line_idx = self.current_field();
let prefix_rows =
self.visual_rows_before_line_and_intra_indented(width, line_idx);
@@ -487,7 +487,7 @@ impl TextAreaState {
let col = self.display_cursor_position();
let (subrow, _x_cols) =
wrapped_rows_to_cursor_indented(&current_line, width, indent, col);
wrapped_rows_to_cursor_indented(current_line, width, indent, col);
let caret_vis_row = prefix_rows.saturating_add(subrow);

View File

@@ -314,11 +314,11 @@ impl<'a> StatefulWidget for TextArea<'a> {
match state.overflow_mode {
TextOverflowMode::Wrap => unreachable!(),
TextOverflowMode::Indicator { ch } => {
let fits = display_width(&s) <= inner.width;
let fits = display_width(s) <= inner.width;
let start_cols = if i == state.current_field() {
let col_idx = state.display_cursor_position();
let cursor_cols = display_cols_up_to(&s, col_idx);
let cursor_cols = display_cols_up_to(s, col_idx);
let (target_h, _left_cols) =
compute_h_scroll_with_padding(cursor_cols, inner.width);
@@ -332,7 +332,7 @@ impl<'a> StatefulWidget for TextArea<'a> {
};
display_lines.push(clip_window_with_indicator_padded(
&s,
s,
inner.width,
ch,
start_cols,

View File

@@ -108,7 +108,7 @@ impl FormattingResult {
pub fn success(formatted: impl Into<String>) -> Self {
FormattingResult::Success {
formatted: formatted.into(),
mapper: Arc::new(DefaultPositionMapper::default()),
mapper: Arc::new(DefaultPositionMapper),
}
}
@@ -117,7 +117,7 @@ impl FormattingResult {
FormattingResult::Warning {
formatted: formatted.into(),
message: message.into(),
mapper: Arc::new(DefaultPositionMapper::default()),
mapper: Arc::new(DefaultPositionMapper),
}
}
@@ -187,7 +187,7 @@ mod tests {
#[test]
fn default_mapper_roundtrip_basic() {
let mapper = DefaultPositionMapper::default();
let mapper = DefaultPositionMapper;
let raw = "01001";
let formatted = "010 01";

View File

@@ -23,8 +23,10 @@ pub struct CharacterLimits {
/// How to count characters for limit checking
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Default)]
pub enum CountMode {
/// Count actual characters (default)
#[default]
Characters,
/// Count display width (useful for CJK characters)
@@ -34,11 +36,6 @@ pub enum CountMode {
Bytes,
}
impl Default for CountMode {
fn default() -> Self {
CountMode::Characters
}
}
/// Result of a character limit check
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -157,9 +154,7 @@ impl CharacterLimits {
if let Some(max) = self.max_length {
if new_count > max {
return Some(ValidationResult::error(format!(
"Character limit exceeded: {}/{}",
new_count,
max
"Character limit exceeded: {new_count}/{max}"
)));
}
@@ -167,9 +162,7 @@ impl CharacterLimits {
if let Some(warning_threshold) = self.warning_threshold {
if new_count >= warning_threshold && current_count < warning_threshold {
return Some(ValidationResult::warning(format!(
"Approaching character limit: {}/{}",
new_count,
max
"Approaching character limit: {new_count}/{max}"
)));
}
}
@@ -186,9 +179,7 @@ impl CharacterLimits {
if let Some(min) = self.min_length {
if count < min {
return Some(ValidationResult::warning(format!(
"Minimum length not met: {}/{}",
count,
min
"Minimum length not met: {count}/{min}"
)));
}
}
@@ -197,9 +188,7 @@ impl CharacterLimits {
if let Some(max) = self.max_length {
if count > max {
return Some(ValidationResult::error(format!(
"Character limit exceeded: {}/{}",
count,
max
"Character limit exceeded: {count}/{max}"
)));
}
@@ -207,9 +196,7 @@ impl CharacterLimits {
if let Some(warning_threshold) = self.warning_threshold {
if count >= warning_threshold {
return Some(ValidationResult::warning(format!(
"Approaching character limit: {}/{}",
count,
max
"Approaching character limit: {count}/{max}"
)));
}
}
@@ -251,20 +238,16 @@ impl CharacterLimits {
match self.check_limits(text) {
LimitCheckResult::Ok => {
// Show current/max if we have a max limit
if let Some(max) = self.max_length {
Some(format!("{}/{}", self.count(text), max))
} else {
None
}
self.max_length.map(|max| format!("{}/{}", self.count(text), max))
},
LimitCheckResult::Warning { current, max } => {
Some(format!("{}/{} (approaching limit)", current, max))
Some(format!("{current}/{max} (approaching limit)"))
},
LimitCheckResult::Exceeded { current, max } => {
Some(format!("{}/{} (exceeded)", current, max))
Some(format!("{current}/{max} (exceeded)"))
},
LimitCheckResult::TooShort { current, min } => {
Some(format!("{}/{} minimum", current, min))
Some(format!("{current}/{min} minimum"))
},
}
}
@@ -284,8 +267,7 @@ impl CharacterLimits {
let count = self.count(text);
if count > 0 && count < min {
return Some(format!(
"Field must be empty or have at least {} characters (currently: {})",
min, count
"Field must be empty or have at least {min} characters (currently: {count})"
));
}
}

View File

@@ -2,9 +2,11 @@
//! Pure display mask system - user-defined patterns only
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Default)]
pub enum MaskDisplayMode {
/// Only show separators as user types
/// Example: "" → "", "123" → "123", "12345" → "(123) 45"
#[default]
Dynamic,
/// Show full template with placeholders from start
@@ -15,11 +17,6 @@ pub enum MaskDisplayMode {
},
}
impl Default for MaskDisplayMode {
fn default() -> Self {
MaskDisplayMode::Dynamic
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DisplayMask {

View File

@@ -49,8 +49,8 @@ impl std::fmt::Debug for CharacterFilter {
CharacterFilter::Alphabetic => write!(f, "Alphabetic"),
CharacterFilter::Numeric => write!(f, "Numeric"),
CharacterFilter::Alphanumeric => write!(f, "Alphanumeric"),
CharacterFilter::Exact(ch) => write!(f, "Exact('{}')", ch),
CharacterFilter::OneOf(chars) => write!(f, "OneOf({:?})", chars),
CharacterFilter::Exact(ch) => write!(f, "Exact('{ch}')"),
CharacterFilter::OneOf(chars) => write!(f, "OneOf({chars:?})"),
CharacterFilter::Custom(_) => write!(f, "Custom(<function>)"),
}
}
@@ -130,10 +130,10 @@ impl CharacterFilter {
CharacterFilter::Alphabetic => "alphabetic characters (a-z, A-Z)".to_string(),
CharacterFilter::Numeric => "numeric characters (0-9)".to_string(),
CharacterFilter::Alphanumeric => "alphanumeric characters (a-z, A-Z, 0-9)".to_string(),
CharacterFilter::Exact(ch) => format!("exactly '{}'", ch),
CharacterFilter::Exact(ch) => format!("exactly '{ch}'"),
CharacterFilter::OneOf(chars) => {
let char_list: String = chars.iter().collect();
format!("one of: {}", char_list)
format!("one of: {char_list}")
},
CharacterFilter::Custom(_) => "custom filter".to_string(),
}
@@ -207,9 +207,7 @@ impl PatternFilters {
/// Validate entire text against all filters
pub fn validate_text(&self, text: &str) -> Result<(), String> {
for (position, character) in text.char_indices() {
if let Err(error) = self.validate_char_at_position(position, character) {
return Err(error);
}
self.validate_char_at_position(position, character)?
}
Ok(())
}