mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 10:45:23 +08:00
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:
@@ -13,8 +13,8 @@ android {
|
|||||||
applicationId "com.termux"
|
applicationId "com.termux"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 24
|
targetSdkVersion 24
|
||||||
versionCode 36
|
versionCode 37
|
||||||
versionName "0.35"
|
versionName "0.37"
|
||||||
|
|
||||||
ndk {
|
ndk {
|
||||||
moduleName "libtermux"
|
moduleName "libtermux"
|
||||||
|
@@ -3,6 +3,7 @@ package com.termux.app;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
@@ -54,16 +55,12 @@ public final class TermuxKeyListener implements TerminalKeyListener {
|
|||||||
mActivity.getDrawer().setDrawerLockMode(copyMode ? DrawerLayout.LOCK_MODE_LOCKED_CLOSED : DrawerLayout.LOCK_MODE_UNLOCKED);
|
mActivity.getDrawer().setDrawerLockMode(copyMode ? DrawerLayout.LOCK_MODE_LOCKED_CLOSED : DrawerLayout.LOCK_MODE_UNLOCKED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void returnOnFinishedSession(TerminalSession currentSession) {
|
||||||
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.
|
// Return pressed with finished session - remove it.
|
||||||
currentSession.finishIfRunning();
|
currentSession.finishIfRunning();
|
||||||
|
|
||||||
|
TermuxService service = mActivity.mTermService;
|
||||||
|
|
||||||
int index = service.removeTermSession(currentSession);
|
int index = service.removeTermSession(currentSession);
|
||||||
mActivity.mListViewAdapter.notifyDataSetChanged();
|
mActivity.mListViewAdapter.notifyDataSetChanged();
|
||||||
if (mActivity.mTermService.getSessions().isEmpty()) {
|
if (mActivity.mTermService.getSessions().isEmpty()) {
|
||||||
@@ -75,6 +72,14 @@ public final class TermuxKeyListener implements TerminalKeyListener {
|
|||||||
}
|
}
|
||||||
mActivity.switchToSession(service.getSessions().get(index));
|
mActivity.switchToSession(service.getSessions().get(index));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession currentSession) {
|
||||||
|
if (handleVirtualKeys(keyCode, e, true)) return true;
|
||||||
|
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_ENTER && !currentSession.isRunning()) {
|
||||||
|
returnOnFinishedSession(currentSession);
|
||||||
return true;
|
return true;
|
||||||
} else if (e.isCtrlPressed() && e.isShiftPressed()) {
|
} else if (e.isCtrlPressed() && e.isShiftPressed()) {
|
||||||
// Get the unmodified code point:
|
// Get the unmodified code point:
|
||||||
@@ -111,6 +116,7 @@ public final class TermuxKeyListener implements TerminalKeyListener {
|
|||||||
mActivity.changeFontSize(false);
|
mActivity.changeFontSize(false);
|
||||||
} else if (unicodeChar >= '1' && unicodeChar <= '9') {
|
} else if (unicodeChar >= '1' && unicodeChar <= '9') {
|
||||||
int num = unicodeChar - '1';
|
int num = unicodeChar - '1';
|
||||||
|
TermuxService service = mActivity.mTermService;
|
||||||
if (service.getSessions().size() > num)
|
if (service.getSessions().size() > num)
|
||||||
mActivity.switchToSession(service.getSessions().get(num));
|
mActivity.switchToSession(service.getSessions().get(num));
|
||||||
}
|
}
|
||||||
@@ -237,6 +243,11 @@ public final class TermuxKeyListener implements TerminalKeyListener {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (ctrlDown) {
|
} else if (ctrlDown) {
|
||||||
|
if (codePoint == 106 /* Ctrl+j or \n */ && !session.isRunning()) {
|
||||||
|
returnOnFinishedSession(session);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
List<TermuxPreferences.KeyboardShortcut> shortcuts = mActivity.mSettings.shortcuts;
|
List<TermuxPreferences.KeyboardShortcut> shortcuts = mActivity.mSettings.shortcuts;
|
||||||
if (!shortcuts.isEmpty()) {
|
if (!shortcuts.isEmpty()) {
|
||||||
for (int i = shortcuts.size() - 1; i >= 0; i--) {
|
for (int i = shortcuts.size() - 1; i >= 0; i--) {
|
||||||
|
Reference in New Issue
Block a user