mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-23 20:52:54 +03:00
fix new https://rust-lang.github.io/rust-clippy/master/#unnecessary_wraps clippy warnigns in nightly
This commit is contained in:
parent
7174817777
commit
337ebb6656
@ -270,10 +270,7 @@ impl DetailsComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_scroll_top(
|
fn move_scroll_top(&mut self, move_type: ScrollType) -> bool {
|
||||||
&mut self,
|
|
||||||
move_type: ScrollType,
|
|
||||||
) -> Result<bool> {
|
|
||||||
if self.data.is_some() {
|
if self.data.is_some() {
|
||||||
let old = self.scroll_top.get();
|
let old = self.scroll_top.get();
|
||||||
let width = self.current_size.get().0 as usize;
|
let width = self.current_size.get().0 as usize;
|
||||||
@ -292,14 +289,14 @@ impl DetailsComponent {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if new_scroll_top > max {
|
if new_scroll_top > max {
|
||||||
return Ok(false);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.scroll_top.set(new_scroll_top);
|
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<bool> {
|
fn event(&mut self, event: Event) -> Result<bool> {
|
||||||
if self.focused {
|
if self.focused {
|
||||||
if let Event::Key(e) = event {
|
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)
|
self.move_scroll_top(ScrollType::Up)
|
||||||
} else if e == self.key_config.move_down {
|
} else if e == self.key_config.move_down {
|
||||||
self.move_scroll_top(ScrollType::Down)
|
self.move_scroll_top(ScrollType::Down)
|
||||||
@ -409,8 +406,8 @@ impl Component for DetailsComponent {
|
|||||||
{
|
{
|
||||||
self.move_scroll_top(ScrollType::End)
|
self.move_scroll_top(ScrollType::End)
|
||||||
} else {
|
} else {
|
||||||
Ok(false)
|
false
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ impl DiffComponent {
|
|||||||
self.selected_hunk = Self::find_selected_hunk(
|
self.selected_hunk = Self::find_selected_hunk(
|
||||||
&diff,
|
&diff,
|
||||||
self.selection.get_start(),
|
self.selection.get_start(),
|
||||||
)?;
|
);
|
||||||
|
|
||||||
self.diff = Some(diff);
|
self.diff = Some(diff);
|
||||||
self.scroll_top.set(0);
|
self.scroll_top.set(0);
|
||||||
@ -184,10 +184,7 @@ impl DiffComponent {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_selection(
|
fn move_selection(&mut self, move_type: ScrollType) {
|
||||||
&mut self,
|
|
||||||
move_type: ScrollType,
|
|
||||||
) -> Result<()> {
|
|
||||||
if let Some(diff) = &self.diff {
|
if let Some(diff) = &self.diff {
|
||||||
let max = diff.lines.saturating_sub(1) as usize;
|
let max = diff.lines.saturating_sub(1) as usize;
|
||||||
|
|
||||||
@ -219,9 +216,8 @@ impl DiffComponent {
|
|||||||
self.selection = Selection::Single(new_start);
|
self.selection = Selection::Single(new_start);
|
||||||
|
|
||||||
self.selected_hunk =
|
self.selected_hunk =
|
||||||
Self::find_selected_hunk(diff, new_start)?;
|
Self::find_selected_hunk(diff, new_start);
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lines_count(&self) -> usize {
|
fn lines_count(&self) -> usize {
|
||||||
@ -230,20 +226,15 @@ impl DiffComponent {
|
|||||||
.map_or(0, |diff| diff.lines.saturating_sub(1))
|
.map_or(0, |diff| diff.lines.saturating_sub(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn modify_selection(
|
fn modify_selection(&mut self, direction: Direction) {
|
||||||
&mut self,
|
|
||||||
direction: Direction,
|
|
||||||
) -> Result<()> {
|
|
||||||
if let Some(diff) = &self.diff {
|
if let Some(diff) = &self.diff {
|
||||||
let max = diff.lines.saturating_sub(1);
|
let max = diff.lines.saturating_sub(1);
|
||||||
|
|
||||||
self.selection.modify(direction, max);
|
self.selection.modify(direction, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_selection(&self) -> Result<()> {
|
fn copy_selection(&self) {
|
||||||
if let Some(diff) = &self.diff {
|
if let Some(diff) = &self.diff {
|
||||||
let lines_to_copy: Vec<&str> = diff
|
let lines_to_copy: Vec<&str> = diff
|
||||||
.hunks
|
.hunks
|
||||||
@ -273,14 +264,12 @@ impl DiffComponent {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_selected_hunk(
|
fn find_selected_hunk(
|
||||||
diff: &FileDiff,
|
diff: &FileDiff,
|
||||||
line_selected: usize,
|
line_selected: usize,
|
||||||
) -> Result<Option<usize>> {
|
) -> Option<usize> {
|
||||||
let mut line_cursor = 0_usize;
|
let mut line_cursor = 0_usize;
|
||||||
for (i, hunk) in diff.hunks.iter().enumerate() {
|
for (i, hunk) in diff.hunks.iter().enumerate() {
|
||||||
let hunk_len = hunk.lines.len();
|
let hunk_len = hunk.lines.len();
|
||||||
@ -291,20 +280,16 @@ impl DiffComponent {
|
|||||||
hunk_min <= line_selected && hunk_max > line_selected;
|
hunk_min <= line_selected && hunk_max > line_selected;
|
||||||
|
|
||||||
if hunk_selected {
|
if hunk_selected {
|
||||||
return Ok(Some(i));
|
return Some(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
line_cursor += hunk_len;
|
line_cursor += hunk_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(None)
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_text(
|
fn get_text(&self, width: u16, height: u16) -> Vec<Spans> {
|
||||||
&self,
|
|
||||||
width: u16,
|
|
||||||
height: u16,
|
|
||||||
) -> Result<Vec<Spans>> {
|
|
||||||
let mut res: Vec<Spans> = Vec::new();
|
let mut res: Vec<Spans> = Vec::new();
|
||||||
if let Some(diff) = &self.diff {
|
if let Some(diff) = &self.diff {
|
||||||
if diff.hunks.is_empty() {
|
if diff.hunks.is_empty() {
|
||||||
@ -397,7 +382,7 @@ impl DiffComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(res)
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_line_to_add<'a>(
|
fn get_line_to_add<'a>(
|
||||||
@ -509,7 +494,7 @@ impl DiffComponent {
|
|||||||
.push_back(InternalEvent::Update(NeedsUpdate::ALL));
|
.push_back(InternalEvent::Update(NeedsUpdate::ALL));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset_hunk(&self) -> Result<()> {
|
fn reset_hunk(&self) {
|
||||||
if let Some(diff) = &self.diff {
|
if let Some(diff) = &self.diff {
|
||||||
if let Some(hunk) = self.selected_hunk {
|
if let Some(hunk) = self.selected_hunk {
|
||||||
let hash = diff.hunks[hunk].header_hash;
|
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(
|
self.queue.as_ref().borrow_mut().push_back(
|
||||||
InternalEvent::ConfirmAction(Action::Reset(ResetItem {
|
InternalEvent::ConfirmAction(Action::Reset(ResetItem {
|
||||||
path: self.current.path.clone(),
|
path: self.current.path.clone(),
|
||||||
is_folder: false,
|
is_folder: false,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn is_stage(&self) -> bool {
|
const fn is_stage(&self) -> bool {
|
||||||
@ -570,7 +552,7 @@ impl DrawableComponent for DiffComponent {
|
|||||||
self.theme.text(false, false),
|
self.theme.text(false, false),
|
||||||
)])]
|
)])]
|
||||||
} else {
|
} else {
|
||||||
self.get_text(r.width, self.current_size.get().1)?
|
self.get_text(r.width, self.current_size.get().1)
|
||||||
};
|
};
|
||||||
|
|
||||||
f.render_widget(
|
f.render_widget(
|
||||||
@ -651,28 +633,28 @@ impl Component for DiffComponent {
|
|||||||
if self.focused {
|
if self.focused {
|
||||||
if let Event::Key(e) = ev {
|
if let Event::Key(e) = ev {
|
||||||
return if e == self.key_config.move_down {
|
return if e == self.key_config.move_down {
|
||||||
self.move_selection(ScrollType::Down)?;
|
self.move_selection(ScrollType::Down);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else if e == self.key_config.shift_down {
|
} else if e == self.key_config.shift_down {
|
||||||
self.modify_selection(Direction::Down)?;
|
self.modify_selection(Direction::Down);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else if e == self.key_config.shift_up {
|
} else if e == self.key_config.shift_up {
|
||||||
self.modify_selection(Direction::Up)?;
|
self.modify_selection(Direction::Up);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else if e == self.key_config.end {
|
} else if e == self.key_config.end {
|
||||||
self.move_selection(ScrollType::End)?;
|
self.move_selection(ScrollType::End);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else if e == self.key_config.home {
|
} else if e == self.key_config.home {
|
||||||
self.move_selection(ScrollType::Home)?;
|
self.move_selection(ScrollType::Home);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else if e == self.key_config.move_up {
|
} else if e == self.key_config.move_up {
|
||||||
self.move_selection(ScrollType::Up)?;
|
self.move_selection(ScrollType::Up);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else if e == self.key_config.page_up {
|
} else if e == self.key_config.page_up {
|
||||||
self.move_selection(ScrollType::PageUp)?;
|
self.move_selection(ScrollType::PageUp);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else if e == self.key_config.page_down {
|
} else if e == self.key_config.page_down {
|
||||||
self.move_selection(ScrollType::PageDown)?;
|
self.move_selection(ScrollType::PageDown);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else if e == self.key_config.enter
|
} else if e == self.key_config.enter
|
||||||
&& !self.is_immutable
|
&& !self.is_immutable
|
||||||
@ -689,14 +671,14 @@ impl Component for DiffComponent {
|
|||||||
{
|
{
|
||||||
if let Some(diff) = &self.diff {
|
if let Some(diff) = &self.diff {
|
||||||
if diff.untracked {
|
if diff.untracked {
|
||||||
self.reset_untracked()?;
|
self.reset_untracked();
|
||||||
} else {
|
} else {
|
||||||
self.reset_hunk()?;
|
self.reset_hunk();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else if e == self.key_config.copy {
|
} else if e == self.key_config.copy {
|
||||||
self.copy_selection()?;
|
self.copy_selection();
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else {
|
} else {
|
||||||
Ok(false)
|
Ok(false)
|
||||||
|
@ -74,7 +74,7 @@ impl DrawableComponent for SelectBranchComponent {
|
|||||||
&self.theme,
|
&self.theme,
|
||||||
area.width,
|
area.width,
|
||||||
height_in_lines,
|
height_in_lines,
|
||||||
)?)
|
))
|
||||||
.block(
|
.block(
|
||||||
Block::default()
|
Block::default()
|
||||||
.title(strings::SELECT_BRANCH_POPUP_MSG)
|
.title(strings::SELECT_BRANCH_POPUP_MSG)
|
||||||
@ -291,7 +291,7 @@ impl SelectBranchComponent {
|
|||||||
theme: &SharedTheme,
|
theme: &SharedTheme,
|
||||||
width_available: u16,
|
width_available: u16,
|
||||||
height: usize,
|
height: usize,
|
||||||
) -> Result<Text> {
|
) -> Text {
|
||||||
const COMMIT_HASH_LENGTH: usize = 8;
|
const COMMIT_HASH_LENGTH: usize = 8;
|
||||||
const IS_HEAD_STAR_LENGTH: usize = 3; // "* "
|
const IS_HEAD_STAR_LENGTH: usize = 3; // "* "
|
||||||
const THREE_DOTS_LENGTH: usize = 3; // "..."
|
const THREE_DOTS_LENGTH: usize = 3; // "..."
|
||||||
@ -376,7 +376,7 @@ impl SelectBranchComponent {
|
|||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Text::from(txt))
|
Text::from(txt)
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user