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
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
@@ -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))
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
@@ -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,
));
@@ -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);
}
787 changes: 393 additions & 394 deletions src/components/textinput.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/keys/key_list.rs
Original file line number Diff line number Diff line change
@@ -211,8 +211,8 @@ impl Default for KeysList {
view_submodule_parent: GituiKeyEvent::new(KeyCode::Char('p'), KeyModifiers::empty()),
update_submodule: GituiKeyEvent::new(KeyCode::Char('u'), KeyModifiers::empty()),
commit_history_next: GituiKeyEvent::new(KeyCode::Char('n'), KeyModifiers::CONTROL),
commit: GituiKeyEvent::new(KeyCode::Enter, KeyModifiers::empty()),
newline: GituiKeyEvent::new(KeyCode::Char('r'), KeyModifiers::CONTROL),
commit: GituiKeyEvent::new(KeyCode::Char('d'), KeyModifiers::CONTROL),
newline: GituiKeyEvent::new(KeyCode::Enter, KeyModifiers::empty()),
}
}
}
6 changes: 4 additions & 2 deletions src/strings.rs
Original file line number Diff line number Diff line change
@@ -964,10 +964,12 @@ pub mod commands {
CMD_GROUP_COMMIT_POPUP,
)
}
pub fn commit_enter(key_config: &SharedKeyConfig) -> CommandText {
pub fn commit_submit(
key_config: &SharedKeyConfig,
) -> CommandText {
CommandText::new(
format!(
"Commit [{}]",
"Do Commit [{}]",
key_config.get_hint(key_config.keys.commit),
),
"commit (available when commit message is non-empty)",