|
3 | 3 | import android.content.Context;
|
4 | 4 | import android.media.AudioManager;
|
5 | 5 | import android.support.v4.widget.DrawerLayout;
|
| 6 | +import android.util.Log; |
6 | 7 | import android.view.Gravity;
|
7 | 8 | import android.view.InputDevice;
|
8 | 9 | import android.view.KeyEvent;
|
@@ -54,27 +55,31 @@ public void copyModeChanged(boolean copyMode) {
|
54 | 55 | mActivity.getDrawer().setDrawerLockMode(copyMode ? DrawerLayout.LOCK_MODE_LOCKED_CLOSED : DrawerLayout.LOCK_MODE_UNLOCKED);
|
55 | 56 | }
|
56 | 57 |
|
| 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 | + |
57 | 77 | @Override
|
58 | 78 | public boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession currentSession) {
|
59 | 79 | if (handleVirtualKeys(keyCode, e, true)) return true;
|
60 | 80 |
|
61 |
| - TermuxService service = mActivity.mTermService; |
62 |
| - |
63 | 81 | 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); |
78 | 83 | return true;
|
79 | 84 | } else if (e.isCtrlPressed() && e.isShiftPressed()) {
|
80 | 85 | // Get the unmodified code point:
|
@@ -111,6 +116,7 @@ public boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession currentSession
|
111 | 116 | mActivity.changeFontSize(false);
|
112 | 117 | } else if (unicodeChar >= '1' && unicodeChar <= '9') {
|
113 | 118 | int num = unicodeChar - '1';
|
| 119 | + TermuxService service = mActivity.mTermService; |
114 | 120 | if (service.getSessions().size() > num)
|
115 | 121 | mActivity.switchToSession(service.getSessions().get(num));
|
116 | 122 | }
|
@@ -237,6 +243,11 @@ public boolean onCodePoint(final int codePoint, boolean ctrlDown, TerminalSessio
|
237 | 243 | }
|
238 | 244 | return true;
|
239 | 245 | } else if (ctrlDown) {
|
| 246 | + if (codePoint == 106 /* Ctrl+j or \n */ && !session.isRunning()) { |
| 247 | + returnOnFinishedSession(session); |
| 248 | + return true; |
| 249 | + } |
| 250 | + |
240 | 251 | List<TermuxPreferences.KeyboardShortcut> shortcuts = mActivity.mSettings.shortcuts;
|
241 | 252 | if (!shortcuts.isEmpty()) {
|
242 | 253 | for (int i = shortcuts.size() - 1; i >= 0; i--) {
|
|
0 commit comments