@@ -611,11 +611,12 @@ public boolean onTouchEvent(MotionEvent event) {
611611 updateFloatingToolbarVisibility (event );
612612 mGestureRecognizer .onTouchEvent (event );
613613 return true ;
614- } else if (event .isFromSource (InputDevice .SOURCE_MOUSE )) {
615- if (event .isButtonPressed (MotionEvent .BUTTON_SECONDARY )) {
614+ // vvv THIS IS THE CORRECTED LINE vvv
615+ } else if (event .isFromSource (InputDevice .SOURCE_MOUSE ) || event .isFromSource (InputDevice .SOURCE_TOUCHSCREEN )) {
616+ if (event .isFromSource (InputDevice .SOURCE_MOUSE ) && event .isButtonPressed (MotionEvent .BUTTON_SECONDARY )) {
616617 if (action == MotionEvent .ACTION_DOWN ) showContextMenu ();
617618 return true ;
618- } else if (event .isButtonPressed (MotionEvent .BUTTON_TERTIARY )) {
619+ } else if (event .isFromSource ( InputDevice . SOURCE_MOUSE ) && event . isButtonPressed (MotionEvent .BUTTON_TERTIARY )) {
619620 ClipboardManager clipboardManager = (ClipboardManager ) getContext ().getSystemService (Context .CLIPBOARD_SERVICE );
620621 ClipData clipData = clipboardManager .getPrimaryClip ();
621622 if (clipData != null ) {
@@ -636,6 +637,40 @@ public boolean onTouchEvent(MotionEvent event) {
636637 break ;
637638 }
638639 }
640+ else { // Mouse tracking is OFF, handle for the shell
641+ if (event .getAction () == MotionEvent .ACTION_DOWN ) {
642+ // --- FINAL 1D LOGIC ---
643+ // Get target row and column from the click
644+ int [] targetCoords = getColumnAndRow (event , false );
645+ int targetColumn = targetCoords [0 ];
646+ int targetRow = targetCoords [1 ];
647+
648+ // Get cursor's current visual position
649+ int currentRow = mEmulator .getCursorRow ();
650+ int currentColumn = mEmulator .getCursorCol ();
651+
652+ // Get the width of the terminal in characters
653+ int terminalWidth = mEmulator .mColumns ;
654+
655+ // Calculate the 1D index for both the click position and the cursor position.
656+ // This treats the multi-line input as a single long line of text.
657+ int targetIndex = (targetRow * terminalWidth ) + targetColumn ;
658+ int currentIndex = (currentRow * terminalWidth ) + currentColumn ;
659+
660+ int diff = targetIndex - currentIndex ;
661+
662+ // --- Now, only send Left or Right commands ---
663+ if (diff > 0 ) { // Need to move right
664+ for (int i = 0 ; i < diff ; i ++) {
665+ handleKeyCode (android .view .KeyEvent .KEYCODE_DPAD_RIGHT , 0 );
666+ }
667+ } else if (diff < 0 ) { // Need to move left
668+ for (int i = 0 ; i < -diff ; i ++) {
669+ handleKeyCode (android .view .KeyEvent .KEYCODE_DPAD_LEFT , 0 );
670+ }
671+ }
672+ }
673+ }
639674 }
640675
641676 mGestureRecognizer .onTouchEvent (event );
0 commit comments