gtktextview: Invoke OSK on button/touch taps that move/undo selection

If the ::release handler is invoked, the press/release happened without
drags in between. Additionally check that there is no selection at all.

This makes OSK invoked on taps that move the caret around, while tapping
in the selection invokes edition popup and text handles without bringing
in the OSK.
This commit is contained in:
Carlos Garnacho 2022-11-27 13:20:02 +01:00
parent ed81c265ac
commit 6cbb7b848a

View File

@ -40,6 +40,7 @@
#include "gtkrenderbackgroundprivate.h"
#include "gtksettings.h"
#include "gtktextiterprivate.h"
#include "gtkimcontextprivate.h"
#include "gtkimmulticontext.h"
#include "gtkprivate.h"
#include "gtktextutilprivate.h"
@ -410,10 +411,15 @@ static void gtk_text_view_state_flags_changed (GtkWidget *widget,
GtkStateFlags previous_state);
static void gtk_text_view_click_gesture_pressed (GtkGestureClick *gesture,
int n_press,
double x,
double y,
GtkTextView *text_view);
int n_press,
double x,
double y,
GtkTextView *text_view);
static void gtk_text_view_click_gesture_released (GtkGestureClick *gesture,
int n_press,
double x,
double y,
GtkTextView *text_view);
static void gtk_text_view_drag_gesture_update (GtkGestureDrag *gesture,
double offset_x,
double offset_y,
@ -1965,6 +1971,9 @@ gtk_text_view_init (GtkTextView *text_view)
g_signal_connect (gesture, "pressed",
G_CALLBACK (gtk_text_view_click_gesture_pressed),
widget);
g_signal_connect (gesture, "released",
G_CALLBACK (gtk_text_view_click_gesture_released),
widget);
gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (gesture));
priv->drag_gesture = gtk_gesture_drag_new ();
@ -5702,6 +5711,25 @@ gtk_text_view_click_gesture_pressed (GtkGestureClick *gesture,
gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture));
}
static void
gtk_text_view_click_gesture_released (GtkGestureClick *gesture,
int n_press,
double x,
double y,
GtkTextView *text_view)
{
GtkTextViewPrivate *priv = text_view->priv;
GtkTextBuffer *buffer;
GtkTextIter start, end;
buffer = get_buffer (text_view);
gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
if (gtk_text_iter_compare (&start, &end) == 0 &&
gtk_text_iter_can_insert (&start, priv->editable))
gtk_im_context_activate_osk (priv->im_context);
}
static void
direction_changed (GdkDevice *device,
GParamSpec *pspec,