Code

screen_play: Changed selection movement on center-playing-song
authorJeffrey Middleton <jefromi@gmail.com>
Fri, 6 Mar 2009 00:06:05 +0000 (18:06 -0600)
committerJeffrey Middleton <jefromi@gmail.com>
Thu, 5 Mar 2009 19:17:22 +0000 (13:17 -0600)
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

index f668757896d3fc81539a1f7eda79673c54f312c7..b9b0ecb0f18606cf639f905a76ef31728cf201a4 100644 (file)
@@ -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