feat(view): Enable mouse cursor movement in shell readline
This pull request adds support for moving the cursor within a long command in the shell by clicking with a mouse or tapping on the touchscreen. This makes editing multi-line commands significantly easier and faster.
How it Works The implementation works by:
Intercepting ACTION_DOWN events from both mice and touchscreens in TerminalView.
Calculating a 1D character index for both the click location and the current cursor position, correctly handling multi-line wrapping.
Sending the appropriate number of left or right arrow keypress events (KEYCODE_DPAD_LEFT/RIGHT) via the existing handleKeyCode() method to move the cursor to the target location.
This approach ensures that the cursor movement is handled by the underlying readline library, behaving exactly like physical keypresses.
https://github.com/user-attachments/assets/b6df9415-c855-4156-a661-59040b586d53
Closes #4748
@TomJo2000 kindly look into this PR.
@obfusk @fornwall @agnostic-apollo @ayoubelmhamdi Kindly look into the PR.
@ankitkrshah30
Recording2.mp4
from the video, i saw the experience will be more awful than i expected before, because we always make wrong presses while using touch screen, but the cursor will be moved to the first character in the first line, we should think about it, after people use this feature.
Hi, Thank you for the excellent feedback on the user experience. I've pushed an update that adds a boundary check to the logic. The cursor now only moves when clicking directly on the command's text, and accidental taps on empty areas are safely ignored. Here is a new video demonstrating the final, improved behavior:
the improved version: https://github.com/user-attachments/assets/4527774b-80c2-449c-bddc-a8596d4ea860
the issue part: https://github.com/user-attachments/assets/56c17cf3-9e32-4635-b856-ec62054e62c0
@ayoubelmhamdi
Hi, just a quick follow-up to note that I've updated the PR with the requested fixes. I'm also participating in Hacktoberfest, so I'd appreciate it if this contribution could be considered when you have time. Thanks for maintaining this great project!
Hi, I appreciate the value of this idea and I believe it would be useful for some people, however, I have two requests:
Even though I have many years of experience with terminal emulators, I have never personally seen any terminal emulator on desktop PC that implements this feature.
Because of that, I believe it should not be the default behavior, but should be configurable to be enabled by a setting in the Termux App "Settings" menu.
If it's not inconvenient for you to do this additional work, could you please try the following steps?
- Try to adjust this so that it is disabled by default, but can be optionally enabled by a setting toggle in the "Settings" that come from holding down long press on the screen and selecting "more" and "settings" (and it should still be possible to return to the Settings the same way and disable it again after it has been enabled!)
- Try to find and show me a terminal emulator for laptop and desktop PC that you like which has the same feature, so that I can compare your implementation with it, especially its behavior when used on Touchscreen Ubuntu Tablets, compared to your implementation for Touchscreen Android Phones.
Hi,
I've pushed the final updates. The feature is now controlled by an on/off switch in the settings, as requested. I've also added the boundary check to prevent the cursor from jumping on accidental taps in empty areas.
Here is a new video demonstrating the final behavior, including the settings toggle:
https://github.com/user-attachments/assets/fb9917a0-29f8-468c-87c3-0db7f5e54045
I'm also participating in Hacktoberfest, so I'd be grateful if this contribution could be considered for the event.
Thank you again for all your guidance! @robertkirkman
Hi @twaik and @robertkirkman,
Thanks so much for the detailed feedback!
You're right, @twaik, my calculation logic is too simple and will break. I'd love to fix it, but I'm not sure of the best way to map the screen coordinates to the shell's command buffer. If you have any suggestions on the right approach, I'd really appreciate it!
And thanks, @robertkirkman, for the testing and for the context on the settings. I'm happy to implement the setting however the team decides is best.
I'll hold off on pushing more code until I hear your thoughts on the calculation fix. Thanks again!
@TomJo2000 @twaik @robertkirkman any info
Neither of us 3 merge pull requests in this repository.
can you help me if to know if any changes required. or if someone who can take this serious..
There are many PRs waiting in order before this PR. The people who can merge PRs in this repository will be busy with all of the other ones before they reach this one.
Hi, sorry about late reply, I am busy with termux-app rewrite and won't be merging any pulls before that, and as robert said some more important PRs will take precedence even after I finish rewrite and push. And this cannot be merged anyways before rewrite as it needs changes to properties, which conflict with my local rewrite changes. Additionally, such changes for mouse tracking in terminal will need to be looked into carefully to not break things and whether it is viable to merge, and whether issues above for ncurses can be solved. That will take time, I am also not very familiar with mouse related implementation in terminal, so will need to research first too. So I cannot give you any immediate timeline for merging this, sorry.