Commit 852196eb authored by Michael Natterer's avatar Michael Natterer 😴

app: fix insert and overwrite cursors for RTL text

by using the right function to figure the location of both kinds of
cursors. Also fix crash in my last cursor movement commit: check for
error values returned by pango_layout_move_cursor_visually() and don't
try to move the cursor beyond the buffer boundaries.
parent f3c2a75e
......@@ -515,6 +515,7 @@ gimp_text_tool_reset_im_context (GimpTextTool *text_tool)
void
gimp_text_tool_editor_get_cursor_rect (GimpTextTool *text_tool,
gboolean overwrite,
PangoRectangle *cursor_rect)
{
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
......@@ -538,7 +539,11 @@ gimp_text_tool_editor_get_cursor_rect (GimpTextTool *text_tool,
gimp_text_layout_get_offsets (text_tool->layout, &offset_x, &offset_y);
pango_layout_index_to_pos (layout, cursor_index, cursor_rect);
if (overwrite)
pango_layout_index_to_pos (layout, cursor_index, cursor_rect);
else
pango_layout_get_cursor_pos (layout, cursor_index, cursor_rect, NULL);
gimp_text_layout_transform_rect (text_tool->layout, cursor_rect);
cursor_rect->x = PANGO_PIXELS (cursor_rect->x) + offset_x;
......@@ -686,17 +691,29 @@ gimp_text_tool_move_cursor (GimpTextTool *text_tool,
while (count != 0)
{
if (count > 0)
gint new_index;
if (count > 0)
{
pango_layout_move_cursor_visually (layout, TRUE, index, 0, 1,
&index, &trailing);
&new_index, &trailing);
count--;
if (new_index != G_MAXINT)
index = new_index;
else
break;
}
else
{
pango_layout_move_cursor_visually (layout, TRUE, index, 0, -1,
&index, &trailing);
&new_index, &trailing);
count++;
if (new_index != -1)
index = new_index;
else
break;
}
}
......@@ -1250,7 +1267,9 @@ gimp_text_tool_im_preedit_start (GtkIMContext *context,
gint off_x, off_y;
if (text_tool->text)
gimp_text_tool_editor_get_cursor_rect (text_tool, &cursor_rect);
gimp_text_tool_editor_get_cursor_rect (text_tool,
text_tool->overwrite_mode,
&cursor_rect);
g_object_get (text_tool, "x1", &off_x, "y1", &off_y, NULL);
......
......@@ -47,6 +47,7 @@ gboolean gimp_text_tool_editor_key_release (GimpTextTool *text_tool
void gimp_text_tool_reset_im_context (GimpTextTool *text_tool);
void gimp_text_tool_editor_get_cursor_rect (GimpTextTool *text_tool,
gboolean overwrite,
PangoRectangle *cursor_rect);
......
......@@ -806,13 +806,15 @@ gimp_text_tool_draw (GimpDrawTool *draw_tool)
gint off_x, off_y;
gboolean overwrite;
gimp_text_tool_editor_get_cursor_rect (text_tool, &cursor_rect);
gimp_text_tool_editor_get_cursor_rect (text_tool,
text_tool->overwrite_mode,
&cursor_rect);
gimp_item_get_offset (GIMP_ITEM (text_tool->layer), &off_x, &off_y);
cursor_rect.x += off_x;
cursor_rect.y += off_y;
overwrite = text_tool->overwrite_mode && cursor_rect.width > 0;
overwrite = text_tool->overwrite_mode && cursor_rect.width != 0;
gimp_draw_tool_add_text_cursor (draw_tool, &cursor_rect, overwrite);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment