Fix Enter to finish session in more cases

Detect the Enter key to finish a session not only on KeyEvent:s,
but also when the IME uses InputConnection.commitText() to send
\n. This seems to be triggered more after switching to the Uri
input type. Closes #124

Also bump app version for a quick release.
This commit is contained in:
Fredrik Fornwall 2016-08-01 06:37:49 +02:00
parent eaeb0930f4
commit a73228b109
2 changed files with 29 additions and 18 deletions

View File

@ -13,8 +13,8 @@ android {
applicationId "com.termux"
minSdkVersion 21
targetSdkVersion 24
versionCode 36
versionName "0.35"
versionCode 37
versionName "0.37"
ndk {
moduleName "libtermux"

View File

@ -3,6 +3,7 @@ package com.termux.app;
import android.content.Context;
import android.media.AudioManager;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Gravity;
import android.view.InputDevice;
import android.view.KeyEvent;
@ -54,27 +55,31 @@ public final class TermuxKeyListener implements TerminalKeyListener {
mActivity.getDrawer().setDrawerLockMode(copyMode ? DrawerLayout.LOCK_MODE_LOCKED_CLOSED : DrawerLayout.LOCK_MODE_UNLOCKED);
}
private void returnOnFinishedSession(TerminalSession currentSession) {
// Return pressed with finished session - remove it.
currentSession.finishIfRunning();
TermuxService service = mActivity.mTermService;
int index = service.removeTermSession(currentSession);
mActivity.mListViewAdapter.notifyDataSetChanged();
if (mActivity.mTermService.getSessions().isEmpty()) {
// There are no sessions to show, so finish the activity.
mActivity.finish();
} else {
if (index >= service.getSessions().size()) {
index = service.getSessions().size() - 1;
}
mActivity.switchToSession(service.getSessions().get(index));
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession currentSession) {
if (handleVirtualKeys(keyCode, e, true)) return true;
TermuxService service = mActivity.mTermService;
if (keyCode == KeyEvent.KEYCODE_ENTER && !currentSession.isRunning()) {
// Return pressed with finished session - remove it.
currentSession.finishIfRunning();
int index = service.removeTermSession(currentSession);
mActivity.mListViewAdapter.notifyDataSetChanged();
if (mActivity.mTermService.getSessions().isEmpty()) {
// There are no sessions to show, so finish the activity.
mActivity.finish();
} else {
if (index >= service.getSessions().size()) {
index = service.getSessions().size() - 1;
}
mActivity.switchToSession(service.getSessions().get(index));
}
returnOnFinishedSession(currentSession);
return true;
} else if (e.isCtrlPressed() && e.isShiftPressed()) {
// Get the unmodified code point:
@ -111,6 +116,7 @@ public final class TermuxKeyListener implements TerminalKeyListener {
mActivity.changeFontSize(false);
} else if (unicodeChar >= '1' && unicodeChar <= '9') {
int num = unicodeChar - '1';
TermuxService service = mActivity.mTermService;
if (service.getSessions().size() > num)
mActivity.switchToSession(service.getSessions().get(num));
}
@ -237,6 +243,11 @@ public final class TermuxKeyListener implements TerminalKeyListener {
}
return true;
} else if (ctrlDown) {
if (codePoint == 106 /* Ctrl+j or \n */ && !session.isRunning()) {
returnOnFinishedSession(session);
return true;
}
List<TermuxPreferences.KeyboardShortcut> shortcuts = mActivity.mSettings.shortcuts;
if (!shortcuts.isEmpty()) {
for (int i = shortcuts.size() - 1; i >= 0; i--) {