From a2cb3fafee925cb08aa327378b3e24eef04b5b26 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Mon, 5 Sep 2016 23:11:25 +0200 Subject: [PATCH] Fix numpad 0 and . key handling Fixes #146. --- app/build.gradle | 4 ++-- .../java/com/termux/terminal/KeyHandler.java | 7 +++---- .../java/com/termux/terminal/KeyHandlerTest.java | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6b3c6bfef6..d33ad77fa8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,8 +13,8 @@ android { applicationId "com.termux" minSdkVersion 21 targetSdkVersion 24 - versionCode 40 - versionName "0.40" + versionCode 41 + versionName "0.41" ndk { moduleName "libtermux" diff --git a/app/src/main/java/com/termux/terminal/KeyHandler.java b/app/src/main/java/com/termux/terminal/KeyHandler.java index 4afe9f8821..a4d0f1ac87 100644 --- a/app/src/main/java/com/termux/terminal/KeyHandler.java +++ b/app/src/main/java/com/termux/terminal/KeyHandler.java @@ -219,9 +219,6 @@ public static String getCode(int keyCode, int keyMode, boolean cursorApp, boolea case KEYCODE_FORWARD_DEL: return transformForModifiers("\033[3", keyMode, '~'); - case KEYCODE_NUMPAD_DOT: - return keypadApplication ? "\033On" : "\033[3~"; - case KEYCODE_PAGE_UP: return "\033[5~"; case KEYCODE_PAGE_DOWN: @@ -251,12 +248,14 @@ public static String getCode(int keyCode, int keyMode, boolean cursorApp, boolea return keypadApplication ? transformForModifiers("\033O", keyMode, 'k') : "+"; case KEYCODE_NUMPAD_COMMA: return ","; + case KEYCODE_NUMPAD_DOT: + return keypadApplication ? "\033On" : "."; case KEYCODE_NUMPAD_SUBTRACT: return keypadApplication ? transformForModifiers("\033O", keyMode, 'm') : "-"; case KEYCODE_NUMPAD_DIVIDE: return keypadApplication ? transformForModifiers("\033O", keyMode, 'o') : "/"; case KEYCODE_NUMPAD_0: - return keypadApplication ? transformForModifiers("\033O", keyMode, 'p') : "1"; + return keypadApplication ? transformForModifiers("\033O", keyMode, 'p') : "0"; case KEYCODE_NUMPAD_1: return keypadApplication ? transformForModifiers("\033O", keyMode, 'q') : "1"; case KEYCODE_NUMPAD_2: diff --git a/app/src/test/java/com/termux/terminal/KeyHandlerTest.java b/app/src/test/java/com/termux/terminal/KeyHandlerTest.java index 590e06b666..9e3ee02691 100644 --- a/app/src/test/java/com/termux/terminal/KeyHandlerTest.java +++ b/app/src/test/java/com/termux/terminal/KeyHandlerTest.java @@ -173,5 +173,19 @@ public void testKeyCodes() { assertKeysEquals("\033[21;2~", KeyHandler.getCode(KeyEvent.KEYCODE_F10, KeyHandler.KEYMOD_SHIFT, false, false)); assertKeysEquals("\033[23;2~", KeyHandler.getCode(KeyEvent.KEYCODE_F11, KeyHandler.KEYMOD_SHIFT, false, false)); assertKeysEquals("\033[24;2~", KeyHandler.getCode(KeyEvent.KEYCODE_F12, KeyHandler.KEYMOD_SHIFT, false, false)); - } + + assertKeysEquals("0", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_0, 0, false, false)); + assertKeysEquals("1", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_1, 0, false, false)); + assertKeysEquals("2", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_2, 0, false, false)); + assertKeysEquals("3", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_3, 0, false, false)); + assertKeysEquals("4", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_4, 0, false, false)); + assertKeysEquals("5", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_5, 0, false, false)); + assertKeysEquals("6", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_6, 0, false, false)); + assertKeysEquals("7", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_7, 0, false, false)); + assertKeysEquals("8", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_8, 0, false, false)); + assertKeysEquals("9", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_9, 0, false, false)); + assertKeysEquals(",", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_COMMA, 0, false, false)); + assertKeysEquals(".", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_DOT, 0, false, false)); + } + }