From 5a753280f9acce40787e62cf64c1b27cf288b060 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonathan=20Neusch=C3=A4fer?= Date: Fri, 10 Aug 2012 13:21:39 +0200 Subject: [PATCH] Try to keep the cursor position when reloading lyrics --- src/screen_lyrics.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c index 604a051..881db29 100644 --- a/src/screen_lyrics.c +++ b/src/screen_lyrics.c @@ -45,6 +45,8 @@ static struct screen_text text; static struct mpd_song *next_song; static bool follow = false; +/** Set if the cursor position shall be kept during the next lyrics update. */ +static bool reloading = false; static struct { struct mpd_song *song; @@ -172,7 +174,19 @@ delete_lyr_hd(void) static void screen_lyrics_set(const GString *str) { - screen_text_set(&text, str->str); + if (reloading) { + unsigned saved_start = text.lw->start; + + screen_text_set(&text, str->str); + + /* restore the cursor and ensure that it's still valid */ + text.lw->start = saved_start; + list_window_fetch_cursor(text.lw); + } else { + screen_text_set(&text, str->str); + } + + reloading = false; /* paint new data */ @@ -255,6 +269,7 @@ screen_lyrics_reload(void) { if (current.loader == NULL && current.artist != NULL && current.title != NULL) { + reloading = true; current.loader = lyrics_load(current.artist, current.title, screen_lyrics_callback, NULL); screen_text_repaint(&text); -- 2.30.2