mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 01:20:42 -05:00
clutter: Enable negative offsets in delete surrounding text
The input method can assign a negative value to clutter_input_method_delete_surrounding() to move the cursor to the left. But Wayland protocol accepts positive values in delete_surrounding() and GTK converts the values to the negative ones in text_input_delete_surrounding_text_apply(). https://gitlab.gnome.org/GNOME/mutter/issues/539
This commit is contained in:
parent
9f31e7252c
commit
2cfdbbd730
@ -29,7 +29,7 @@ void clutter_input_focus_focus_out (ClutterInputFocus *focus);
|
||||
void clutter_input_focus_commit (ClutterInputFocus *focus,
|
||||
const gchar *text);
|
||||
void clutter_input_focus_delete_surrounding (ClutterInputFocus *focus,
|
||||
guint offset,
|
||||
int offset,
|
||||
guint len);
|
||||
void clutter_input_focus_request_surrounding (ClutterInputFocus *focus);
|
||||
|
||||
|
@ -217,7 +217,7 @@ clutter_input_focus_commit (ClutterInputFocus *focus,
|
||||
|
||||
void
|
||||
clutter_input_focus_delete_surrounding (ClutterInputFocus *focus,
|
||||
guint offset,
|
||||
int offset,
|
||||
guint len)
|
||||
{
|
||||
g_return_if_fail (CLUTTER_IS_INPUT_FOCUS (focus));
|
||||
|
@ -41,7 +41,7 @@ struct _ClutterInputFocusClass
|
||||
|
||||
void (* request_surrounding) (ClutterInputFocus *focus);
|
||||
void (* delete_surrounding) (ClutterInputFocus *focus,
|
||||
guint offset,
|
||||
int offset,
|
||||
guint len);
|
||||
void (* commit_text) (ClutterInputFocus *focus,
|
||||
const gchar *text);
|
||||
|
@ -168,7 +168,7 @@ clutter_input_method_class_init (ClutterInputMethodClass *klass)
|
||||
G_TYPE_FROM_CLASS (object_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0, NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
|
||||
G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_UINT);
|
||||
signals[REQUEST_SURROUNDING] =
|
||||
g_signal_new ("request-surrounding",
|
||||
G_TYPE_FROM_CLASS (object_class),
|
||||
@ -292,7 +292,7 @@ clutter_input_method_commit (ClutterInputMethod *im,
|
||||
|
||||
void
|
||||
clutter_input_method_delete_surrounding (ClutterInputMethod *im,
|
||||
guint offset,
|
||||
int offset,
|
||||
guint len)
|
||||
{
|
||||
ClutterInputMethodPrivate *priv;
|
||||
|
@ -68,7 +68,7 @@ void clutter_input_method_commit (ClutterInputMethod *im,
|
||||
const gchar *text);
|
||||
CLUTTER_EXPORT
|
||||
void clutter_input_method_delete_surrounding (ClutterInputMethod *im,
|
||||
guint offset,
|
||||
int offset,
|
||||
guint len);
|
||||
CLUTTER_EXPORT
|
||||
void clutter_input_method_request_surrounding (ClutterInputMethod *im);
|
||||
|
@ -348,13 +348,23 @@ clutter_text_input_focus_request_surrounding (ClutterInputFocus *focus)
|
||||
|
||||
static void
|
||||
clutter_text_input_focus_delete_surrounding (ClutterInputFocus *focus,
|
||||
guint offset,
|
||||
int offset,
|
||||
guint len)
|
||||
{
|
||||
ClutterText *clutter_text = CLUTTER_TEXT_INPUT_FOCUS (focus)->text;
|
||||
int cursor;
|
||||
int start;
|
||||
|
||||
cursor = clutter_text_get_cursor_position (clutter_text);
|
||||
start = cursor + offset;
|
||||
if (start < 0)
|
||||
{
|
||||
g_warning ("The offset '%d' of deleting surrounding is larger than the cursor pos '%d'",
|
||||
offset, cursor);
|
||||
return;
|
||||
}
|
||||
if (clutter_text_get_editable (clutter_text))
|
||||
clutter_text_delete_text (clutter_text, offset, len);
|
||||
clutter_text_delete_text (clutter_text, start, len);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -94,17 +94,23 @@ meta_wayland_text_input_focus_request_surrounding (ClutterInputFocus *focus)
|
||||
|
||||
static void
|
||||
meta_wayland_text_input_focus_delete_surrounding (ClutterInputFocus *focus,
|
||||
guint cursor,
|
||||
int offset,
|
||||
guint len)
|
||||
{
|
||||
MetaWaylandGtkTextInput *text_input;
|
||||
uint32_t before_length;
|
||||
uint32_t after_length;
|
||||
struct wl_resource *resource;
|
||||
|
||||
text_input = META_WAYLAND_GTK_TEXT_INPUT_FOCUS (focus)->text_input;
|
||||
before_length = offset <= 0 ? -offset : offset;
|
||||
after_length = len >= before_length ? (len - before_length) : len + before_length;
|
||||
|
||||
wl_resource_for_each (resource, &text_input->focus_resource_list)
|
||||
{
|
||||
gtk_text_input_send_delete_surrounding_text (resource, cursor, len);
|
||||
gtk_text_input_send_delete_surrounding_text (resource,
|
||||
before_length,
|
||||
after_length);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,17 +166,23 @@ meta_wayland_text_input_focus_defer_done (ClutterInputFocus *focus)
|
||||
|
||||
static void
|
||||
meta_wayland_text_input_focus_delete_surrounding (ClutterInputFocus *focus,
|
||||
guint cursor,
|
||||
int offset,
|
||||
guint len)
|
||||
{
|
||||
MetaWaylandTextInput *text_input;
|
||||
uint32_t before_length;
|
||||
uint32_t after_length;
|
||||
struct wl_resource *resource;
|
||||
|
||||
text_input = META_WAYLAND_TEXT_INPUT_FOCUS (focus)->text_input;
|
||||
before_length = offset <= 0 ? -offset : offset;
|
||||
after_length = len >= before_length ? (len - before_length) : len + before_length;
|
||||
|
||||
wl_resource_for_each (resource, &text_input->focus_resource_list)
|
||||
{
|
||||
zwp_text_input_v3_send_delete_surrounding_text (resource, cursor, len);
|
||||
zwp_text_input_v3_send_delete_surrounding_text (resource,
|
||||
before_length,
|
||||
after_length);
|
||||
}
|
||||
|
||||
meta_wayland_text_input_focus_defer_done (focus);
|
||||
|
Loading…
Reference in New Issue
Block a user