From 0d8ef99f257a7ee9a84d07c0c491f7e7067c33af Mon Sep 17 00:00:00 2001 From: Jeffrey Middleton Date: Thu, 5 Mar 2009 18:06:05 -0600 Subject: [PATCH] screen_play: Changed selection movement on center-playing-song Previously, the cursor remained in the same screen position (and had some odd behavior in visual mode). Now it attempts to stay on the same song like other large movement commands, leaving visual mode intact, so you can do fun things like using center-playing-song to help select a range of songs up to the current song. --- src/screen_play.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/screen_play.c b/src/screen_play.c index f668757..b9b0ecb 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -140,7 +140,6 @@ static void center_playing_item(mpdclient_t *c) { unsigned length = c->playlist.list->len; - unsigned offset = lw->selected - lw->start; int idx; if (!c->song || length < lw->rows || @@ -155,10 +154,25 @@ center_playing_item(mpdclient_t *c) list_window_center(lw, length, idx); /* make sure the cursor is in the window */ - lw->selected = lw->start+offset; - lw->selected_start = lw->selected; - lw->selected_end = lw->selected; - list_window_check_selected(lw, length); + if (lw->selected < lw->start) { + lw->selected = lw->start; + if (lw->visual_selection) { + lw->selected_start = lw->visual_base; + lw->selected_end = lw->selected; + } else { + lw->selected_start = lw->selected; + lw->selected_end = lw->selected; + } + } else if (lw->selected > lw->start + lw->rows - 1) { + lw->selected = lw->start + lw->rows - 1; + if (lw->visual_selection) { + lw->selected_start = lw->selected; + lw->selected_end = lw->visual_base; + } else { + lw->selected_start = lw->selected; + lw->selected_end = lw->selected; + } + } } #ifndef NCMPC_MINI -- 2.30.2