From 5e6481bdc57912ff31c92c5df85e22b5f8ede99d Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 2 Jun 2017 12:53:57 +0300 Subject: [PATCH] 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) --- src/xdisp.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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; -- 2.39.2