[text] Fix the deletion actions

When using the delete-prev action from the end of the text we end
up either missing the first glyph we have to delete or falling
through the last one in the text.

This commit fixes both issues.
This commit is contained in:
Emmanuele Bassi 2009-01-06 20:54:20 +00:00
parent 3d32d464e9
commit 8182b354b1

View File

@ -1388,16 +1388,12 @@ clutter_text_real_del_next (ClutterText *self,
return TRUE; return TRUE;
pos = priv->position; pos = priv->position;
len = g_utf8_strlen (priv->text, -1); len = priv->n_chars;
if (len && pos != -1 && pos < len) if (len && pos != -1 && pos < len)
{ clutter_text_delete_text (self, pos, pos + 1);
clutter_text_delete_text (self, pos, pos + 1);
return TRUE; return TRUE;
}
return FALSE;
} }
static gboolean static gboolean
@ -1414,7 +1410,7 @@ clutter_text_real_del_prev (ClutterText *self,
return TRUE; return TRUE;
pos = priv->position; pos = priv->position;
len = g_utf8_strlen (priv->text, -1); len = priv->n_chars;
if (pos != 0 && len != 0) if (pos != 0 && len != 0)
{ {
@ -1422,19 +1418,19 @@ clutter_text_real_del_prev (ClutterText *self,
{ {
clutter_text_set_cursor_position (self, len - 1); clutter_text_set_cursor_position (self, len - 1);
clutter_text_set_selection_bound (self, len - 1); clutter_text_set_selection_bound (self, len - 1);
clutter_text_delete_text (self, len - 1, len);
} }
else else
{ {
clutter_text_set_cursor_position (self, pos - 1); clutter_text_set_cursor_position (self, pos - 1);
clutter_text_set_selection_bound (self, pos - 1); clutter_text_set_selection_bound (self, pos - 1);
clutter_text_delete_text (self, pos - 1, pos);
} }
clutter_text_delete_text (self, pos - 1, pos);
return TRUE;
} }
return FALSE; return TRUE;
} }
static gboolean static gboolean
@ -3480,18 +3476,15 @@ clutter_text_delete_text (ClutterText *self,
if (!priv->text) if (!priv->text)
return; return;
if (end_pos == -1) if (start_pos == 0)
{ start_bytes = 0;
start_bytes = offset_to_bytes (priv->text,
g_utf8_strlen (priv->text, -1) - 1);
end_bytes = offset_to_bytes (priv->text,
g_utf8_strlen (priv->text, -1));
}
else else
{ start_bytes = offset_to_bytes (priv->text, start_pos);
start_bytes = offset_to_bytes (priv->text, start_pos);
end_bytes = offset_to_bytes (priv->text, end_pos); if (end_pos == -1)
} end_bytes = offset_to_bytes (priv->text, priv->n_chars);
else
end_bytes = offset_to_bytes (priv->text, end_pos);
new = g_string_new (priv->text); new = g_string_new (priv->text);
new = g_string_erase (new, start_bytes, end_bytes - start_bytes); new = g_string_erase (new, start_bytes, end_bytes - start_bytes);