Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix text selection from the panes #53

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

elvankonukseven
Copy link

@elvankonukseven elvankonukseven commented Apr 1, 2025

This PR introduces tips/advice for users when they try selecting text from the panes. Every time a user makes the action of "selection" by clicking and scrolling on text from the panels, a temporary message displays.

The commands for the "selection" action is specific to terminals and this implementation checks for the terminal type to show the appropriate tip.

Addresses issue #44

@elvankonukseven elvankonukseven marked this pull request as ready for review April 1, 2025 21:38
}
"""

# Terminal-specific selection tips
SELECTION_TIPS = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we detect which app we are running and display the relevant tip?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is what is done currently(?)
For the "default" which is the Mac terminal, I haven't figured out the command and I don't think it's possible just with a command, that's why I put a general message for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, sounds good. Do we need to enumerate the shortcuts by hand -- isn't there some api that we can use? I bet there is some way to configure these on the user end...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I unfortunately couldn't find any api... I will definitely keep it in mind for later though

Copy link
Contributor

@Vipul-Cariappa Vipul-Cariappa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. I have left some comments, please have a look.

"Terminal.app": "Option(⌥)+Click to select text",
"iTerm2": "Cmd(⌘)+Shift+C: Copy mode | Option(⌥)+Click: Selection",
"Warp": "Shift+Click to select text",
"default": "Use terminal's selection mechanism to copy text" #default mac terminal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"default": "Use terminal's selection mechanism to copy text" #default mac terminal
"default": "Use terminal's selection mechanism to copy text (Maybe Shift+Click)" #default mac terminal

Does this sound better?


def on_mouse_up(self, event: events.MouseUp) -> None:
"""Reset click state when mouse button is released."""
if hasattr(self, '_clicked'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize self._clicked in __init__. And remove the hasattr.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment on lines 84 to 85
if hasattr(self, '_clicked'):
self._clicked = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Comment on lines 71 to 72
terminal = self._get_terminal_type()
tip = self.SELECTION_TIPS.get(terminal, self.SELECTION_TIPS["default"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be part of __init__. Why recompute this again?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks!

Comment on lines 64 to 65
# Only show tip if we've been clicked and haven't shown a tip yet
if hasattr(self, '_clicked') and self._clicked and not self.tip_shown:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's show the tip multiple times. I will need it, I can't remember anything 😄.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vipul-Cariappa I have tried this by setting tip_shown to false again in on_mouse_up function. The other issue I have is about the tip showing multiple times (depending on the pane I scroll+click). So I get multiple tips(one on top of the other) all showing at the same time. This comes from the fact that each pane initialises its own TextScrollView in DiffDebug. How would you go about this ? I have tried using global variables but it still seems to be attached to each instance of TextScrollView. I thought about maybe moving the tip_shown variable to DiffDebug ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not realise you were modifying TextScrollView. I believe you will have to move all these changes to DiffDebug. It belongs there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks!

@vgvassilev
Copy link
Contributor

I have even more basic question. Why standard copy and paste does not work? Why they are required to different shortcuts?

@vgvassilev
Copy link
Contributor

I have even more basic question. Why standard copy and paste does not work? Why they are required to different shortcuts?

Replying to self: https://textual.textualize.io/FAQ/

apparently the terminal enters in some mode… not sure why that is not the case when you run standard lldb/gdb…

@elvankonukseven
Copy link
Author

@vgvassilev Indeed, it seems adding a tip message is the best way right now. The good news is I found how to do it in the Mac terminal. I'll add it too.

@elvankonukseven
Copy link
Author

elvankonukseven commented Apr 4, 2025

@vgvassilev @Vipul-Cariappa The changes you suggested are implemented. I also display the tip multiple times now. I added the changes to DiffDebug and I added specific commands for vs code and Mac terminals. Vs code config was also about changing the user settings json with this: "terminal.integrated.macOptionClickForcesSelection": true. Not sure if I should add this in the tip ? Afterwards it just works with Opt+click.

Copy link
Contributor

@Vipul-Cariappa Vipul-Cariappa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice Work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants