After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 780750 - Shift + click in GtkEntry doesn't select
Shift + click in GtkEntry doesn't select
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkEntry
3.22.x
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2017-03-31 09:23 UTC by akurtakov
Modified: 2017-08-30 17:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Entry: Fix Shift-click → extend/truncate selection (4.74 KB, patch)
2017-08-05 22:55 UTC, Daniel Boles
committed Details | Review

Description akurtakov 2017-03-31 09:23:06 UTC
GtkTextView properly selects but with GtkEntry nothing happens. This used to work with Gtk 2.24.
Comment 1 akurtakov 2017-03-31 09:32:35 UTC
Properly selects means the test between cursor location and click location are selected.
Comment 2 akurtakov 2017-03-31 09:33:20 UTC
Obviously it's text not test.
Comment 3 Daniel Boles 2017-08-04 13:00:50 UTC
presumably broken by commit e580c29f07f42fb171264a97389a18a2a7cdb3cd changing from button-press events to gestures
Comment 4 Daniel Boles 2017-08-04 14:05:50 UTC
Also not working is the "Truncate current selection, but keep it as big as possible" behaviour.


I suspect a comparison is inverted somewhere, but that's just based on a quick glance and is probably totally wrong
Comment 5 Daniel Boles 2017-08-05 19:05:42 UTC
perhaps relevant: GTK+ 4 not only doesn't work here, but also emits a display beep when you try to select this way
Comment 6 Daniel Boles 2017-08-05 21:10:57 UTC
...which is due to the IM context thinking that the release of the Shift key represents the end of a key sequence, which failed.
Comment 7 Daniel Boles 2017-08-05 21:13:15 UTC
The beep occurs on current GTK+ 3 too. My guess is that it might be related to the recent commit adding support for entry of emoji sequences, though I haven't bisected this yet.
Comment 8 Daniel Boles 2017-08-05 22:55:04 UTC
Created attachment 357036 [details] [review]
Entry: Fix Shift-click → extend/truncate selection

Since the move from button-press to gesture events, Shift-clicking did
not work to start a selection (from none) or truncate an existing one.

This was due to the code being copy-pasted around and some logic being
broken in the process. This makes both of those work as they should, by
shuffling it again so the end result is the same as before. Highlights:

(1) ::button-press if extending due to a single press would call
set_positions(tmp_pos, tmp_pos), which is what made the Shift+click to
create a selection work. That was lost. Add it back to make that work.

(2) ::button-press in the “Truncate current selection” branch would not
execute all the stuff around “extend_to_left”, as that was the else
case. So, set extend_selection = FALSE so we skip over that later on.

(3) BUT! This Truncate case never fired because it was in the else
branch of if (in_selection())! Of course, it must be in the true branch.

(4) The IM context was not reset if the Shift-click occurred within an
existing selection, only if it did not. In ::button-press this was the
first thing done if extending a selection, regardless. Make it so again.
Comment 9 Daniel Boles 2017-08-07 18:31:28 UTC
Hi Carlos, any thoughts? :)
Comment 10 Daniel Boles 2017-08-30 11:43:52 UTC
Carlos had an alternative patch but said on IRC the way I do it made sense (plus, mine ensures the IM context is always reset, which his didn't, iirc). So, I'll probably go for it, so we can get this important feature fixed in 3.22.20.

It may be possible to shuffle this all around again to read more nicely, so it can always be refactored, but it's more important just to get the feature working again first, and afaict I exactly restore the old behaviour with minimal changes.
Comment 11 Carlos Garnacho 2017-08-30 15:52:41 UTC
Review of attachment 357036 [details] [review]:

Yes, my patch didn't try to address the IM context issue. The code shuffling in your patch also makes sense, so let's go with your changes instead.

One minor nit with the patch, AFAIK there's no specific codestyle for separating cases on a switch statement, so I'd maybe leave the extra newlines out, as it's not like the current code is breaking any style.
Comment 12 Daniel Boles 2017-08-30 16:02:44 UTC
Thanks for the review!

(In reply to Carlos Garnacho from comment #11)
> One minor nit with the patch, AFAIK there's no specific codestyle for
> separating cases on a switch statement, so I'd maybe leave the extra
> newlines out, as it's not like the current code is breaking any style.

docs/CODING_STYLE says:

> It is preferable, though not mandatory, to separate the various cases with
> a newline

At the time, I wasn't consciously aware of that, and based my decision on how (A) I was in the area and (B) several other large switch statements in the source file do have blank lines between their break/case labels already, and it seemed nice to follow this and gain readability while I was there.
Comment 13 Daniel Boles 2017-08-30 17:26:27 UTC
Attachment 357036 [details] pushed as 6e414d4 - Entry: Fix Shift-click → extend/truncate selection
Comment 14 Daniel Boles 2017-08-30 17:34:31 UTC
Thanks for the report!