fix next commit msg from history ordering

and also disable this command if no history is present

this fixes #1445
This commit is contained in:
extrawurst 2022-11-22 12:18:36 +01:00
parent 234e7cb3fc
commit b987598c7b
3 changed files with 18 additions and 6 deletions

View File

@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Fixes
* commit msg history ordered the wrong way ([#1445](https://github.com/extrawurst/gitui/issues/1445))
## [0.22.1] - 2022-11-22
Bugfix followup release - check `0.22.0` notes for more infos!

View File

@ -344,7 +344,7 @@ impl Component for CommitComponent {
strings::commands::commit_next_msg_from_history(
&self.key_config,
),
true,
self.options.borrow().has_commit_msg_history(),
true,
));
}

View File

@ -104,15 +104,24 @@ impl Options {
self.save();
}
pub fn has_commit_msg_history(&self) -> bool {
!self.data.commit_msgs.is_empty()
}
pub fn commit_msg(&self, idx: usize) -> Option<String> {
if self.data.commit_msgs.is_empty() {
None
} else {
Some(
self.data.commit_msgs
[idx % self.data.commit_msgs.len()]
.to_string(),
)
let entries = self.data.commit_msgs.len();
let mut index = idx;
while index >= entries {
index -= entries;
}
index = entries.saturating_sub(1) - index;
Some(self.data.commit_msgs[index].to_string())
}
}