prompt-toolkit / prompt-toolkit/python-prompt-toolkit
selection mode highlighting is very confusing in my terminal
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
This is with gnome-terminal on Linux, using ipython.
Suppose I have this text:
here is the mark: _ more text
I place my cursor on top of the underscore, and hit control-space, and then move my cursor around to perform various experiments:
What I see after moving my cursor to the left a bit (using [x] to indicate that x is displayed in reverse-font):
here is the mark[:][ ][_] more text
What this means: the text k: _ is selected, and will be cut if I hit control-W. Notice that k is not highlighted.
What I see immediately after hitting control-space, before moving the cursor anywhere:
here is the mark: _ more text
i.e., the cursor has disappeared, and nothing is highlighted. What this means: the text _ is selected, and will be cut if I hit control-W. (NB that in addition to being visually confusing, this is subtly incompatible with what emacs does, cf. #323 -- for emacs, immediately after hitting control-space, the mark and point are both immediately to the left of the character that's under the cursor, and so hitting control-W cuts the empty string.)
What I see after moving the cursor one space in either direction:
here is the mark: [_] more text
What this means: either the text _ (space and the following underscore) or the text _ (underscore and the following space) is selected and will be cut if hit control-W. These cases are visually indistinguishable.
What I see after placing the cursor top of the t at the end of the line:
here is the mark: [_][ ][m][o][r][e][ ][t][e][x]t
What I see after moving the cursor one more space to the right, so that it's actually at the end of the line:
here is the mark: [_][ ][m][o][r][e][ ][t][e][x][t][ ]
i.e. moving the cursor one space to the right apparently causes two extra highlighted spaces to appear. AFAICT these two cases are identical in terms of what's selected: in both cases, hitting control-W will cut the text _ more text (which is not what's visually selected in either case!)
I think maybe there are two underlying bugs here:
- prompt-toolkit should follow emacs and interpreter the mark and point as being placed at the space in between characters, to the left of where the cursor is when control-Space is pressed (for mark) and where the cursor is currently (for point)
- prompt-toolkit's attempt to highlight the selected region by reversing the text colors collides with gnome-terminal's using this same approach to show the cursor. It would be better if prompt toolkit used some more distinctive mechanism for showing the highlight, like perhaps the light grey background that it uses for completion drop-downs.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the selection-mode behavior in gnome-terminal on Linux using ipython, following the cursor movements and control-space cases described here. Investigate the prompt-toolkit selection and terminal highlighting entry points; done means selection boundaries and cut behavior are consistent with the intended emacs semantics and the selected region is visually unambiguous.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100