Skip to content

Commit 1ee38a2

Browse files
authored
Merge branch 'master' into feat/checkout_method
2 parents fd5ff21 + 2ced3f9 commit 1ee38a2

File tree

11 files changed

+113
-63
lines changed

11 files changed

+113
-63
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Added
1313
* support choosing checkout branch method when status is not empty [[@fatpandac](https://github.com/fatpandac)] ([#2404](https://github.com/extrawurst/gitui/issues/2404))
14+
* Message tab supports pageUp and pageDown [[@xlai89](https://github.com/xlai89)] ([#2623](https://github.com/extrawurst/gitui/issues/2623))
1415
* Files and status tab support pageUp and pageDown [[@fatpandac](https://github.com/fatpandac)] ([#1951](https://github.com/extrawurst/gitui/issues/1951))
1516
* support loading custom syntax highlighting themes from a file [[@acuteenvy](https://github.com/acuteenvy)] ([#2565](https://github.com/gitui-org/gitui/pull/2565))
1617
* Select syntax highlighting theme out of the defaults from syntect [[@vasilismanol](https://github.com/vasilismanol)] ([#1931](https://github.com/extrawurst/gitui/issues/1931))
@@ -34,6 +35,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3435
* resolve `core.hooksPath` relative to `GIT_WORK_TREE` [[@naseschwarz](https://github.com/naseschwarz)] ([#2571](https://github.com/gitui-org/gitui/issues/2571))
3536
* yanking commit ranges no longer generates incorrect dotted range notations, but lists each individual commit [[@naseschwarz](https://github.com/naseschwarz)] (https://github.com/gitui-org/gitui/issues/2576)
3637
* print slightly nicer errors when failing to create a directory [[@linkmauve](https://github.com/linkmauve)] (https://github.com/gitui-org/gitui/pull/2728)
38+
* When the terminal is insufficient to display all the commands, the cmdbar_bg configuration color does not fully take effect. ([#2347](https://github.com/extrawurst/gitui/issues/2347))
39+
* disable blame and history popup keybinds for untracked files [[@kpbaks](https://github.com/kpbaks)] ([#2489](https://github.com/gitui-org/gitui/pull/2489))
3740

3841
## [0.27.0] - 2024-01-14
3942

Cargo.lock

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ two-face = { version = "0.4.3", default-features = false }
8282
unicode-segmentation = "1.12"
8383
unicode-truncate = "2.0"
8484
unicode-width = "0.2"
85-
which = "7.0"
85+
which = "8.0"
8686

8787
[build-dependencies]
8888
chrono = { version = "0.4", default-features = false, features = ["clock"] }

src/cmdbar.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ enum DrawListEntry {
2020
struct Command {
2121
txt: String,
2222
enabled: bool,
23-
line: usize,
2423
}
2524

2625
/// helper to be used while drawing
@@ -106,7 +105,6 @@ impl CommandBar {
106105
self.draw_list.push(DrawListEntry::Command(Command {
107106
txt: c.text.name.clone(),
108107
enabled: c.enabled,
109-
line: lines.saturating_sub(1) as usize,
110108
}));
111109
}
112110

@@ -157,9 +155,7 @@ impl CommandBar {
157155
DrawListEntry::Command(c) => {
158156
Span::styled(
159157
Cow::from(c.txt.as_str()),
160-
self.theme.commandbar(
161-
c.enabled, c.line,
162-
),
158+
self.theme.commandbar(c.enabled),
163159
)
164160
}
165161
DrawListEntry::LineBreak => {

src/components/commit_details/details.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,18 @@ impl Component for DetailsComponent {
369369
self.key_config.keys.move_down,
370370
) {
371371
self.move_scroll_top(ScrollType::Down).into()
372+
} else if key_match(
373+
e,
374+
self.key_config.keys.page_up,
375+
) {
376+
self.move_scroll_top(ScrollType::PageUp)
377+
.into()
378+
} else if key_match(
379+
e,
380+
self.key_config.keys.page_down,
381+
) {
382+
self.move_scroll_top(ScrollType::PageDown)
383+
.into()
372384
} else if key_match(e, self.key_config.keys.home)
373385
|| key_match(e, self.key_config.keys.shift_up)
374386
{

src/components/status_tree.rs

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,25 @@ impl StatusTreeComponent {
308308
}
309309
}
310310
}
311+
312+
fn open_history(&mut self) {
313+
match self.selection_file() {
314+
Some(status_item)
315+
if !matches!(
316+
status_item.status,
317+
StatusItemType::New
318+
) =>
319+
{
320+
self.hide();
321+
self.queue.push(InternalEvent::OpenPopup(
322+
StackablePopupOpen::FileRevlog(FileRevOpen::new(
323+
status_item.path,
324+
)),
325+
));
326+
}
327+
_ => {}
328+
}
329+
}
311330
}
312331

313332
/// Used for drawing the `FileTreeComponent`
@@ -395,20 +414,27 @@ impl Component for StatusTreeComponent {
395414
out: &mut Vec<CommandInfo>,
396415
force_all: bool,
397416
) -> CommandBlocking {
417+
let available = self.focused || force_all;
418+
let selection = self.selection_file();
419+
let selected_is_file = selection.is_some();
420+
let tracked = selection.is_some_and(|s| {
421+
!matches!(s.status, StatusItemType::New)
422+
});
423+
398424
out.push(
399425
CommandInfo::new(
400426
strings::commands::navigate_tree(&self.key_config),
401427
!self.is_empty(),
402-
self.focused || force_all,
428+
available,
403429
)
404430
.order(order::NAV),
405431
);
406432

407433
out.push(
408434
CommandInfo::new(
409435
strings::commands::blame_file(&self.key_config),
410-
self.selection_file().is_some(),
411-
self.focused || force_all,
436+
selected_is_file && tracked,
437+
available,
412438
)
413439
.order(order::RARE_ACTION),
414440
);
@@ -418,62 +444,67 @@ impl Component for StatusTreeComponent {
418444
strings::commands::open_file_history(
419445
&self.key_config,
420446
),
421-
self.selection_file().is_some(),
422-
self.focused || force_all,
447+
selected_is_file && tracked,
448+
available,
423449
)
424450
.order(order::RARE_ACTION),
425451
);
426452

427453
out.push(
428454
CommandInfo::new(
429455
strings::commands::edit_item(&self.key_config),
430-
self.selection_file().is_some(),
431-
self.focused || force_all,
456+
selected_is_file,
457+
available,
432458
)
433459
.order(order::RARE_ACTION),
434460
);
435461

436462
out.push(
437463
CommandInfo::new(
438464
strings::commands::copy_path(&self.key_config),
439-
self.selection_file().is_some(),
440-
self.focused || force_all,
465+
selected_is_file,
466+
available,
441467
)
442468
.order(order::RARE_ACTION),
443469
);
444470

445471
CommandBlocking::PassingOn
446472
}
447473

474+
#[expect(clippy::cognitive_complexity)]
448475
fn event(&mut self, ev: &Event) -> Result<EventState> {
449476
if self.focused {
450477
if let Event::Key(e) = ev {
451478
return if key_match(e, self.key_config.keys.blame) {
452-
if let Some(status_item) = self.selection_file() {
453-
self.hide();
454-
self.queue.push(InternalEvent::OpenPopup(
455-
StackablePopupOpen::BlameFile(
456-
BlameFileOpen {
457-
file_path: status_item.path,
458-
commit_id: self.revision,
459-
selection: None,
460-
},
461-
),
462-
));
479+
match self.selection_file() {
480+
Some(status_item)
481+
if !matches!(
482+
status_item.status,
483+
StatusItemType::New
484+
) =>
485+
{
486+
self.hide();
487+
self.queue.push(
488+
InternalEvent::OpenPopup(
489+
StackablePopupOpen::BlameFile(
490+
BlameFileOpen {
491+
file_path: status_item
492+
.path,
493+
commit_id: self.revision,
494+
selection: None,
495+
},
496+
),
497+
),
498+
);
499+
}
500+
_ => {}
463501
}
464502
Ok(EventState::Consumed)
465503
} else if key_match(
466504
e,
467505
self.key_config.keys.file_history,
468506
) {
469-
if let Some(status_item) = self.selection_file() {
470-
self.hide();
471-
self.queue.push(InternalEvent::OpenPopup(
472-
StackablePopupOpen::FileRevlog(
473-
FileRevOpen::new(status_item.path),
474-
),
475-
));
476-
}
507+
self.open_history();
477508
Ok(EventState::Consumed)
478509
} else if key_match(e, self.key_config.keys.edit_file)
479510
{

src/components/utils/scroll_vertical.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ use std::cell::Cell;
88
pub struct VerticalScroll {
99
top: Cell<usize>,
1010
max_top: Cell<usize>,
11+
visual_height: Cell<usize>,
1112
}
1213

1314
impl VerticalScroll {
1415
pub const fn new() -> Self {
1516
Self {
1617
top: Cell::new(0),
1718
max_top: Cell::new(0),
19+
visual_height: Cell::new(0),
1820
}
1921
}
2022

@@ -33,9 +35,14 @@ impl VerticalScroll {
3335
let new_scroll_top = match move_type {
3436
ScrollType::Down => old.saturating_add(1),
3537
ScrollType::Up => old.saturating_sub(1),
38+
ScrollType::PageDown => old
39+
.saturating_sub(1)
40+
.saturating_add(self.visual_height.get()),
41+
ScrollType::PageUp => old
42+
.saturating_add(1)
43+
.saturating_sub(self.visual_height.get()),
3644
ScrollType::Home => 0,
3745
ScrollType::End => max,
38-
_ => old,
3946
};
4047

4148
let new_scroll_top = new_scroll_top.clamp(0, max);
@@ -81,6 +88,8 @@ impl VerticalScroll {
8188
selection_max: usize,
8289
visual_height: usize,
8390
) -> usize {
91+
self.visual_height.set(visual_height);
92+
8493
let new_top = calc_scroll_top(
8594
self.get_top(),
8695
visual_height,
@@ -192,4 +201,26 @@ mod tests {
192201
scroll.move_area_to_visible(visual_height, 0, 2);
193202
assert_eq!(scroll.get_top(), 0);
194203
}
204+
205+
#[test]
206+
fn test_scroll_with_pageup_pagedown() {
207+
let scroll = VerticalScroll::new();
208+
scroll.max_top.set(10);
209+
scroll.visual_height.set(8);
210+
211+
assert!(scroll.move_top(ScrollType::End));
212+
assert_eq!(scroll.get_top(), 10);
213+
214+
assert!(!scroll.move_top(ScrollType::PageDown));
215+
assert_eq!(scroll.get_top(), 10);
216+
217+
assert!(scroll.move_top(ScrollType::PageUp));
218+
assert_eq!(scroll.get_top(), 3);
219+
220+
assert!(scroll.move_top(ScrollType::PageUp));
221+
assert_eq!(scroll.get_top(), 0);
222+
223+
assert!(!scroll.move_top(ScrollType::PageUp));
224+
assert_eq!(scroll.get_top(), 0);
225+
}
195226
}

src/keys/key_config.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ impl KeyConfig {
4040
Ok(Self { keys, symbols })
4141
}
4242

43-
#[expect(
44-
clippy::missing_const_for_fn,
45-
reason = "as of 1.86.0 clippy wants this to be const even though that breaks"
46-
)]
4743
fn get_key_symbol(&self, k: KeyCode) -> &str {
4844
match k {
4945
KeyCode::Enter => &self.symbols.enter,
@@ -110,10 +106,6 @@ impl KeyConfig {
110106
}
111107
}
112108

113-
#[expect(
114-
clippy::missing_const_for_fn,
115-
reason = "as of 1.86.0 clippy wants this to be const even though that breaks"
116-
)]
117109
fn get_modifier_hint(&self, modifier: KeyModifiers) -> &str {
118110
match modifier {
119111
KeyModifiers::CONTROL => &self.symbols.control,

src/popups/blame_file.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ struct SyntaxFileBlame {
4141
}
4242

4343
impl SyntaxFileBlame {
44-
#[expect(
45-
clippy::missing_const_for_fn,
46-
reason = "as of 1.86.0 clippy wants this to be const even though that breaks"
47-
)]
4844
fn path(&self) -> &str {
4945
&self.file_blame.path
5046
}

src/ui/style.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub struct Theme {
1818
selection_fg: Color,
1919
use_selection_fg: bool,
2020
cmdbar_bg: Color,
21-
cmdbar_extra_lines_bg: Color,
2221
disabled_fg: Color,
2322
diff_line_add: Color,
2423
diff_line_delete: Color,
@@ -211,17 +210,13 @@ impl Theme {
211210
self.line_break.clone()
212211
}
213212

214-
pub fn commandbar(&self, enabled: bool, line: usize) -> Style {
213+
pub fn commandbar(&self, enabled: bool) -> Style {
215214
if enabled {
216215
Style::default().fg(self.command_fg)
217216
} else {
218217
Style::default().fg(self.disabled_fg)
219218
}
220-
.bg(if line == 0 {
221-
self.cmdbar_bg
222-
} else {
223-
self.cmdbar_extra_lines_bg
224-
})
219+
.bg(self.cmdbar_bg)
225220
}
226221

227222
pub fn commit_hash(&self, selected: bool) -> Style {
@@ -347,7 +342,6 @@ impl Default for Theme {
347342
selection_fg: Color::White,
348343
use_selection_fg: true,
349344
cmdbar_bg: Color::Blue,
350-
cmdbar_extra_lines_bg: Color::Blue,
351345
disabled_fg: Color::DarkGray,
352346
diff_line_add: Color::Green,
353347
diff_line_delete: Color::Red,

0 commit comments

Comments
 (0)