Reorder services without switching to the reordered service

This commit is contained in:
Alice Gaudon 2020-05-19 05:34:00 +02:00
parent 7dea8d9484
commit 27c27f2e04

View File

@ -23,6 +23,7 @@ let emptyPage;
let urlPreview; let urlPreview;
let lastDragPosition; let lastDragPosition;
let oldActiveService; // For service reordering
// Service context menu // Service context menu
function openServiceContextMenu(event, serviceId) { function openServiceContextMenu(event, serviceId) {
@ -216,16 +217,19 @@ ipcRenderer.on('reorderService', (e, serviceId, targetId) => {
const oldServices = services; const oldServices = services;
services = []; services = [];
let newId = targetId;
for (let i = 0; i < targetId; i++) { for (let i = 0; i < targetId; i++) {
if (i !== serviceId) { if (i !== serviceId) {
services.push(oldServices[i]); services.push(oldServices[i]);
if (i === oldActiveService) newId = i;
} }
} }
services.push(oldServices[serviceId]); services.push(oldServices[serviceId]);
const newId = services.length - 1;
for (let i = targetId; i < oldServices.length; i++) { for (let i = targetId; i < oldServices.length; i++) {
if (i !== serviceId) { if (i !== serviceId) {
services.push(oldServices[i]); services.push(oldServices[i]);
if (i === oldActiveService) newId = i;
} }
} }
@ -354,6 +358,7 @@ function resetDrag() {
function reorderService(serviceId, targetId) { function reorderService(serviceId, targetId) {
console.log('Reordering service', serviceId, targetId); console.log('Reordering service', serviceId, targetId);
if (targetId >= 0) { if (targetId >= 0) {
oldActiveService = selectedService;
setActiveService(null); setActiveService(null);
ipcRenderer.send('reorderService', serviceId, targetId); ipcRenderer.send('reorderService', serviceId, targetId);
} }