Skip to content

Commit 5382ce7

Browse files
author
Stephan Dilly
committed
Improve navigation (#29)
* offer commit only when selecting staging area * show quickbar cmd to switch between unstaged/staged * adjust size of focused file tree
1 parent d90d5d9 commit 5382ce7

File tree

3 files changed

+62
-25
lines changed

3 files changed

+62
-25
lines changed

src/app.rs

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,17 @@ impl App {
138138
let left_chunks = Layout::default()
139139
.direction(Direction::Vertical)
140140
.constraints(
141-
[
142-
Constraint::Percentage(50),
143-
Constraint::Percentage(50),
144-
]
141+
if self.diff_target == DiffTarget::WorkingDir {
142+
[
143+
Constraint::Percentage(60),
144+
Constraint::Percentage(40),
145+
]
146+
} else {
147+
[
148+
Constraint::Percentage(40),
149+
Constraint::Percentage(60),
150+
]
151+
}
145152
.as_ref(),
146153
)
147154
.split(chunks[0]);
@@ -187,6 +194,13 @@ impl App {
187194
DiffTarget::WorkingDir => Focus::WorkDir,
188195
})
189196
}
197+
keys::OPEN_COMMIT
198+
if !self.index.is_empty()
199+
&& self.offer_open_commit_cmd() =>
200+
{
201+
self.commit.show();
202+
NeedsUpdate::COMMANDS
203+
}
190204
_ => NeedsUpdate::empty(),
191205
};
192206

@@ -295,7 +309,6 @@ impl App {
295309
self.index_wd.update(&status.work_dir);
296310

297311
self.update_diff();
298-
self.commit.set_stage_empty(self.index.is_empty());
299312
self.update_commands();
300313
}
301314

@@ -413,6 +426,33 @@ impl App {
413426
));
414427
}
415428

429+
res.push(
430+
CommandInfo::new(
431+
commands::COMMIT_OPEN,
432+
!self.index.is_empty(),
433+
self.offer_open_commit_cmd(),
434+
)
435+
.order(-1),
436+
);
437+
438+
res.push(
439+
CommandInfo::new(
440+
commands::SELECT_STAGING,
441+
true,
442+
self.focus == Focus::WorkDir,
443+
)
444+
.order(-2),
445+
);
446+
447+
res.push(
448+
CommandInfo::new(
449+
commands::SELECT_UNSTAGED,
450+
true,
451+
self.focus == Focus::Stage,
452+
)
453+
.order(-2),
454+
);
455+
416456
res.push(
417457
CommandInfo::new(
418458
commands::QUIT,
@@ -426,6 +466,11 @@ impl App {
426466
res
427467
}
428468

469+
fn offer_open_commit_cmd(&self) -> bool {
470+
!self.commit.is_visible()
471+
&& self.diff_target == DiffTarget::Stage
472+
}
473+
429474
fn components(&self) -> Vec<&dyn Component> {
430475
vec![
431476
&self.msg,

src/components/commit.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use super::{
33
DrawableComponent,
44
};
55
use crate::{
6-
keys,
76
queue::{InternalEvent, NeedsUpdate, Queue},
87
strings, ui,
98
};
@@ -24,7 +23,6 @@ use tui::{
2423
pub struct CommitComponent {
2524
msg: String,
2625
visible: bool,
27-
stage_empty: bool,
2826
queue: Queue,
2927
}
3028

@@ -62,11 +60,6 @@ impl Component for CommitComponent {
6260
out: &mut Vec<CommandInfo>,
6361
_force_all: bool,
6462
) -> CommandBlocking {
65-
out.push(CommandInfo::new(
66-
commands::COMMIT_OPEN,
67-
!self.stage_empty,
68-
!self.visible,
69-
));
7063
out.push(CommandInfo::new(
7164
commands::COMMIT_ENTER,
7265
self.can_commit(),
@@ -100,13 +93,6 @@ impl Component for CommitComponent {
10093
};
10194
return true;
10295
}
103-
} else if let Event::Key(e) = ev {
104-
if let keys::OPEN_COMMIT = e {
105-
if !self.stage_empty {
106-
self.show();
107-
return true;
108-
}
109-
}
11096
}
11197
false
11298
}
@@ -130,7 +116,6 @@ impl CommitComponent {
130116
Self {
131117
queue,
132118
msg: String::default(),
133-
stage_empty: true,
134119
visible: false,
135120
}
136121
}
@@ -171,9 +156,4 @@ impl CommitComponent {
171156
fn can_commit(&self) -> bool {
172157
!self.msg.is_empty()
173158
}
174-
175-
///
176-
pub fn set_stage_empty(&mut self, empty: bool) {
177-
self.stage_empty = empty;
178-
}
179159
}

src/strings.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ pub mod commands {
6767
)
6868
.hide_help();
6969
///
70+
pub static SELECT_STAGING: CommandText = CommandText::new(
71+
"Focus Staging [2]",
72+
"focus/select staging area",
73+
CMD_GROUP_GENERAL,
74+
);
75+
///
76+
pub static SELECT_UNSTAGED: CommandText = CommandText::new(
77+
"Focus Unstaged [1]",
78+
"focus/select unstaged area",
79+
CMD_GROUP_GENERAL,
80+
);
81+
///
7082
pub static COMMIT_OPEN: CommandText = CommandText::new(
7183
"Commit [c]",
7284
"open commit view (available in non-empty stage)",

0 commit comments

Comments
 (0)