Commit 8e0dd56f authored by Michael Natterer's avatar Michael Natterer 😴

app: fix crashes by not trying to navigate on a NULL layout

Add boolean return value to gimp_text_tool_ensure_layout() and check
it where needed. Also fix the new VISUAL_POSITIONS navigation code yet
again.
parent 852196eb
......@@ -681,45 +681,43 @@ gimp_text_tool_move_cursor (GimpTextTool *text_tool,
if (! cancel_selection)
{
PangoLayout *layout;
gint index;
gint trailing;
index = gimp_text_buffer_get_iter_index (text_tool->buffer,
&cursor, TRUE);
if (! gimp_text_tool_ensure_layout (text_tool))
break;
layout = gimp_text_layout_get_pango_layout (text_tool->layout);
while (count != 0)
{
gint index;
gint trailing;
gint new_index;
index = gimp_text_buffer_get_iter_index (text_tool->buffer,
&cursor, TRUE);
if (count > 0)
{
pango_layout_move_cursor_visually (layout, TRUE, index, 0, 1,
&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,
&new_index, &trailing);
count++;
if (new_index != -1)
index = new_index;
else
break;
}
}
gimp_text_buffer_get_iter_at_index (text_tool->buffer,
&cursor, index, TRUE);
gtk_text_iter_forward_chars (&cursor, trailing);
if (new_index != G_MAXINT && new_index != -1)
index = new_index;
else
break;
gimp_text_buffer_get_iter_at_index (text_tool->buffer,
&cursor, index, TRUE);
gtk_text_iter_forward_chars (&cursor, trailing);
}
}
break;
......@@ -753,7 +751,8 @@ gimp_text_tool_move_cursor (GimpTextTool *text_tool,
cursor_index = gimp_text_buffer_get_iter_index (text_tool->buffer,
&cursor, TRUE);
gimp_text_tool_ensure_layout (text_tool);
if (! gimp_text_tool_ensure_layout (text_tool))
break;
layout = gimp_text_layout_get_pango_layout (text_tool->layout);
......
......@@ -1740,7 +1740,7 @@ gimp_text_tool_clear_layout (GimpTextTool *text_tool)
}
}
void
gboolean
gimp_text_tool_ensure_layout (GimpTextTool *text_tool)
{
if (! text_tool->layout && text_tool->text)
......@@ -1749,6 +1749,8 @@ gimp_text_tool_ensure_layout (GimpTextTool *text_tool)
text_tool->layout = gimp_text_layout_new (text_tool->layer->text, image);
}
return text_tool->layout != NULL;
}
void
......
......@@ -118,7 +118,7 @@ void gimp_text_tool_create_vectors_warped (GimpTextTool *text_tool);
/* only for the text editor */
void gimp_text_tool_clear_layout (GimpTextTool *text_tool);
void gimp_text_tool_ensure_layout (GimpTextTool *text_tool);
gboolean gimp_text_tool_ensure_layout (GimpTextTool *text_tool);
#endif /* __GIMP_TEXT_TOOL_H__ */
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