diff --git a/src/components/commit_details/details.rs b/src/components/commit_details/details.rs index f11cd914..918fccbe 100644 --- a/src/components/commit_details/details.rs +++ b/src/components/commit_details/details.rs @@ -270,10 +270,7 @@ impl DetailsComponent { } } - fn move_scroll_top( - &mut self, - move_type: ScrollType, - ) -> Result { + fn move_scroll_top(&mut self, move_type: ScrollType) -> bool { if self.data.is_some() { let old = self.scroll_top.get(); let width = self.current_size.get().0 as usize; @@ -292,14 +289,14 @@ impl DetailsComponent { }; if new_scroll_top > max { - return Ok(false); + return false; } self.scroll_top.set(new_scroll_top); - return Ok(true); + return true; } - Ok(false) + false } } @@ -396,7 +393,7 @@ impl Component for DetailsComponent { fn event(&mut self, event: Event) -> Result { if self.focused { if let Event::Key(e) = event { - return if e == self.key_config.move_up { + return Ok(if e == self.key_config.move_up { self.move_scroll_top(ScrollType::Up) } else if e == self.key_config.move_down { self.move_scroll_top(ScrollType::Down) @@ -409,8 +406,8 @@ impl Component for DetailsComponent { { self.move_scroll_top(ScrollType::End) } else { - Ok(false) - }; + false + }); } } diff --git a/src/components/diff.rs b/src/components/diff.rs index cf6e3a05..b5be1565 100644 --- a/src/components/diff.rs +++ b/src/components/diff.rs @@ -174,7 +174,7 @@ impl DiffComponent { self.selected_hunk = Self::find_selected_hunk( &diff, self.selection.get_start(), - )?; + ); self.diff = Some(diff); self.scroll_top.set(0); @@ -184,10 +184,7 @@ impl DiffComponent { Ok(()) } - fn move_selection( - &mut self, - move_type: ScrollType, - ) -> Result<()> { + fn move_selection(&mut self, move_type: ScrollType) { if let Some(diff) = &self.diff { let max = diff.lines.saturating_sub(1) as usize; @@ -219,9 +216,8 @@ impl DiffComponent { self.selection = Selection::Single(new_start); self.selected_hunk = - Self::find_selected_hunk(diff, new_start)?; + Self::find_selected_hunk(diff, new_start); } - Ok(()) } fn lines_count(&self) -> usize { @@ -230,20 +226,15 @@ impl DiffComponent { .map_or(0, |diff| diff.lines.saturating_sub(1)) } - fn modify_selection( - &mut self, - direction: Direction, - ) -> Result<()> { + fn modify_selection(&mut self, direction: Direction) { if let Some(diff) = &self.diff { let max = diff.lines.saturating_sub(1); self.selection.modify(direction, max); } - - Ok(()) } - fn copy_selection(&self) -> Result<()> { + fn copy_selection(&self) { if let Some(diff) = &self.diff { let lines_to_copy: Vec<&str> = diff .hunks @@ -273,14 +264,12 @@ impl DiffComponent { ) ); } - - Ok(()) } fn find_selected_hunk( diff: &FileDiff, line_selected: usize, - ) -> Result> { + ) -> Option { let mut line_cursor = 0_usize; for (i, hunk) in diff.hunks.iter().enumerate() { let hunk_len = hunk.lines.len(); @@ -291,20 +280,16 @@ impl DiffComponent { hunk_min <= line_selected && hunk_max > line_selected; if hunk_selected { - return Ok(Some(i)); + return Some(i); } line_cursor += hunk_len; } - Ok(None) + None } - fn get_text( - &self, - width: u16, - height: u16, - ) -> Result> { + fn get_text(&self, width: u16, height: u16) -> Vec { let mut res: Vec = Vec::new(); if let Some(diff) = &self.diff { if diff.hunks.is_empty() { @@ -397,7 +382,7 @@ impl DiffComponent { } } } - Ok(res) + res } fn get_line_to_add<'a>( @@ -509,7 +494,7 @@ impl DiffComponent { .push_back(InternalEvent::Update(NeedsUpdate::ALL)); } - fn reset_hunk(&self) -> Result<()> { + fn reset_hunk(&self) { if let Some(diff) = &self.diff { if let Some(hunk) = self.selected_hunk { let hash = diff.hunks[hunk].header_hash; @@ -522,18 +507,15 @@ impl DiffComponent { ); } } - Ok(()) } - fn reset_untracked(&self) -> Result<()> { + fn reset_untracked(&self) { self.queue.as_ref().borrow_mut().push_back( InternalEvent::ConfirmAction(Action::Reset(ResetItem { path: self.current.path.clone(), is_folder: false, })), ); - - Ok(()) } const fn is_stage(&self) -> bool { @@ -570,7 +552,7 @@ impl DrawableComponent for DiffComponent { self.theme.text(false, false), )])] } else { - self.get_text(r.width, self.current_size.get().1)? + self.get_text(r.width, self.current_size.get().1) }; f.render_widget( @@ -651,28 +633,28 @@ impl Component for DiffComponent { if self.focused { if let Event::Key(e) = ev { return if e == self.key_config.move_down { - self.move_selection(ScrollType::Down)?; + self.move_selection(ScrollType::Down); Ok(true) } else if e == self.key_config.shift_down { - self.modify_selection(Direction::Down)?; + self.modify_selection(Direction::Down); Ok(true) } else if e == self.key_config.shift_up { - self.modify_selection(Direction::Up)?; + self.modify_selection(Direction::Up); Ok(true) } else if e == self.key_config.end { - self.move_selection(ScrollType::End)?; + self.move_selection(ScrollType::End); Ok(true) } else if e == self.key_config.home { - self.move_selection(ScrollType::Home)?; + self.move_selection(ScrollType::Home); Ok(true) } else if e == self.key_config.move_up { - self.move_selection(ScrollType::Up)?; + self.move_selection(ScrollType::Up); Ok(true) } else if e == self.key_config.page_up { - self.move_selection(ScrollType::PageUp)?; + self.move_selection(ScrollType::PageUp); Ok(true) } else if e == self.key_config.page_down { - self.move_selection(ScrollType::PageDown)?; + self.move_selection(ScrollType::PageDown); Ok(true) } else if e == self.key_config.enter && !self.is_immutable @@ -689,14 +671,14 @@ impl Component for DiffComponent { { if let Some(diff) = &self.diff { if diff.untracked { - self.reset_untracked()?; + self.reset_untracked(); } else { - self.reset_hunk()?; + self.reset_hunk(); } } Ok(true) } else if e == self.key_config.copy { - self.copy_selection()?; + self.copy_selection(); Ok(true) } else { Ok(false) diff --git a/src/components/select_branch.rs b/src/components/select_branch.rs index 0995cfde..f65796f8 100644 --- a/src/components/select_branch.rs +++ b/src/components/select_branch.rs @@ -74,7 +74,7 @@ impl DrawableComponent for SelectBranchComponent { &self.theme, area.width, height_in_lines, - )?) + )) .block( Block::default() .title(strings::SELECT_BRANCH_POPUP_MSG) @@ -291,7 +291,7 @@ impl SelectBranchComponent { theme: &SharedTheme, width_available: u16, height: usize, - ) -> Result { + ) -> Text { const COMMIT_HASH_LENGTH: usize = 8; const IS_HEAD_STAR_LENGTH: usize = 3; // "* " const THREE_DOTS_LENGTH: usize = 3; // "..." @@ -376,7 +376,7 @@ impl SelectBranchComponent { ])); } - Ok(Text::from(txt)) + Text::from(txt) } ///