mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 08:58:21 +00:00
chore(checklist): make check + fmt + tests + changelog
This commit is contained in:
parent
a6354dd204
commit
6e68424ab1
10 changed files with 132 additions and 75 deletions
|
|
@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## Unreleased
|
||||
|
||||
### Added
|
||||
* vim-like navigation: `j`/`k` for up/down, `l` to open preview
|
||||
|
||||
### Changed
|
||||
* use [tombi](https://github.com/tombi-toml/tombi) for all toml file formatting
|
||||
* open the external editor from the status diff view [[@WaterWhisperer](https://github.com/WaterWhisperer)] ([#2805](https://github.com/gitui-org/gitui/issues/2805))
|
||||
|
|
|
|||
|
|
@ -361,37 +361,26 @@ impl Component for DetailsComponent {
|
|||
fn event(&mut self, event: &Event) -> Result<EventState> {
|
||||
if self.focused {
|
||||
if let Event::Key(e) = event {
|
||||
return Ok(
|
||||
if self.key_config.is_nav_up(e) {
|
||||
self.move_scroll_top(ScrollType::Up).into()
|
||||
} else if self.key_config.is_nav_down(e) {
|
||||
self.move_scroll_top(ScrollType::Down).into()
|
||||
} else if key_match(
|
||||
e,
|
||||
self.key_config.keys.page_up,
|
||||
) {
|
||||
self.move_scroll_top(ScrollType::PageUp)
|
||||
.into()
|
||||
} else if key_match(
|
||||
e,
|
||||
self.key_config.keys.page_down,
|
||||
) {
|
||||
self.move_scroll_top(ScrollType::PageDown)
|
||||
.into()
|
||||
} else if key_match(e, self.key_config.keys.home)
|
||||
|| key_match(e, self.key_config.keys.shift_up)
|
||||
{
|
||||
self.move_scroll_top(ScrollType::Home).into()
|
||||
} else if key_match(e, self.key_config.keys.end)
|
||||
|| key_match(
|
||||
e,
|
||||
self.key_config.keys.shift_down,
|
||||
) {
|
||||
self.move_scroll_top(ScrollType::End).into()
|
||||
} else {
|
||||
EventState::NotConsumed
|
||||
},
|
||||
);
|
||||
return Ok(if self.key_config.is_nav_up(e) {
|
||||
self.move_scroll_top(ScrollType::Up).into()
|
||||
} else if self.key_config.is_nav_down(e) {
|
||||
self.move_scroll_top(ScrollType::Down).into()
|
||||
} else if key_match(e, self.key_config.keys.page_up) {
|
||||
self.move_scroll_top(ScrollType::PageUp).into()
|
||||
} else if key_match(e, self.key_config.keys.page_down)
|
||||
{
|
||||
self.move_scroll_top(ScrollType::PageDown).into()
|
||||
} else if key_match(e, self.key_config.keys.home)
|
||||
|| key_match(e, self.key_config.keys.shift_up)
|
||||
{
|
||||
self.move_scroll_top(ScrollType::Home).into()
|
||||
} else if key_match(e, self.key_config.keys.end)
|
||||
|| key_match(e, self.key_config.keys.shift_down)
|
||||
{
|
||||
self.move_scroll_top(ScrollType::End).into()
|
||||
} else {
|
||||
EventState::NotConsumed
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,7 @@ use super::{
|
|||
Component, DrawableComponent, EventState, StatusTreeComponent,
|
||||
};
|
||||
use crate::{
|
||||
accessors,
|
||||
app::Environment,
|
||||
keys::SharedKeyConfig,
|
||||
strings,
|
||||
accessors, app::Environment, keys::SharedKeyConfig, strings,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use asyncgit::{
|
||||
|
|
|
|||
|
|
@ -830,41 +830,37 @@ impl DrawableComponent for CommitList {
|
|||
impl Component for CommitList {
|
||||
fn event(&mut self, ev: &Event) -> Result<EventState> {
|
||||
if let Event::Key(k) = ev {
|
||||
let selection_changed =
|
||||
if self.key_config.is_nav_up(k) {
|
||||
self.move_selection(ScrollType::Up)?
|
||||
} else if self.key_config.is_nav_down(k) {
|
||||
self.move_selection(ScrollType::Down)?
|
||||
} else if key_match(k, self.key_config.keys.shift_up)
|
||||
|| key_match(k, self.key_config.keys.home)
|
||||
{
|
||||
self.move_selection(ScrollType::Home)?
|
||||
} else if key_match(
|
||||
k,
|
||||
self.key_config.keys.shift_down,
|
||||
) || key_match(k, self.key_config.keys.end)
|
||||
{
|
||||
self.move_selection(ScrollType::End)?
|
||||
} else if key_match(k, self.key_config.keys.page_up) {
|
||||
self.move_selection(ScrollType::PageUp)?
|
||||
} else if key_match(k, self.key_config.keys.page_down)
|
||||
{
|
||||
self.move_selection(ScrollType::PageDown)?
|
||||
} else if key_match(
|
||||
k,
|
||||
self.key_config.keys.log_mark_commit,
|
||||
) {
|
||||
self.mark();
|
||||
true
|
||||
} else if key_match(
|
||||
k,
|
||||
self.key_config.keys.log_checkout_commit,
|
||||
) {
|
||||
self.checkout();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
let selection_changed = if self.key_config.is_nav_up(k) {
|
||||
self.move_selection(ScrollType::Up)?
|
||||
} else if self.key_config.is_nav_down(k) {
|
||||
self.move_selection(ScrollType::Down)?
|
||||
} else if key_match(k, self.key_config.keys.shift_up)
|
||||
|| key_match(k, self.key_config.keys.home)
|
||||
{
|
||||
self.move_selection(ScrollType::Home)?
|
||||
} else if key_match(k, self.key_config.keys.shift_down)
|
||||
|| key_match(k, self.key_config.keys.end)
|
||||
{
|
||||
self.move_selection(ScrollType::End)?
|
||||
} else if key_match(k, self.key_config.keys.page_up) {
|
||||
self.move_selection(ScrollType::PageUp)?
|
||||
} else if key_match(k, self.key_config.keys.page_down) {
|
||||
self.move_selection(ScrollType::PageDown)?
|
||||
} else if key_match(
|
||||
k,
|
||||
self.key_config.keys.log_mark_commit,
|
||||
) {
|
||||
self.mark();
|
||||
true
|
||||
} else if key_match(
|
||||
k,
|
||||
self.key_config.keys.log_checkout_commit,
|
||||
) {
|
||||
self.checkout();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
return Ok(selection_changed.into());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -864,7 +864,8 @@ impl Component for DiffComponent {
|
|||
self.horizontal_scroll
|
||||
.move_right(HorizontalScrollType::Right);
|
||||
Ok(EventState::Consumed)
|
||||
} else if key_match(e, self.key_config.keys.move_left) {
|
||||
} else if key_match(e, self.key_config.keys.move_left)
|
||||
{
|
||||
self.horizontal_scroll
|
||||
.move_right(HorizontalScrollType::Left);
|
||||
Ok(EventState::Consumed)
|
||||
|
|
|
|||
|
|
@ -543,7 +543,8 @@ impl Component for StatusTreeComponent {
|
|||
Ok(self
|
||||
.move_selection(MoveSelection::PageDown)
|
||||
.into())
|
||||
} else if key_match(e, self.key_config.keys.move_left) {
|
||||
} else if key_match(e, self.key_config.keys.move_left)
|
||||
{
|
||||
Ok(self
|
||||
.move_selection(MoveSelection::Left)
|
||||
.into())
|
||||
|
|
|
|||
|
|
@ -153,6 +153,71 @@ mod tests {
|
|||
use std::io::Write;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
fn key_event(code: KeyCode, modifiers: KeyModifiers) -> KeyEvent {
|
||||
KeyEvent::new(code, modifiers)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vim_nav_up() {
|
||||
let config = KeyConfig::default();
|
||||
assert!(config
|
||||
.is_nav_up(&key_event(KeyCode::Up, KeyModifiers::NONE)));
|
||||
assert!(config.is_nav_up(&key_event(
|
||||
KeyCode::Char('k'),
|
||||
KeyModifiers::NONE
|
||||
)));
|
||||
assert!(!config.is_nav_up(&key_event(
|
||||
KeyCode::Char('k'),
|
||||
KeyModifiers::CONTROL
|
||||
)));
|
||||
assert!(!config.is_nav_up(&key_event(
|
||||
KeyCode::Char('j'),
|
||||
KeyModifiers::NONE
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vim_nav_down() {
|
||||
let config = KeyConfig::default();
|
||||
assert!(config.is_nav_down(&key_event(
|
||||
KeyCode::Down,
|
||||
KeyModifiers::NONE
|
||||
)));
|
||||
assert!(config.is_nav_down(&key_event(
|
||||
KeyCode::Char('j'),
|
||||
KeyModifiers::NONE
|
||||
)));
|
||||
assert!(!config.is_nav_down(&key_event(
|
||||
KeyCode::Char('j'),
|
||||
KeyModifiers::CONTROL
|
||||
)));
|
||||
assert!(!config.is_nav_down(&key_event(
|
||||
KeyCode::Char('k'),
|
||||
KeyModifiers::NONE
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vim_nav_right() {
|
||||
let config = KeyConfig::default();
|
||||
assert!(config.is_nav_right(&key_event(
|
||||
KeyCode::Right,
|
||||
KeyModifiers::NONE
|
||||
)));
|
||||
assert!(config.is_nav_right(&key_event(
|
||||
KeyCode::Char('l'),
|
||||
KeyModifiers::NONE
|
||||
)));
|
||||
assert!(!config.is_nav_right(&key_event(
|
||||
KeyCode::Char('l'),
|
||||
KeyModifiers::CONTROL
|
||||
)));
|
||||
assert!(!config.is_nav_right(&key_event(
|
||||
KeyCode::Char('j'),
|
||||
KeyModifiers::NONE
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_hint() {
|
||||
let config = KeyConfig::default();
|
||||
|
|
|
|||
|
|
@ -129,7 +129,8 @@ impl Component for CompareCommitsPopup {
|
|||
{
|
||||
self.details.focus(false);
|
||||
self.diff.focus(true);
|
||||
} else if key_match(e, self.key_config.keys.move_left) {
|
||||
} else if key_match(e, self.key_config.keys.move_left)
|
||||
{
|
||||
self.hide_stacked(false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -166,7 +166,8 @@ impl Component for InspectCommitPopup {
|
|||
{
|
||||
self.details.focus(false);
|
||||
self.diff.focus(true);
|
||||
} else if key_match(e, self.key_config.keys.move_left) {
|
||||
} else if key_match(e, self.key_config.keys.move_left)
|
||||
{
|
||||
self.hide_stacked(false);
|
||||
} else if key_match(
|
||||
e,
|
||||
|
|
|
|||
|
|
@ -328,7 +328,10 @@ impl Component for OptionsPopup {
|
|||
self.move_selection(false);
|
||||
} else if self.key_config.is_nav_right(key) {
|
||||
self.switch_option(true);
|
||||
} else if key_match(key, self.key_config.keys.move_left) {
|
||||
} else if key_match(
|
||||
key,
|
||||
self.key_config.keys.move_left,
|
||||
) {
|
||||
self.switch_option(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue