Commit 1af4ba9a authored by Christian Hergert's avatar Christian Hergert

sourceiter: check movements before continuing

When moving through the buffer, we can have a situation where the edges
of the buffer are invisible, and therefore _is_start() will return FALSE
but the movement we performed did nothing (and left us at the visual
position of 0:0 or -1:-1).

This fixes that situation by checking the return value of those
movements and bailing as we would otherwise.

Fixes #76
parent 9bde21f1
......@@ -68,14 +68,21 @@ _gtk_source_iter_forward_full_word_end (GtkTextIter *iter)
while (g_unichar_isspace (gtk_text_iter_get_char (&pos)))
{
gtk_text_iter_forward_visible_cursor_position (&pos);
if (!gtk_text_iter_forward_visible_cursor_position (&pos))
{
break;
}
}
while (!gtk_text_iter_is_end (&pos) &&
!g_unichar_isspace (gtk_text_iter_get_char (&pos)))
{
non_blank_found = TRUE;
gtk_text_iter_forward_visible_cursor_position (&pos);
if (!gtk_text_iter_forward_visible_cursor_position (&pos))
{
break;
}
}
if (non_blank_found)
......@@ -97,7 +104,11 @@ _gtk_source_iter_backward_full_word_start (GtkTextIter *iter)
while (!gtk_text_iter_is_start (&pos))
{
prev = pos;
gtk_text_iter_backward_visible_cursor_position (&prev);
if (!gtk_text_iter_backward_visible_cursor_position (&prev))
{
break;
}
if (!g_unichar_isspace (gtk_text_iter_get_char (&prev)))
{
......@@ -110,7 +121,11 @@ _gtk_source_iter_backward_full_word_start (GtkTextIter *iter)
while (!gtk_text_iter_is_start (&pos))
{
prev = pos;
gtk_text_iter_backward_visible_cursor_position (&prev);
if (!gtk_text_iter_backward_visible_cursor_position (&prev))
{
break;
}
if (g_unichar_isspace (gtk_text_iter_get_char (&prev)))
{
......@@ -197,11 +212,17 @@ _gtk_source_iter_forward_extra_natural_word_end (GtkTextIter *iter)
{
if (gtk_text_iter_get_char (iter) == '_')
{
gtk_text_iter_forward_visible_cursor_position (iter);
if (!gtk_text_iter_forward_visible_cursor_position (iter))
{
break;
}
}
else if (gtk_text_iter_starts_word (iter))
{
gtk_text_iter_forward_visible_word_end (iter);
if (!gtk_text_iter_forward_visible_word_end (iter))
{
break;
}
}
else
{
......@@ -243,7 +264,11 @@ _gtk_source_iter_backward_extra_natural_word_start (GtkTextIter *iter)
while (!gtk_text_iter_is_start (iter))
{
GtkTextIter prev = *iter;
gtk_text_iter_backward_visible_cursor_position (&prev);
if (!gtk_text_iter_backward_visible_cursor_position (&prev))
{
break;
}
if (gtk_text_iter_get_char (&prev) == '_')
{
......@@ -251,7 +276,10 @@ _gtk_source_iter_backward_extra_natural_word_start (GtkTextIter *iter)
}
else if (gtk_text_iter_ends_word (iter))
{
gtk_text_iter_backward_visible_word_start (iter);
if (!gtk_text_iter_backward_visible_word_start (iter))
{
break;
}
}
else
{
......
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