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

Shift+Click selection starts from last mouse click instead of cursor position #2639

Open
rkagerer opened this issue Feb 5, 2023 · 6 comments · May be fixed by #2768
Open

Shift+Click selection starts from last mouse click instead of cursor position #2639

rkagerer opened this issue Feb 5, 2023 · 6 comments · May be fixed by #2768
Milestone

Comments

@rkagerer
Copy link

rkagerer commented Feb 5, 2023

If I hold down SHIFT and then left-click somewhere in my code, my expectation is that it should highlight all of the text between the current cursor position and where I've clicked.

Instead, it highlights the text between where I've just clicked, and the last place I clicked before that. i.e. It thinks the current cursor position is still located where I last dropped it using the mouse, when in fact I could have moved the cursor using the keyboard since that time.

To reproduce:

  1. Click anywhere in your code
  2. Move the cursor using the keyboard (e.g. arrow buttons)
  3. Hold Shift and click somewhere else in your code
  4. Observe the highlight begins from where you clicked in step 1, rather than where you placed the cursor in step 2.

If you need more specific steps to reproduce, try this:

  1. Paste the following code into a Thonny editor window (e.g. main.py):
a = 1
b = 2
c = a + b
d = a + b + c
  1. Left-click on the third line, just after the "a"
  2. Press HOME, or press the left arrow 5 times, to move the cursor to the beginning of that line. (Don't use the mouse for this step!)
  3. Hold down your left SHIFT button, and while holding it, click the end of the very last line.
  4. Observe that even though you clearly intended to select the full contents of the final two lines, the highlight only grabbed part of the third line.

Repeat the above steps in any other text editor (e.g. Notepad, a Chrome TEXTAREA, etc) to see the more intuitive way it should function.

Note this was tested using Thonny 4.0.2 on Windows 7.

This is my first Thonny bug report, please be gentle and forgive me if I didn't fill out the correct template or whatever.

EDIT: I think this might also explain the cause of Issue #912

@aivarannamaa
Copy link
Member

Thank you for this thorough report and sorry for the late reply!

I could reproduce this, but I'm afraid the problem is in the UI widget I've used, so it is not straightforward to fix. I'm considering moving to a new UI toolkit, so I'll postpone this issue for now.

@aivarannamaa aivarannamaa added this to the 4.1 milestone Feb 11, 2023
@mrexodia
Copy link
Contributor

mrexodia commented May 2, 2023

Investigating this a bit and I found something that could solve this while keeping tk: https://wiki.tcl-lang.org/page/Modern+Bindings+for+the+Text+Widget. Will investigate more and see if I can get this to work somehow.

@mrexodia mrexodia linked a pull request May 2, 2023 that will close this issue
@mrexodia
Copy link
Contributor

mrexodia commented May 2, 2023

Managed to get it to work! Obviously this needs more testing to check for other side effects (maybe an experimental option?). Because I don't know Tcl I wanted to avoid rewriting modernText in Python. I found if you use tk.evalfile during startup you can use self.bindtags to reuse the origin Tcl code.

@mrexodia
Copy link
Contributor

mrexodia commented May 2, 2023

If someone wants to try this locally for the 4.0.2 release, look for workbench.py in your installation (on Windows this is in %LocalAppData%\Programs\Thonny\Lib\site-packages\thonny) and replace workbench.py, tktexttext.py and add res\modernText.tcl from the attached ZIP file.

thonny-modernText-4.0.2.zip

@rkagerer
Copy link
Author

rkagerer commented May 2, 2023

Thanks @mrexodia for taking a crack at this. I tried it out, it loaded up under 4.0.2 on Windows OK.

It fixes the behavior of the selection when holding SHIFT, but breaks it when not holding SHIFT. To reproduce, use similar steps as above, but after step 3, try to highlight a new section of the document without holding down SHIFT and you'll see what I mean. It's treating the old cursor point as the start of your selection.

@mrexodia
Copy link
Contributor

mrexodia commented May 2, 2023

I see. Unfortunately I don’t know Tcl, but there might be an improved version of modernText out there that handles it (this version is from 2007). I also found that autocomplete wasn’t working (pressing Ctrl+Space), but I don’t know if it ever did.

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

Successfully merging a pull request may close this issue.

3 participants