-
Notifications
You must be signed in to change notification settings - Fork 742
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
Pasting "〽️" in TextArea Moves Cursor Too Far #4694
Comments
Just to test a theory, could you try pasting this version of the emoji instead?
This was generated with |
This works: Pasting |
When you paste 〽️, you're pasting 2 codepoints into the TextArea. When you press backspace after this, you're only deleting the second codepoint. The 🏴 emoji, for example, contains 7 codepoints, so you'd need backspace 7 times to delete them all. This aligns with how VSCode and PyCharm behave too. Python 3.11.8 (main, Apr 25 2024, 11:02:29) [Clang 13.0.0 (clang-1300.0.27.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> len("🏴")
7
>>> len("〽️")
2
>>> len("🌴")
1 |
This makes sense to me now, thank you. Indeed, also Vim and Neovim insert seven columns with What do you think? Will there be a way for |
Do you mean you're seeing some kind of visual glitch too? I'm unsure if that's what you mean by "skew". Could you post a screenshot if so? |
With "skew" I just mean the difference between the insertion of 1 emoji and the resulting displacement of the cursor by potentially more than 1 cell, in any editor. Sorry for being unclear on that. In the case of I mean, this is a minor issue after all. It's a bit weird to me having to press What is your view on that? |
I think you've already summed it up nicely:
If Microsoft haven't figured out how to treat emoji sequences as single clusters in VSCode, perhaps this is a bit much to expect from Textual? |
I have high hopes I won't close this issue myself because I would really like to see this feature implemented, but I am also happy with you closing this as "won't implement". Feel free 🙂 Thank you both for your quick replies, @TomJGooding and @darrenburns. Always nice to see. 🥇 |
To do this we'd probably need to introduce a new dependency for segmenting text into grapheme clusters, e.g. https://uniseg-py.readthedocs.io/en/latest/graphemecluster.html. As mentioned though, you're unlikely to see this any time soon inside Textual itself as it's pretty low priority. If you really want this, it might not be too difficult to do it in a subclass of TextArea (and overwriting the "cursor left/right" and "delete left/right" actions to make use of the library linked above (specifically this). I don't have the bandwidth to look into the exact code that would be required, but I'm happy to give a bit of guidance/pointers if you try it in a subclass. |
Cool, thanks ❤️ |
Hi! 👋
Problem
After pasting
〽️
inTextArea
, the selection is moved too far and I need to pressBackspace
twice (instead of once) to delete it.Probably other emojis also cause this, but I have not tested this.
I tried to dive into the code, but unfortunately could not find where to fix this.
Example
Starting with a blank
TextArea
, the selection is given with(start, end) == ((0, 0), (0, 0))
.Inserting
a
would give(start, end) == ((0, 1), (0, 1))
, as expected.Inserting
🌴
("palm tree") would also give(start, end) == ((0, 1), (0, 1))
. Nice.However, pasting
〽️
("part alternation mark") sets the selection to(start, end) == ((0, 2), (0, 2))
.Test Script
Test Script
Textual Diagnostics
Textual Diagnostics
Versions
Python
Operating System
Terminal
Rich Console options
The text was updated successfully, but these errors were encountered: