[gtksourceview] hover: simplify hover bounds detection



commit c227b3f1457dc9cd74c31992f639ed65c4b888b0
Author: Christian Hergert <chergert redhat com>
Date:   Mon Aug 29 20:58:26 2022 -0700

    hover: simplify hover bounds detection
    
    We risk getting bounds that are out of view if we try to use various
    natural words which aren't necessarily going to be the same in any syntax
    language.
    
    This tries to be simpler and just looks for non-space characters.

 gtksourceview/gtksourcehover.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)
---
diff --git a/gtksourceview/gtksourcehover.c b/gtksourceview/gtksourcehover.c
index 09fa09c9..ec964fda 100644
--- a/gtksourceview/gtksourcehover.c
+++ b/gtksourceview/gtksourcehover.c
@@ -166,28 +166,38 @@ gtk_source_hover_get_bounds (GtkSourceHover *self,
                return FALSE;
        }
 
-       *location = iter;
-
-       if (!_gtk_source_iter_inside_word (&iter))
+       if (g_unichar_isspace (gtk_text_iter_get_char (&iter)))
        {
-               *begin = iter;
-               gtk_text_iter_set_line_offset (begin, 0);
+               return FALSE;
+       }
 
-               *end = iter;
-               gtk_text_iter_forward_to_line_end (end);
+       *begin = *end = iter;
 
-               return TRUE;
+       while (!gtk_text_iter_starts_line (begin))
+       {
+               gtk_text_iter_backward_char (begin);
+
+               if (g_unichar_isspace (gtk_text_iter_get_char (begin)))
+               {
+                       gtk_text_iter_forward_char (begin);
+                       break;
+               }
        }
 
-       if (!_gtk_source_iter_starts_full_word (&iter))
+       while (!gtk_text_iter_ends_line (end))
        {
-               _gtk_source_iter_backward_extra_natural_word_start (&iter);
-       }
+               if (g_unichar_isspace (gtk_text_iter_get_char (end)))
+               {
+                       break;
+               }
 
-       *begin = iter;
-       *end = iter;
+               if (!gtk_text_iter_forward_char (end))
+               {
+                       break;
+               }
+       }
 
-       _gtk_source_iter_forward_extra_natural_word_end (end);
+       *location = iter;
 
        return TRUE;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]