Skip to content

Commit 91ae9fb

Browse files
committed
multiline annotation tag message edit
1 parent f29d769 commit 91ae9fb

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

src/components/textinput.rs

+6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ impl TextInputComponent {
8888
self
8989
}
9090

91+
///
92+
pub fn set_input_type(&mut self, input_type: InputType) {
93+
self.clear();
94+
self.input_type = input_type;
95+
}
96+
9197
/// Clear the `msg`.
9298
pub fn clear(&mut self) {
9399
self.msg.take();

src/popups/tag_commit.rs

+31-14
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@ impl Component for TagCommitPopup {
4646
if self.is_visible() || force_all {
4747
self.input.commands(out, force_all);
4848

49+
let is_annotation_mode =
50+
matches!(self.mode, Mode::Annotation { .. });
51+
4952
out.push(CommandInfo::new(
5053
strings::commands::tag_commit_confirm_msg(
5154
&self.key_config,
55+
is_annotation_mode,
5256
),
5357
self.is_valid_tag(),
5458
true,
@@ -67,29 +71,27 @@ impl Component for TagCommitPopup {
6771
fn event(&mut self, ev: &Event) -> Result<EventState> {
6872
if self.is_visible() {
6973
if let Event::Key(e) = ev {
70-
if key_match(e, self.key_config.keys.enter)
74+
let is_annotation_mode =
75+
matches!(self.mode, Mode::Annotation { .. });
76+
77+
if !is_annotation_mode
78+
&& key_match(e, self.key_config.keys.enter)
7179
&& self.is_valid_tag()
7280
{
7381
try_or_popup!(self, "tag error:", self.tag());
7482
return Ok(EventState::Consumed);
83+
}
84+
if is_annotation_mode
85+
&& key_match(e, self.key_config.keys.commit)
86+
{
87+
try_or_popup!(self, "tag error:", self.tag());
88+
return Ok(EventState::Consumed);
7589
} else if key_match(
7690
e,
7791
self.key_config.keys.tag_annotate,
7892
) && self.is_valid_tag()
7993
{
80-
let tag_name: String =
81-
self.input.get_text().into();
82-
83-
self.input.clear();
84-
self.input.set_title(
85-
strings::tag_popup_annotation_title(
86-
&tag_name,
87-
),
88-
);
89-
self.input.set_default_msg(
90-
strings::tag_popup_annotation_msg(),
91-
);
92-
self.mode = Mode::Annotation { tag_name };
94+
self.start_annotate_mode();
9395
return Ok(EventState::Consumed);
9496
}
9597
}
@@ -110,6 +112,7 @@ impl Component for TagCommitPopup {
110112

111113
fn show(&mut self) -> Result<()> {
112114
self.mode = Mode::Name;
115+
self.input.set_input_type(InputType::Singleline);
113116
self.input.set_title(strings::tag_popup_name_title());
114117
self.input.set_default_msg(strings::tag_popup_name_msg());
115118
self.input.show()?;
@@ -165,6 +168,7 @@ impl TagCommitPopup {
165168
.flatten()
166169
.and_then(|val| val.parse::<bool>().ok())
167170
.unwrap_or_default();
171+
168172
anyhow::ensure!(!gpgsign, "config tag.gpgsign=true detected.\ngpg signing not supported.\ndeactivate in your repo/gitconfig to be able to tag without signing.");
169173

170174
let (tag_name, tag_annotation) = self.tag_info();
@@ -200,4 +204,17 @@ impl TagCommitPopup {
200204

201205
Ok(())
202206
}
207+
208+
fn start_annotate_mode(&mut self) {
209+
let tag_name: String = self.input.get_text().into();
210+
211+
self.input.clear();
212+
self.input.set_input_type(InputType::Multiline);
213+
self.input.set_title(strings::tag_popup_annotation_title(
214+
&tag_name,
215+
));
216+
self.input
217+
.set_default_msg(strings::tag_popup_annotation_msg());
218+
self.mode = Mode::Annotation { tag_name };
219+
}
203220
}

src/strings.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1423,11 +1423,16 @@ pub mod commands {
14231423
}
14241424
pub fn tag_commit_confirm_msg(
14251425
key_config: &SharedKeyConfig,
1426+
is_annotation_mode: bool,
14261427
) -> CommandText {
14271428
CommandText::new(
14281429
format!(
14291430
"Tag [{}]",
1430-
key_config.get_hint(key_config.keys.enter),
1431+
key_config.get_hint(if is_annotation_mode {
1432+
key_config.keys.commit
1433+
} else {
1434+
key_config.keys.enter
1435+
}),
14311436
),
14321437
"tag commit",
14331438
CMD_GROUP_LOG,

0 commit comments

Comments
 (0)