diff --git a/kstars/ekos/scheduler/scheduler.cpp b/kstars/ekos/scheduler/scheduler.cpp index cecb7e50a..a00f7855d 100644 --- a/kstars/ekos/scheduler/scheduler.cpp +++ b/kstars/ekos/scheduler/scheduler.cpp @@ -879,6 +879,17 @@ void Scheduler::setJobManipulation(bool can_reorder, bool can_delete) void Scheduler::reorderJobs(QList reordered_sublist) { int destinationRow = 0; + /* identify the new selection position */ + int selectedRow = queueTable->currentRow(); + int newPosition = -1; + + if (selectedRow != -1 && selectedRow < jobs.size()) + { + SchedulerJob * const selectedJob = jobs.at(selectedRow); + newPosition = reordered_sublist.indexOf(selectedJob); + } + + /* re-arrange due to the new order */ foreach (SchedulerJob* job, reordered_sublist) { /* Find the reordered job's index in the list */ @@ -890,13 +901,13 @@ void Scheduler::reorderJobs(QList reordered_sublist) if (destinationRow != currentRow) jobs.move(currentRow, destinationRow); - /* Eventually move selection with moved job */ - if (queueTable->currentRow() == currentRow) - queueTable->selectRow(destinationRow); - destinationRow++; } + /* Eventually move selection with moved job */ + if (newPosition != -1) + queueTable->selectRow(newPosition); + /* Post checks */ foreach (SchedulerJob* job, reordered_sublist) {