From: Eli Zaretskii Date: Fri, 2 Jun 2017 09:53:57 +0000 (+0300) Subject: Fix cursor position in Dired buffers after dired-sort-toggle X-Git-Tag: emacs-26.0.90~521^2~186 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5e6481bdc57912ff31c92c5df85e22b5f8ede99d;p=emacs.git Fix cursor position in Dired buffers after dired-sort-toggle * src/xdisp.c (display_and_set_cursor): Record cursor coordinates even if the frame is marked as garbaged. (Bug#27187) --- diff --git a/src/xdisp.c b/src/xdisp.c index 53210e5be5b..17a1cae0048 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -28793,7 +28793,6 @@ display_and_set_cursor (struct window *w, bool on, be in the midst of changing its size, and x and y may be off the window. */ if (! FRAME_VISIBLE_P (f) - || FRAME_GARBAGED_P (f) || vpos >= w->current_matrix->nrows || hpos >= w->current_matrix->matrix_w) return; @@ -28811,6 +28810,26 @@ display_and_set_cursor (struct window *w, bool on, return; } + /* A frame might be marked garbaged even though its cursor position + is correct, and will not change upon subsequent redisplay. This + happens in some rare situations, like toggling the sort order in + Dired windows. We've already established that VPOS is valid, so + it shouldn't do any harm to record the cursor position, as we are + going to return without acting on it anyway. Otherwise, expose + events might come in and call update_window_cursor, which will + blindly use outdated values in w->phys_cursor. */ + if (FRAME_GARBAGED_P (f)) + { + if (on) + { + w->phys_cursor.x = x; + w->phys_cursor.y = glyph_row->y; + w->phys_cursor.hpos = hpos; + w->phys_cursor.vpos = vpos; + } + return; + } + glyph = NULL; if (0 <= hpos && hpos < glyph_row->used[TEXT_AREA]) glyph = glyph_row->glyphs[TEXT_AREA] + hpos;