mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
Improve navigation (#29)
* offer commit only when selecting staging area * show quickbar cmd to switch between unstaged/staged * adjust size of focused file tree
This commit is contained in:
parent
d90d5d9fb3
commit
5382ce7408
3 changed files with 62 additions and 25 deletions
55
src/app.rs
55
src/app.rs
|
|
@ -138,10 +138,17 @@ impl App {
|
|||
let left_chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(
|
||||
[
|
||||
Constraint::Percentage(50),
|
||||
Constraint::Percentage(50),
|
||||
]
|
||||
if self.diff_target == DiffTarget::WorkingDir {
|
||||
[
|
||||
Constraint::Percentage(60),
|
||||
Constraint::Percentage(40),
|
||||
]
|
||||
} else {
|
||||
[
|
||||
Constraint::Percentage(40),
|
||||
Constraint::Percentage(60),
|
||||
]
|
||||
}
|
||||
.as_ref(),
|
||||
)
|
||||
.split(chunks[0]);
|
||||
|
|
@ -187,6 +194,13 @@ impl App {
|
|||
DiffTarget::WorkingDir => Focus::WorkDir,
|
||||
})
|
||||
}
|
||||
keys::OPEN_COMMIT
|
||||
if !self.index.is_empty()
|
||||
&& self.offer_open_commit_cmd() =>
|
||||
{
|
||||
self.commit.show();
|
||||
NeedsUpdate::COMMANDS
|
||||
}
|
||||
_ => NeedsUpdate::empty(),
|
||||
};
|
||||
|
||||
|
|
@ -295,7 +309,6 @@ impl App {
|
|||
self.index_wd.update(&status.work_dir);
|
||||
|
||||
self.update_diff();
|
||||
self.commit.set_stage_empty(self.index.is_empty());
|
||||
self.update_commands();
|
||||
}
|
||||
|
||||
|
|
@ -413,6 +426,33 @@ impl App {
|
|||
));
|
||||
}
|
||||
|
||||
res.push(
|
||||
CommandInfo::new(
|
||||
commands::COMMIT_OPEN,
|
||||
!self.index.is_empty(),
|
||||
self.offer_open_commit_cmd(),
|
||||
)
|
||||
.order(-1),
|
||||
);
|
||||
|
||||
res.push(
|
||||
CommandInfo::new(
|
||||
commands::SELECT_STAGING,
|
||||
true,
|
||||
self.focus == Focus::WorkDir,
|
||||
)
|
||||
.order(-2),
|
||||
);
|
||||
|
||||
res.push(
|
||||
CommandInfo::new(
|
||||
commands::SELECT_UNSTAGED,
|
||||
true,
|
||||
self.focus == Focus::Stage,
|
||||
)
|
||||
.order(-2),
|
||||
);
|
||||
|
||||
res.push(
|
||||
CommandInfo::new(
|
||||
commands::QUIT,
|
||||
|
|
@ -426,6 +466,11 @@ impl App {
|
|||
res
|
||||
}
|
||||
|
||||
fn offer_open_commit_cmd(&self) -> bool {
|
||||
!self.commit.is_visible()
|
||||
&& self.diff_target == DiffTarget::Stage
|
||||
}
|
||||
|
||||
fn components(&self) -> Vec<&dyn Component> {
|
||||
vec![
|
||||
&self.msg,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ use super::{
|
|||
DrawableComponent,
|
||||
};
|
||||
use crate::{
|
||||
keys,
|
||||
queue::{InternalEvent, NeedsUpdate, Queue},
|
||||
strings, ui,
|
||||
};
|
||||
|
|
@ -24,7 +23,6 @@ use tui::{
|
|||
pub struct CommitComponent {
|
||||
msg: String,
|
||||
visible: bool,
|
||||
stage_empty: bool,
|
||||
queue: Queue,
|
||||
}
|
||||
|
||||
|
|
@ -62,11 +60,6 @@ impl Component for CommitComponent {
|
|||
out: &mut Vec<CommandInfo>,
|
||||
_force_all: bool,
|
||||
) -> CommandBlocking {
|
||||
out.push(CommandInfo::new(
|
||||
commands::COMMIT_OPEN,
|
||||
!self.stage_empty,
|
||||
!self.visible,
|
||||
));
|
||||
out.push(CommandInfo::new(
|
||||
commands::COMMIT_ENTER,
|
||||
self.can_commit(),
|
||||
|
|
@ -100,13 +93,6 @@ impl Component for CommitComponent {
|
|||
};
|
||||
return true;
|
||||
}
|
||||
} else if let Event::Key(e) = ev {
|
||||
if let keys::OPEN_COMMIT = e {
|
||||
if !self.stage_empty {
|
||||
self.show();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
|
@ -130,7 +116,6 @@ impl CommitComponent {
|
|||
Self {
|
||||
queue,
|
||||
msg: String::default(),
|
||||
stage_empty: true,
|
||||
visible: false,
|
||||
}
|
||||
}
|
||||
|
|
@ -171,9 +156,4 @@ impl CommitComponent {
|
|||
fn can_commit(&self) -> bool {
|
||||
!self.msg.is_empty()
|
||||
}
|
||||
|
||||
///
|
||||
pub fn set_stage_empty(&mut self, empty: bool) {
|
||||
self.stage_empty = empty;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,6 +67,18 @@ pub mod commands {
|
|||
)
|
||||
.hide_help();
|
||||
///
|
||||
pub static SELECT_STAGING: CommandText = CommandText::new(
|
||||
"Focus Staging [2]",
|
||||
"focus/select staging area",
|
||||
CMD_GROUP_GENERAL,
|
||||
);
|
||||
///
|
||||
pub static SELECT_UNSTAGED: CommandText = CommandText::new(
|
||||
"Focus Unstaged [1]",
|
||||
"focus/select unstaged area",
|
||||
CMD_GROUP_GENERAL,
|
||||
);
|
||||
///
|
||||
pub static COMMIT_OPEN: CommandText = CommandText::new(
|
||||
"Commit [c]",
|
||||
"open commit view (available in non-empty stage)",
|
||||
|
|
|
|||
Loading…
Reference in a new issue