Skip to content

Commit a73228b

Browse files
committed
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.
1 parent eaeb093 commit a73228b

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ android {
1313
applicationId "com.termux"
1414
minSdkVersion 21
1515
targetSdkVersion 24
16-
versionCode 36
17-
versionName "0.35"
16+
versionCode 37
17+
versionName "0.37"
1818

1919
ndk {
2020
moduleName "libtermux"

app/src/main/java/com/termux/app/TermuxKeyListener.java

+27-16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Context;
44
import android.media.AudioManager;
55
import android.support.v4.widget.DrawerLayout;
6+
import android.util.Log;
67
import android.view.Gravity;
78
import android.view.InputDevice;
89
import android.view.KeyEvent;
@@ -54,27 +55,31 @@ public void copyModeChanged(boolean copyMode) {
5455
mActivity.getDrawer().setDrawerLockMode(copyMode ? DrawerLayout.LOCK_MODE_LOCKED_CLOSED : DrawerLayout.LOCK_MODE_UNLOCKED);
5556
}
5657

58+
private void returnOnFinishedSession(TerminalSession currentSession) {
59+
// Return pressed with finished session - remove it.
60+
currentSession.finishIfRunning();
61+
62+
TermuxService service = mActivity.mTermService;
63+
64+
int index = service.removeTermSession(currentSession);
65+
mActivity.mListViewAdapter.notifyDataSetChanged();
66+
if (mActivity.mTermService.getSessions().isEmpty()) {
67+
// There are no sessions to show, so finish the activity.
68+
mActivity.finish();
69+
} else {
70+
if (index >= service.getSessions().size()) {
71+
index = service.getSessions().size() - 1;
72+
}
73+
mActivity.switchToSession(service.getSessions().get(index));
74+
}
75+
}
76+
5777
@Override
5878
public boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession currentSession) {
5979
if (handleVirtualKeys(keyCode, e, true)) return true;
6080

61-
TermuxService service = mActivity.mTermService;
62-
6381
if (keyCode == KeyEvent.KEYCODE_ENTER && !currentSession.isRunning()) {
64-
// Return pressed with finished session - remove it.
65-
currentSession.finishIfRunning();
66-
67-
int index = service.removeTermSession(currentSession);
68-
mActivity.mListViewAdapter.notifyDataSetChanged();
69-
if (mActivity.mTermService.getSessions().isEmpty()) {
70-
// There are no sessions to show, so finish the activity.
71-
mActivity.finish();
72-
} else {
73-
if (index >= service.getSessions().size()) {
74-
index = service.getSessions().size() - 1;
75-
}
76-
mActivity.switchToSession(service.getSessions().get(index));
77-
}
82+
returnOnFinishedSession(currentSession);
7883
return true;
7984
} else if (e.isCtrlPressed() && e.isShiftPressed()) {
8085
// Get the unmodified code point:
@@ -111,6 +116,7 @@ public boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession currentSession
111116
mActivity.changeFontSize(false);
112117
} else if (unicodeChar >= '1' && unicodeChar <= '9') {
113118
int num = unicodeChar - '1';
119+
TermuxService service = mActivity.mTermService;
114120
if (service.getSessions().size() > num)
115121
mActivity.switchToSession(service.getSessions().get(num));
116122
}
@@ -237,6 +243,11 @@ public boolean onCodePoint(final int codePoint, boolean ctrlDown, TerminalSessio
237243
}
238244
return true;
239245
} else if (ctrlDown) {
246+
if (codePoint == 106 /* Ctrl+j or \n */ && !session.isRunning()) {
247+
returnOnFinishedSession(session);
248+
return true;
249+
}
250+
240251
List<TermuxPreferences.KeyboardShortcut> shortcuts = mActivity.mSettings.shortcuts;
241252
if (!shortcuts.isEmpty()) {
242253
for (int i = shortcuts.size() - 1; i >= 0; i--) {

0 commit comments

Comments
 (0)