Code

configure.ac: enable automake silent-rules
[ncmpc.git] / src / screen_lyrics.c
index ee76e28b45134563715e378f7d9655a500a88d5c..066fe6edc2ab69baaaf04031dae5f4f574f7596e 100644 (file)
@@ -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);
+       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);
@@ -379,6 +394,8 @@ lyrics_edit(void)
        pid_t pid = fork();
        if (pid == -1) {
                screen_status_printf(("%s (%s)"), _("Can't start editor"), g_strerror(errno));
+               ncu_init();
+               return;
        } else if (pid == 0) {
                char path[1024];
                path_lyr_file(path, sizeof(path), current.artist, current.title);
@@ -448,7 +465,7 @@ lyrics_cmd(struct mpdclient *c, command_t cmd)
                        screen_text_repaint(&text);
                }
                return true;
-       case CMD_LYRICS_EDIT:
+       case CMD_EDIT:
                lyrics_edit();
                return true;
        case CMD_SELECT: