Skip to content

Commit d61ba14

Browse files
committed
fix: support AltGr text input
1 parent 685cca9 commit d61ba14

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
* 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))
1818

1919
### Fixes
20+
* allow entering AltGr-bound characters in text inputs on Windows ([#2848](https://github.com/gitui-org/gitui/issues/2848))
2021
* crash when opening submodule ([#2895](https://github.com/gitui-org/gitui/issues/2895))
2122
* 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))
2223
* index-out-of-bounds panic when unstaging lines near the end of a diff ([#2953](https://github.com/gitui-org/gitui/issues/2953))

src/components/textinput.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,17 @@ impl TextInputComponent {
610610
ta.scroll(Scrolling::PageUp);
611611
true
612612
}
613+
// On Windows, AltGr is reported as Ctrl+Alt. Handle any characters
614+
// not reserved for existing Ctrl+Alt editing shortcuts as text input.
615+
Input {
616+
key: Key::Char(c),
617+
ctrl: true,
618+
alt: true,
619+
..
620+
} => {
621+
ta.insert_char(*c);
622+
true
623+
}
613624
_ => false,
614625
}
615626
}
@@ -733,6 +744,54 @@ impl Component for TextInputComponent {
733744
#[cfg(test)]
734745
mod tests {
735746
use super::*;
747+
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
748+
749+
#[test]
750+
fn test_altgr_character_input() {
751+
let env = Environment::test_env();
752+
let mut comp = TextInputComponent::new(&env, "", "", false);
753+
comp.show_inner_textarea();
754+
755+
comp.event(&Event::Key(KeyEvent::new(
756+
KeyCode::Char('{'),
757+
KeyModifiers::CONTROL | KeyModifiers::ALT,
758+
)))
759+
.unwrap();
760+
761+
assert_eq!(comp.get_text(), "{");
762+
}
763+
764+
#[test]
765+
fn test_alt_character_input_is_not_inserted() {
766+
let env = Environment::test_env();
767+
let mut comp = TextInputComponent::new(&env, "", "", false);
768+
comp.show_inner_textarea();
769+
770+
comp.event(&Event::Key(KeyEvent::new(
771+
KeyCode::Char('{'),
772+
KeyModifiers::ALT,
773+
)))
774+
.unwrap();
775+
776+
assert_eq!(comp.get_text(), "");
777+
}
778+
779+
#[test]
780+
fn test_ctrl_alt_editor_shortcut_is_preserved() {
781+
let env = Environment::test_env();
782+
let mut comp = TextInputComponent::new(&env, "", "", false);
783+
comp.show_inner_textarea();
784+
comp.set_text("text".to_string());
785+
comp.textarea.as_mut().unwrap().move_cursor(CursorMove::End);
786+
787+
comp.event(&Event::Key(KeyEvent::new(
788+
KeyCode::Char('b'),
789+
KeyModifiers::CONTROL | KeyModifiers::ALT,
790+
)))
791+
.unwrap();
792+
793+
assert_eq!(comp.textarea.as_ref().unwrap().cursor(), (0, 0));
794+
}
736795

737796
#[test]
738797
fn test_smoke() {

0 commit comments

Comments
 (0)