Skip to content

Commit

Permalink
Fix arrow key bug in hangul (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
Riey authored Mar 18, 2021
1 parent 4c57402 commit 160243a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Improve

* Fix arrow key bug in hangul [#373](https://github.com/Riey/kime/issues/373)

## 2.0.0

### Breaking
Expand Down
9 changes: 7 additions & 2 deletions src/engine/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ impl Default for RawConfig {
icon_color: IconColor::default(),
global_hotkeys: btreemap! {
Key::normal(KeyCode::Esc) => Hotkey::new(HotkeyBehavior::Switch(InputCategory::Latin), HotkeyResult::Bypass),
Key::normal(KeyCode::Tab) => Hotkey::new(HotkeyBehavior::Commit, HotkeyResult::ConsumeIfProcessed),
Key::normal(KeyCode::AltR) => Hotkey::new(HotkeyBehavior::toggle_hangul_latin(), HotkeyResult::Consume),
Key::normal(KeyCode::Hangul) => Hotkey::new(HotkeyBehavior::toggle_hangul_latin(), HotkeyResult::Consume),
Key::super_(KeyCode::Space) => Hotkey::new(HotkeyBehavior::toggle_hangul_latin(), HotkeyResult::Consume),
Expand All @@ -117,18 +116,24 @@ impl Default for RawConfig {
Key::normal(KeyCode::ControlR) => Hotkey::new(HotkeyBehavior::Mode(InputMode::Hanja), HotkeyResult::Consume),
Key::normal(KeyCode::Space) => Hotkey::new(HotkeyBehavior::Commit, HotkeyResult::Bypass),
Key::normal(KeyCode::Enter) => Hotkey::new(HotkeyBehavior::Commit, HotkeyResult::Bypass),
Key::normal(KeyCode::Left) => Hotkey::new(HotkeyBehavior::Commit, HotkeyResult::Bypass),
Key::normal(KeyCode::Right) => Hotkey::new(HotkeyBehavior::Commit, HotkeyResult::Bypass),
Key::normal(KeyCode::Up) => Hotkey::new(HotkeyBehavior::Commit, HotkeyResult::Bypass),
Key::normal(KeyCode::Down) => Hotkey::new(HotkeyBehavior::Commit, HotkeyResult::Bypass),
},
},
mode_hotkeys: btreemap! {
InputMode::Hanja => btreemap! {
Key::normal(KeyCode::Enter) => Hotkey::new(HotkeyBehavior::Commit, HotkeyResult::ConsumeIfProcessed),
Key::normal(KeyCode::Space) => Hotkey::new(HotkeyBehavior::Commit, HotkeyResult::Bypass),
Key::normal(KeyCode::Tab) => Hotkey::new(HotkeyBehavior::Commit, HotkeyResult::ConsumeIfProcessed),
},
InputMode::Emoji => btreemap! {
Key::normal(KeyCode::Enter) => Hotkey::new(HotkeyBehavior::Commit, HotkeyResult::ConsumeIfProcessed),
Key::normal(KeyCode::Tab) => Hotkey::new(HotkeyBehavior::Commit, HotkeyResult::ConsumeIfProcessed),
},
InputMode::Math => btreemap! {
Key::normal(KeyCode::Enter) => Hotkey::new(HotkeyBehavior::Commit, HotkeyResult::ConsumeIfProcessed),
Key::normal(KeyCode::Tab) => Hotkey::new(HotkeyBehavior::Commit, HotkeyResult::ConsumeIfProcessed),
Key::normal(KeyCode::Space) => Hotkey::new(HotkeyBehavior::Commit, HotkeyResult::Bypass),
},
},
Expand Down
22 changes: 7 additions & 15 deletions src/engine/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ impl InputEngine {
pub fn press_key(&mut self, key: Key, config: &Config) -> InputResult {
self.try_get_global_input_category_state(config);

let mut ret = InputResult::empty();

if let Some(hotkey) = self.try_hotkey(&key, config) {
let mut processed = false;
let mut ret = InputResult::empty();

match hotkey.behavior() {
HotkeyBehavior::Switch(category) => {
if self.category() != category {
Expand Down Expand Up @@ -133,21 +133,13 @@ impl InputEngine {
ret |= InputResult::CONSUMED;
}
}
} else if self.engine_impl.press_key(key, &mut self.commit_buf) {
ret |= InputResult::CONSUMED;
}

ret |= self.current_result();

ret
} else {
let mut ret = InputResult::empty();

if self.engine_impl.press_key(key, &mut self.commit_buf) {
ret |= InputResult::CONSUMED;
}

ret |= self.current_result();
ret |= self.current_result();

ret
}
ret
}

pub fn press_key_code(
Expand Down
9 changes: 9 additions & 0 deletions src/engine/core/tests/dubeolsik.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ fn esc() {
]);
}

// issue #373
#[test]
fn arrow() {
test_input(&[
(Key::normal(R), "ㄱ", ""),
(Key::normal(Left), "", "ㄱPASS"),
]);
}

#[test]
fn next_jaum() {
test_input(&[
Expand Down

0 comments on commit 160243a

Please sign in to comment.