How can I swap the order of two selected tasks

I need to specify two tasks to exchange positions
Here is an example. On the surface, it seems that I need it, but in essence, I find that I don’t realize the position exchange of two specified tasks

If you want to swap the position of two tasks, and you know its IDs, then you can use moveTask method to change the positions of the required tasks: ;
You need to get the index and the parent of the task by getTaskIndex and getParent methods:; ;
So, to swap certain tasks might look like:

function swap() {
        let temp_ind = gantt.getTaskIndex(1)
        let temp_par = gantt.getParent(1)
        gantt.moveTask(1, gantt.getTaskIndex(4), gantt.getParent(4));
        gantt.moveTask(4, temp_ind, temp_par);

where temp_ind, temp_par temporary variables that hold the value of the initial task.
Please check the example: ;
Also, If you want to swap two selected tasks, one of the options is to use multiselect extension to select certain tasks and using moveTask method: ;
You can use eachSelectedTask method to get all selected tasks: ;
Please check the example of how it might be implemented (select two tasks by ctrl + click and click at the button):