Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* support rewording non-HEAD commits when `commit.gpgsign` is enabled (gpg format only) [[@guerinoni](https://github.com/guerinoni)] ([#2959](https://github.com/gitui-org/gitui/pull/2959))

### Fixes
* allow entering AltGr-bound characters in text inputs on Windows ([#2848](https://github.com/gitui-org/gitui/issues/2848))
* crash when opening submodule ([#2895](https://github.com/gitui-org/gitui/issues/2895))
* when staging the last file in a directory, the first item after the directory is no longer skipped [[@Tillerino](https://github.com/Tillerino)] ([#2748](https://github.com/gitui-org/gitui/issues/2748))
* index-out-of-bounds panic when unstaging lines near the end of a diff ([#2953](https://github.com/gitui-org/gitui/issues/2953))
Expand Down
59 changes: 59 additions & 0 deletions src/components/textinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,17 @@ impl TextInputComponent {
ta.scroll(Scrolling::PageUp);
true
}
// On Windows, AltGr is reported as Ctrl+Alt. Handle any characters
// not reserved for existing Ctrl+Alt editing shortcuts as text input.
Input {
key: Key::Char(c),
ctrl: true,
alt: true,
..
} => {
ta.insert_char(*c);
true
}
_ => false,
}
}
Expand Down Expand Up @@ -733,6 +744,54 @@ impl Component for TextInputComponent {
#[cfg(test)]
mod tests {
use super::*;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};

#[test]
fn test_altgr_character_input() {
let env = Environment::test_env();
let mut comp = TextInputComponent::new(&env, "", "", false);
comp.show_inner_textarea();

comp.event(&Event::Key(KeyEvent::new(
KeyCode::Char('{'),
KeyModifiers::CONTROL | KeyModifiers::ALT,
)))
.unwrap();

assert_eq!(comp.get_text(), "{");
}

#[test]
fn test_alt_character_input_is_not_inserted() {
let env = Environment::test_env();
let mut comp = TextInputComponent::new(&env, "", "", false);
comp.show_inner_textarea();

comp.event(&Event::Key(KeyEvent::new(
KeyCode::Char('{'),
KeyModifiers::ALT,
)))
.unwrap();

assert_eq!(comp.get_text(), "");
}

#[test]
fn test_ctrl_alt_editor_shortcut_is_preserved() {
let env = Environment::test_env();
let mut comp = TextInputComponent::new(&env, "", "", false);
comp.show_inner_textarea();
comp.set_text("text".to_string());
comp.textarea.as_mut().unwrap().move_cursor(CursorMove::End);

comp.event(&Event::Key(KeyEvent::new(
KeyCode::Char('b'),
KeyModifiers::CONTROL | KeyModifiers::ALT,
)))
.unwrap();

assert_eq!(comp.textarea.as_ref().unwrap().cursor(), (0, 0));
}

#[test]
fn test_smoke() {
Expand Down