Skip to content

Multiline TextEdit cleanups #2053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

** multiline text editor **

![multiline editor](assets/multiline-texteditor.gif)

### Breaking Change
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`).
Both commands can be overwritten via `newline` and `commit` in the key bindings. see [KEY_CONFIG](./KEY_CONFIG.md) on how.
These defaults require some adoption from existing users but feel more natural to new users.

### Added
* `theme.ron` now supports customizing line break symbol ([#1894](https://github.com/extrawurst/gitui/issues/1894))
* add confirmation for dialog for undo commit [[@TeFiLeDo](https://github.com/TeFiLeDo)] ([#1912](https://github.com/extrawurst/gitui/issues/1912))
* support `prepare-commit-msg` hook ([#1873](https://github.com/extrawurst/gitui/issues/1873))
* support for new-line in text-input (e.g. commit message editor) [[@pm100]](https://github/pm100) ([#1662](https://github.com/extrawurst/gitui/issues/1662)).

### Changed
* do not allow tag when `tag.gpgsign` enabled [[@TeFiLeDo](https://github.com/TeFiLeDo)] ([#1915](https://github.com/extrawurst/gitui/pull/1915))
Expand Down
Binary file added assets/multiline-texteditor.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 59 additions & 49 deletions src/components/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ impl Component for CommitComponent {

if self.is_visible() || force_all {
out.push(CommandInfo::new(
strings::commands::commit_enter(&self.key_config),
strings::commands::commit_submit(&self.key_config),
self.can_commit(),
true,
));
Expand Down Expand Up @@ -566,57 +566,67 @@ impl Component for CommitComponent {

fn event(&mut self, ev: &Event) -> Result<EventState> {
if self.is_visible() {
if self.input.event(ev)?.is_consumed() {
return Ok(EventState::Consumed);
}

if let Event::Key(e) = ev {
if key_match(e, self.key_config.keys.commit)
&& self.can_commit()
{
try_or_popup!(
self,
"commit error:",
self.commit()
);
} else if key_match(
e,
self.key_config.keys.toggle_verify,
) && self.can_commit()
{
self.toggle_verify();
} else if key_match(
e,
self.key_config.keys.commit_amend,
) && self.can_amend()
{
self.amend()?;
} else if key_match(
e,
self.key_config.keys.open_commit_editor,
) {
self.queue.push(
InternalEvent::OpenExternalEditor(None),
);
self.hide();
} else if key_match(
e,
self.key_config.keys.commit_history_next,
) {
if let Some(msg) = self
.options
.borrow()
.commit_msg(self.commit_msg_history_idx)
let input_consumed =
if key_match(e, self.key_config.keys.commit)
&& self.can_commit()
{
try_or_popup!(
self,
"commit error:",
self.commit()
);
true
} else if key_match(
e,
self.key_config.keys.toggle_verify,
) && self.can_commit()
{
self.toggle_verify();
true
} else if key_match(
e,
self.key_config.keys.commit_amend,
) && self.can_amend()
{
self.input.set_text(msg);
self.commit_msg_history_idx += 1;
}
} else if key_match(
e,
self.key_config.keys.toggle_signoff,
) {
self.signoff_commit();
self.amend()?;
true
} else if key_match(
e,
self.key_config.keys.open_commit_editor,
) {
self.queue.push(
InternalEvent::OpenExternalEditor(None),
);
self.hide();
true
} else if key_match(
e,
self.key_config.keys.commit_history_next,
) {
if let Some(msg) = self
.options
.borrow()
.commit_msg(self.commit_msg_history_idx)
{
self.input.set_text(msg);
self.commit_msg_history_idx += 1;
}
true
} else if key_match(
e,
self.key_config.keys.toggle_signoff,
) {
self.signoff_commit();
true
} else {
false
};

if !input_consumed {
self.input.event(ev)?;
}

// stop key event propagation
return Ok(EventState::Consumed);
}
Expand Down
Loading