]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix bug #17047 with cursor motion when invisible text starts a line.
authorEli Zaretskii <eliz@gnu.org>
Sun, 23 Mar 2014 15:57:25 +0000 (17:57 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sun, 23 Mar 2014 15:57:25 +0000 (17:57 +0200)
 src/xdisp.c (redisplay_window): If all previous attempts to find the
 cursor row failed, try a few alternatives before falling back to
 the top-most row of the window.  Use row_containing_pos.

src/ChangeLog
src/xdisp.c

index e8ae781bf4d17d4b99cf49c0391d815bffe9d04d..a9a0ebbe4a12bcd62a279c6c770a8778ece6ad1b 100644 (file)
@@ -1,3 +1,9 @@
+2014-03-23  Eli Zaretskii  <eliz@gnu.org>
+
+       * xdisp.c (redisplay_window): If all previous attempts to find the
+       cursor row failed, try a few alternatives before falling back to
+       the top-most row of the window.  (Bug#17047)
+
 2014-03-22  Daniel Colascione  <dancol@dancol.org>
 
        * process.c (conv_sockaddr_to_lisp): When extracting the string
index 6f39324d2f0b771dd8e683d7b81396b0780c8f2a..53bd46328f2674a10d660bc69d030543559383e6 100644 (file)
@@ -16400,12 +16400,50 @@ redisplay_window (Lisp_Object window, bool just_this_one_p)
   /* Consider the following case: Window starts at BEGV, there is
      invisible, intangible text at BEGV, so that display starts at
      some point START > BEGV.  It can happen that we are called with
-     PT somewhere between BEGV and START.  Try to handle that case.  */
+     PT somewhere between BEGV and START.  Try to handle that case,
+     and similar ones.  */
   if (w->cursor.vpos < 0)
     {
-      struct glyph_row *row = w->current_matrix->rows;
-      if (row->mode_line_p)
-       ++row;
+      /* First, try locating the proper glyph row for PT.  */
+      struct glyph_row *row =
+       row_containing_pos (w, PT, w->current_matrix->rows, NULL, 0);
+
+      /* Sometimes point is at the beginning of invisible text that is
+        before the 1st character displayed in the row.  In that case,
+        row_containing_pos fails to find the row, because no glyphs
+        with appropriate buffer positions are present in the row.
+        Therefore, we next try to find the row which shows the 1st
+        position after the invisible text.  */
+      if (!row)
+       {
+         Lisp_Object val =
+           get_char_property_and_overlay (make_number (PT), Qinvisible,
+                                          Qnil, NULL);
+
+         if (TEXT_PROP_MEANS_INVISIBLE (val))
+           {
+             ptrdiff_t alt_pos;
+             Lisp_Object invis_end =
+               Fnext_single_char_property_change (make_number (PT), Qinvisible,
+                                                  Qnil, Qnil);
+
+             if (NATNUMP (invis_end))
+               alt_pos = XFASTINT (invis_end);
+             else
+               alt_pos = ZV;
+             row = row_containing_pos (w, alt_pos, w->current_matrix->rows,
+                                       NULL, 0);
+           }
+       }
+      /* Finally, fall back on the first row of the window after the
+        header line (if any).  This is slightly better than not
+        displaying the cursor at all.  */
+      if (!row)
+       {
+         row = w->current_matrix->rows;
+         if (row->mode_line_p)
+           ++row;
+       }
       set_cursor_from_row (w, row, w->current_matrix, 0, 0, 0, 0);
     }