-
-
Notifications
You must be signed in to change notification settings - Fork 980
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
Off-by-one error when selecting text #1616
Comments
Just noticed that this could be a duplicate of #945. |
Tried cherry-picking the four patches in martinetd's selection branch (#1007) onto the master branch. They had no effect on the issue I describe in this ticket. |
What's your |
It makes no difference. I tried removing the
Double-click |
I'm also seeing this. I don't think it's a duplicate of #945 because it's not just that it selects the next word too early, but you can also get a selection which doesn't include whole words. E.g. with the text |
Just wanted to clarify my answer to martinetd's question, quoted below:
When I said it did not matter what I put in |
kovidgoyal, thanks for the patch. It changes the way selection works for this issue, but sadly it still doesn't make it possible to include an arbitrary number of non-word characters in the selection. Here's another example:
Double-click on |
Well, yeah. Why would word selection allow you to select non-word |
That's the way it works in xterm, gnome-terminal and konsole (maybe more, didn't bother to check others). It makes sense in my opinion, because when I need to copy a mix of word and non-word characters, I usually want whole words + one or more non-word characters following the word, as shown in my matrix example. Word selection doesn't mean the selection must start and end with word-characters. Also, why change the behavior compared to all(?) other terminal emulators? |
Thanks for the patch. After thinking about it, I agree with @hakonrk though. It would be more practical to be able to control the inclusion of non-word characters, even though I said in my last comment that the selection should go directly from |
OK, I dont see an issue with doing that. |
I have played around with it a little bit, and here's a patch that I've applied on top of 5f33d90. It seems to make kitty do word selection the same as other terminal emulators, but it's barely been tested, and I don't claim to fully understand the code I'm modifying, so it might have some unintended side effects. diff --git a/kitty/screen.c b/kitty/screen.c
index f5f68570..970c61f0 100644
--- a/kitty/screen.c
+++ b/kitty/screen.c
@@ -2013,7 +2013,10 @@ screen_selection_range_for_word(Screen *self, index_type x, index_type *y1, inde
Line *line = visual_line_(self, *y1);
*y2 = *y1;
#define is_ok(x) (is_word_char((line->cpu_cells[x].ch)) || is_opt_word_char(line->cpu_cells[x].ch))
- if (!is_ok(x)) return false;
+ if (!is_ok(x)) {
+ *e = x;
+ return true;
+ }
start = x; end = x;
while(true) {
while(start > 0 && is_ok(start - 1)) start--; |
Should probably also set the start value, |
Umm this is already implemented in master. 9849a69 |
Yes, I noticed that after I had posted it. :) Thanks again for fixing this! 👍 |
After double-clicking a word to start a selection, and growing the selection by moving the mouse cursor beyond the end of the initially selected word, the selection grows to one character beyond the mouse cursor. Example:
Let's say you want to select only
foo[bar]
. You start by double-clicking onfoo
, thereby highlighting only that word (using the defaultselect_by_word_characters
setting). Then you drag the mouse to the closing bracket to also include[bar]
in the selection. The result is that the selection also includes the following=
character. I don't see any way to select onlyfoo[bar]
.The text was updated successfully, but these errors were encountered: