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.
This commit is contained in:
Michael Natterer 2010-10-14 11:01:16 +02:00
parent 852196eb3d
commit 8e0dd56feb
3 changed files with 22 additions and 21 deletions

View File

@ -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);

View File

@ -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

View File

@ -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__ */