def move_entry(self, start_idx: int, upwards: bool = True) -> None:
"""Move playlist entry at start_idx up or down one step."""
- if (start_idx == self._idx
- or (upwards and start_idx == self._idx + 1)
- or ((not upwards) and start_idx == self._idx - 1)
- or (upwards and start_idx < 1)
- or ((not upwards) and start_idx > len(self.playlist) - 2)):
- return
i0, i1 = start_idx, start_idx + (-1 if upwards else 1)
+ if i1 < 0 or i1 >= len(self.playlist):
+ return
if self._mpv:
# NB: a functional playlist-move would do this in a single step,
# but for some reason I don't seem to get it to do anything
+ if self._idx == i1: # currently playing entries to be jumped over
+ self._idx = i0
+ i0, i1 = i1, i0
path = self.playlist[i1].full_path
self._mpv.command('playlist-remove', i1)
self._mpv.command('loadfile', path, 'insert-at', i0)