Skip to content

Commit 337ebb6

Browse files
author
Stephan Dilly
committed
1 parent 7174817 commit 337ebb6

File tree

3 files changed

+34
-55
lines changed

3 files changed

+34
-55
lines changed

src/components/commit_details/details.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,7 @@ impl DetailsComponent {
270270
}
271271
}
272272

273-
fn move_scroll_top(
274-
&mut self,
275-
move_type: ScrollType,
276-
) -> Result<bool> {
273+
fn move_scroll_top(&mut self, move_type: ScrollType) -> bool {
277274
if self.data.is_some() {
278275
let old = self.scroll_top.get();
279276
let width = self.current_size.get().0 as usize;
@@ -292,14 +289,14 @@ impl DetailsComponent {
292289
};
293290

294291
if new_scroll_top > max {
295-
return Ok(false);
292+
return false;
296293
}
297294

298295
self.scroll_top.set(new_scroll_top);
299296

300-
return Ok(true);
297+
return true;
301298
}
302-
Ok(false)
299+
false
303300
}
304301
}
305302

@@ -396,7 +393,7 @@ impl Component for DetailsComponent {
396393
fn event(&mut self, event: Event) -> Result<bool> {
397394
if self.focused {
398395
if let Event::Key(e) = event {
399-
return if e == self.key_config.move_up {
396+
return Ok(if e == self.key_config.move_up {
400397
self.move_scroll_top(ScrollType::Up)
401398
} else if e == self.key_config.move_down {
402399
self.move_scroll_top(ScrollType::Down)
@@ -409,8 +406,8 @@ impl Component for DetailsComponent {
409406
{
410407
self.move_scroll_top(ScrollType::End)
411408
} else {
412-
Ok(false)
413-
};
409+
false
410+
});
414411
}
415412
}
416413

src/components/diff.rs

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl DiffComponent {
174174
self.selected_hunk = Self::find_selected_hunk(
175175
&diff,
176176
self.selection.get_start(),
177-
)?;
177+
);
178178

179179
self.diff = Some(diff);
180180
self.scroll_top.set(0);
@@ -184,10 +184,7 @@ impl DiffComponent {
184184
Ok(())
185185
}
186186

187-
fn move_selection(
188-
&mut self,
189-
move_type: ScrollType,
190-
) -> Result<()> {
187+
fn move_selection(&mut self, move_type: ScrollType) {
191188
if let Some(diff) = &self.diff {
192189
let max = diff.lines.saturating_sub(1) as usize;
193190

@@ -219,9 +216,8 @@ impl DiffComponent {
219216
self.selection = Selection::Single(new_start);
220217

221218
self.selected_hunk =
222-
Self::find_selected_hunk(diff, new_start)?;
219+
Self::find_selected_hunk(diff, new_start);
223220
}
224-
Ok(())
225221
}
226222

227223
fn lines_count(&self) -> usize {
@@ -230,20 +226,15 @@ impl DiffComponent {
230226
.map_or(0, |diff| diff.lines.saturating_sub(1))
231227
}
232228

233-
fn modify_selection(
234-
&mut self,
235-
direction: Direction,
236-
) -> Result<()> {
229+
fn modify_selection(&mut self, direction: Direction) {
237230
if let Some(diff) = &self.diff {
238231
let max = diff.lines.saturating_sub(1);
239232

240233
self.selection.modify(direction, max);
241234
}
242-
243-
Ok(())
244235
}
245236

246-
fn copy_selection(&self) -> Result<()> {
237+
fn copy_selection(&self) {
247238
if let Some(diff) = &self.diff {
248239
let lines_to_copy: Vec<&str> = diff
249240
.hunks
@@ -273,14 +264,12 @@ impl DiffComponent {
273264
)
274265
);
275266
}
276-
277-
Ok(())
278267
}
279268

280269
fn find_selected_hunk(
281270
diff: &FileDiff,
282271
line_selected: usize,
283-
) -> Result<Option<usize>> {
272+
) -> Option<usize> {
284273
let mut line_cursor = 0_usize;
285274
for (i, hunk) in diff.hunks.iter().enumerate() {
286275
let hunk_len = hunk.lines.len();
@@ -291,20 +280,16 @@ impl DiffComponent {
291280
hunk_min <= line_selected && hunk_max > line_selected;
292281

293282
if hunk_selected {
294-
return Ok(Some(i));
283+
return Some(i);
295284
}
296285

297286
line_cursor += hunk_len;
298287
}
299288

300-
Ok(None)
289+
None
301290
}
302291

303-
fn get_text(
304-
&self,
305-
width: u16,
306-
height: u16,
307-
) -> Result<Vec<Spans>> {
292+
fn get_text(&self, width: u16, height: u16) -> Vec<Spans> {
308293
let mut res: Vec<Spans> = Vec::new();
309294
if let Some(diff) = &self.diff {
310295
if diff.hunks.is_empty() {
@@ -397,7 +382,7 @@ impl DiffComponent {
397382
}
398383
}
399384
}
400-
Ok(res)
385+
res
401386
}
402387

403388
fn get_line_to_add<'a>(
@@ -509,7 +494,7 @@ impl DiffComponent {
509494
.push_back(InternalEvent::Update(NeedsUpdate::ALL));
510495
}
511496

512-
fn reset_hunk(&self) -> Result<()> {
497+
fn reset_hunk(&self) {
513498
if let Some(diff) = &self.diff {
514499
if let Some(hunk) = self.selected_hunk {
515500
let hash = diff.hunks[hunk].header_hash;
@@ -522,18 +507,15 @@ impl DiffComponent {
522507
);
523508
}
524509
}
525-
Ok(())
526510
}
527511

528-
fn reset_untracked(&self) -> Result<()> {
512+
fn reset_untracked(&self) {
529513
self.queue.as_ref().borrow_mut().push_back(
530514
InternalEvent::ConfirmAction(Action::Reset(ResetItem {
531515
path: self.current.path.clone(),
532516
is_folder: false,
533517
})),
534518
);
535-
536-
Ok(())
537519
}
538520

539521
const fn is_stage(&self) -> bool {
@@ -570,7 +552,7 @@ impl DrawableComponent for DiffComponent {
570552
self.theme.text(false, false),
571553
)])]
572554
} else {
573-
self.get_text(r.width, self.current_size.get().1)?
555+
self.get_text(r.width, self.current_size.get().1)
574556
};
575557

576558
f.render_widget(
@@ -651,28 +633,28 @@ impl Component for DiffComponent {
651633
if self.focused {
652634
if let Event::Key(e) = ev {
653635
return if e == self.key_config.move_down {
654-
self.move_selection(ScrollType::Down)?;
636+
self.move_selection(ScrollType::Down);
655637
Ok(true)
656638
} else if e == self.key_config.shift_down {
657-
self.modify_selection(Direction::Down)?;
639+
self.modify_selection(Direction::Down);
658640
Ok(true)
659641
} else if e == self.key_config.shift_up {
660-
self.modify_selection(Direction::Up)?;
642+
self.modify_selection(Direction::Up);
661643
Ok(true)
662644
} else if e == self.key_config.end {
663-
self.move_selection(ScrollType::End)?;
645+
self.move_selection(ScrollType::End);
664646
Ok(true)
665647
} else if e == self.key_config.home {
666-
self.move_selection(ScrollType::Home)?;
648+
self.move_selection(ScrollType::Home);
667649
Ok(true)
668650
} else if e == self.key_config.move_up {
669-
self.move_selection(ScrollType::Up)?;
651+
self.move_selection(ScrollType::Up);
670652
Ok(true)
671653
} else if e == self.key_config.page_up {
672-
self.move_selection(ScrollType::PageUp)?;
654+
self.move_selection(ScrollType::PageUp);
673655
Ok(true)
674656
} else if e == self.key_config.page_down {
675-
self.move_selection(ScrollType::PageDown)?;
657+
self.move_selection(ScrollType::PageDown);
676658
Ok(true)
677659
} else if e == self.key_config.enter
678660
&& !self.is_immutable
@@ -689,14 +671,14 @@ impl Component for DiffComponent {
689671
{
690672
if let Some(diff) = &self.diff {
691673
if diff.untracked {
692-
self.reset_untracked()?;
674+
self.reset_untracked();
693675
} else {
694-
self.reset_hunk()?;
676+
self.reset_hunk();
695677
}
696678
}
697679
Ok(true)
698680
} else if e == self.key_config.copy {
699-
self.copy_selection()?;
681+
self.copy_selection();
700682
Ok(true)
701683
} else {
702684
Ok(false)

src/components/select_branch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl DrawableComponent for SelectBranchComponent {
7474
&self.theme,
7575
area.width,
7676
height_in_lines,
77-
)?)
77+
))
7878
.block(
7979
Block::default()
8080
.title(strings::SELECT_BRANCH_POPUP_MSG)
@@ -291,7 +291,7 @@ impl SelectBranchComponent {
291291
theme: &SharedTheme,
292292
width_available: u16,
293293
height: usize,
294-
) -> Result<Text> {
294+
) -> Text {
295295
const COMMIT_HASH_LENGTH: usize = 8;
296296
const IS_HEAD_STAR_LENGTH: usize = 3; // "* "
297297
const THREE_DOTS_LENGTH: usize = 3; // "..."
@@ -376,7 +376,7 @@ impl SelectBranchComponent {
376376
]));
377377
}
378378

379-
Ok(Text::from(txt))
379+
Text::from(txt)
380380
}
381381

382382
///

0 commit comments

Comments
 (0)