Skip to content

Commit 825935b

Browse files
authored
Multiline TextEdit cleanups (#2053)
* change commit default binding * animated gif of multiline text edit * update changelog * fix style of default text * textinput should not need to know about its users * fix branch create popup
1 parent b9a2e13 commit 825935b

File tree

6 files changed

+468
-447
lines changed

6 files changed

+468
-447
lines changed

‎CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
** multiline text editor **
11+
12+
![multiline editor](assets/multiline-texteditor.gif)
13+
14+
### Breaking Change
15+
The Commit message popup now supports multiline editing! Inserting a **newline** defaults to `enter`. This comes with a new default to confirm the commit message (`ctrl+d`).
16+
Both commands can be overwritten via `newline` and `commit` in the key bindings. see [KEY_CONFIG](./KEY_CONFIG.md) on how.
17+
These defaults require some adoption from existing users but feel more natural to new users.
18+
1019
### Added
1120
* `theme.ron` now supports customizing line break symbol ([#1894](https://github.com/extrawurst/gitui/issues/1894))
1221
* add confirmation for dialog for undo commit [[@TeFiLeDo](https://github.com/TeFiLeDo)] ([#1912](https://github.com/extrawurst/gitui/issues/1912))
1322
* support `prepare-commit-msg` hook ([#1873](https://github.com/extrawurst/gitui/issues/1873))
23+
* support for new-line in text-input (e.g. commit message editor) [[@pm100]](https://github/pm100) ([#1662](https://github.com/extrawurst/gitui/issues/1662)).
1424

1525
### Changed
1626
* do not allow tag when `tag.gpgsign` enabled [[@TeFiLeDo](https://github.com/TeFiLeDo)] ([#1915](https://github.com/extrawurst/gitui/pull/1915))

‎assets/multiline-texteditor.gif

1.01 MB
Loading

‎src/components/commit.rs

+59-49
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ impl Component for CommitComponent {
512512

513513
if self.is_visible() || force_all {
514514
out.push(CommandInfo::new(
515-
strings::commands::commit_enter(&self.key_config),
515+
strings::commands::commit_submit(&self.key_config),
516516
self.can_commit(),
517517
true,
518518
));
@@ -566,57 +566,67 @@ impl Component for CommitComponent {
566566

567567
fn event(&mut self, ev: &Event) -> Result<EventState> {
568568
if self.is_visible() {
569-
if self.input.event(ev)?.is_consumed() {
570-
return Ok(EventState::Consumed);
571-
}
572-
573569
if let Event::Key(e) = ev {
574-
if key_match(e, self.key_config.keys.commit)
575-
&& self.can_commit()
576-
{
577-
try_or_popup!(
578-
self,
579-
"commit error:",
580-
self.commit()
581-
);
582-
} else if key_match(
583-
e,
584-
self.key_config.keys.toggle_verify,
585-
) && self.can_commit()
586-
{
587-
self.toggle_verify();
588-
} else if key_match(
589-
e,
590-
self.key_config.keys.commit_amend,
591-
) && self.can_amend()
592-
{
593-
self.amend()?;
594-
} else if key_match(
595-
e,
596-
self.key_config.keys.open_commit_editor,
597-
) {
598-
self.queue.push(
599-
InternalEvent::OpenExternalEditor(None),
600-
);
601-
self.hide();
602-
} else if key_match(
603-
e,
604-
self.key_config.keys.commit_history_next,
605-
) {
606-
if let Some(msg) = self
607-
.options
608-
.borrow()
609-
.commit_msg(self.commit_msg_history_idx)
570+
let input_consumed =
571+
if key_match(e, self.key_config.keys.commit)
572+
&& self.can_commit()
573+
{
574+
try_or_popup!(
575+
self,
576+
"commit error:",
577+
self.commit()
578+
);
579+
true
580+
} else if key_match(
581+
e,
582+
self.key_config.keys.toggle_verify,
583+
) && self.can_commit()
584+
{
585+
self.toggle_verify();
586+
true
587+
} else if key_match(
588+
e,
589+
self.key_config.keys.commit_amend,
590+
) && self.can_amend()
610591
{
611-
self.input.set_text(msg);
612-
self.commit_msg_history_idx += 1;
613-
}
614-
} else if key_match(
615-
e,
616-
self.key_config.keys.toggle_signoff,
617-
) {
618-
self.signoff_commit();
592+
self.amend()?;
593+
true
594+
} else if key_match(
595+
e,
596+
self.key_config.keys.open_commit_editor,
597+
) {
598+
self.queue.push(
599+
InternalEvent::OpenExternalEditor(None),
600+
);
601+
self.hide();
602+
true
603+
} else if key_match(
604+
e,
605+
self.key_config.keys.commit_history_next,
606+
) {
607+
if let Some(msg) = self
608+
.options
609+
.borrow()
610+
.commit_msg(self.commit_msg_history_idx)
611+
{
612+
self.input.set_text(msg);
613+
self.commit_msg_history_idx += 1;
614+
}
615+
true
616+
} else if key_match(
617+
e,
618+
self.key_config.keys.toggle_signoff,
619+
) {
620+
self.signoff_commit();
621+
true
622+
} else {
623+
false
624+
};
625+
626+
if !input_consumed {
627+
self.input.event(ev)?;
619628
}
629+
620630
// stop key event propagation
621631
return Ok(EventState::Consumed);
622632
}

0 commit comments

Comments
 (0)