mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28: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
|
## Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
* vim-like navigation: `j`/`k` for up/down, `l` to open preview
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
* use [tombi](https://github.com/tombi-toml/tombi) for all toml file formatting
|
* 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))
|
* 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> {
|
fn event(&mut self, event: &Event) -> Result<EventState> {
|
||||||
if self.focused {
|
if self.focused {
|
||||||
if let Event::Key(e) = event {
|
if let Event::Key(e) = event {
|
||||||
return Ok(
|
return Ok(if self.key_config.is_nav_up(e) {
|
||||||
if self.key_config.is_nav_up(e) {
|
self.move_scroll_top(ScrollType::Up).into()
|
||||||
self.move_scroll_top(ScrollType::Up).into()
|
} else if self.key_config.is_nav_down(e) {
|
||||||
} else if self.key_config.is_nav_down(e) {
|
self.move_scroll_top(ScrollType::Down).into()
|
||||||
self.move_scroll_top(ScrollType::Down).into()
|
} else if key_match(e, self.key_config.keys.page_up) {
|
||||||
} else if key_match(
|
self.move_scroll_top(ScrollType::PageUp).into()
|
||||||
e,
|
} else if key_match(e, self.key_config.keys.page_down)
|
||||||
self.key_config.keys.page_up,
|
{
|
||||||
) {
|
self.move_scroll_top(ScrollType::PageDown).into()
|
||||||
self.move_scroll_top(ScrollType::PageUp)
|
} else if key_match(e, self.key_config.keys.home)
|
||||||
.into()
|
|| key_match(e, self.key_config.keys.shift_up)
|
||||||
} else if key_match(
|
{
|
||||||
e,
|
self.move_scroll_top(ScrollType::Home).into()
|
||||||
self.key_config.keys.page_down,
|
} else if key_match(e, self.key_config.keys.end)
|
||||||
) {
|
|| key_match(e, self.key_config.keys.shift_down)
|
||||||
self.move_scroll_top(ScrollType::PageDown)
|
{
|
||||||
.into()
|
self.move_scroll_top(ScrollType::End).into()
|
||||||
} else if key_match(e, self.key_config.keys.home)
|
} else {
|
||||||
|| key_match(e, self.key_config.keys.shift_up)
|
EventState::NotConsumed
|
||||||
{
|
});
|
||||||
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,
|
Component, DrawableComponent, EventState, StatusTreeComponent,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
accessors,
|
accessors, app::Environment, keys::SharedKeyConfig, strings,
|
||||||
app::Environment,
|
|
||||||
keys::SharedKeyConfig,
|
|
||||||
strings,
|
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use asyncgit::{
|
use asyncgit::{
|
||||||
|
|
|
||||||
|
|
@ -830,41 +830,37 @@ impl DrawableComponent for CommitList {
|
||||||
impl Component for CommitList {
|
impl Component for CommitList {
|
||||||
fn event(&mut self, ev: &Event) -> Result<EventState> {
|
fn event(&mut self, ev: &Event) -> Result<EventState> {
|
||||||
if let Event::Key(k) = ev {
|
if let Event::Key(k) = ev {
|
||||||
let selection_changed =
|
let selection_changed = if self.key_config.is_nav_up(k) {
|
||||||
if self.key_config.is_nav_up(k) {
|
self.move_selection(ScrollType::Up)?
|
||||||
self.move_selection(ScrollType::Up)?
|
} else if self.key_config.is_nav_down(k) {
|
||||||
} else if self.key_config.is_nav_down(k) {
|
self.move_selection(ScrollType::Down)?
|
||||||
self.move_selection(ScrollType::Down)?
|
} else if key_match(k, self.key_config.keys.shift_up)
|
||||||
} else if key_match(k, self.key_config.keys.shift_up)
|
|| key_match(k, self.key_config.keys.home)
|
||||||
|| key_match(k, self.key_config.keys.home)
|
{
|
||||||
{
|
self.move_selection(ScrollType::Home)?
|
||||||
self.move_selection(ScrollType::Home)?
|
} else if key_match(k, self.key_config.keys.shift_down)
|
||||||
} else if key_match(
|
|| key_match(k, self.key_config.keys.end)
|
||||||
k,
|
{
|
||||||
self.key_config.keys.shift_down,
|
self.move_selection(ScrollType::End)?
|
||||||
) || key_match(k, self.key_config.keys.end)
|
} else if key_match(k, self.key_config.keys.page_up) {
|
||||||
{
|
self.move_selection(ScrollType::PageUp)?
|
||||||
self.move_selection(ScrollType::End)?
|
} else if key_match(k, self.key_config.keys.page_down) {
|
||||||
} else if key_match(k, self.key_config.keys.page_up) {
|
self.move_selection(ScrollType::PageDown)?
|
||||||
self.move_selection(ScrollType::PageUp)?
|
} else if key_match(
|
||||||
} else if key_match(k, self.key_config.keys.page_down)
|
k,
|
||||||
{
|
self.key_config.keys.log_mark_commit,
|
||||||
self.move_selection(ScrollType::PageDown)?
|
) {
|
||||||
} else if key_match(
|
self.mark();
|
||||||
k,
|
true
|
||||||
self.key_config.keys.log_mark_commit,
|
} else if key_match(
|
||||||
) {
|
k,
|
||||||
self.mark();
|
self.key_config.keys.log_checkout_commit,
|
||||||
true
|
) {
|
||||||
} else if key_match(
|
self.checkout();
|
||||||
k,
|
true
|
||||||
self.key_config.keys.log_checkout_commit,
|
} else {
|
||||||
) {
|
false
|
||||||
self.checkout();
|
};
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
|
||||||
return Ok(selection_changed.into());
|
return Ok(selection_changed.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -864,7 +864,8 @@ impl Component for DiffComponent {
|
||||||
self.horizontal_scroll
|
self.horizontal_scroll
|
||||||
.move_right(HorizontalScrollType::Right);
|
.move_right(HorizontalScrollType::Right);
|
||||||
Ok(EventState::Consumed)
|
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
|
self.horizontal_scroll
|
||||||
.move_right(HorizontalScrollType::Left);
|
.move_right(HorizontalScrollType::Left);
|
||||||
Ok(EventState::Consumed)
|
Ok(EventState::Consumed)
|
||||||
|
|
|
||||||
|
|
@ -543,7 +543,8 @@ impl Component for StatusTreeComponent {
|
||||||
Ok(self
|
Ok(self
|
||||||
.move_selection(MoveSelection::PageDown)
|
.move_selection(MoveSelection::PageDown)
|
||||||
.into())
|
.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
|
Ok(self
|
||||||
.move_selection(MoveSelection::Left)
|
.move_selection(MoveSelection::Left)
|
||||||
.into())
|
.into())
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,71 @@ mod tests {
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use tempfile::NamedTempFile;
|
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]
|
#[test]
|
||||||
fn test_get_hint() {
|
fn test_get_hint() {
|
||||||
let config = KeyConfig::default();
|
let config = KeyConfig::default();
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,8 @@ impl Component for CompareCommitsPopup {
|
||||||
{
|
{
|
||||||
self.details.focus(false);
|
self.details.focus(false);
|
||||||
self.diff.focus(true);
|
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);
|
self.hide_stacked(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,8 @@ impl Component for InspectCommitPopup {
|
||||||
{
|
{
|
||||||
self.details.focus(false);
|
self.details.focus(false);
|
||||||
self.diff.focus(true);
|
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);
|
self.hide_stacked(false);
|
||||||
} else if key_match(
|
} else if key_match(
|
||||||
e,
|
e,
|
||||||
|
|
|
||||||
|
|
@ -328,7 +328,10 @@ impl Component for OptionsPopup {
|
||||||
self.move_selection(false);
|
self.move_selection(false);
|
||||||
} else if self.key_config.is_nav_right(key) {
|
} else if self.key_config.is_nav_right(key) {
|
||||||
self.switch_option(true);
|
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);
|
self.switch_option(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue