From b296405a45ccf99dabb34b2b1726a843809d556c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristijan=20Ribari=C4=87?= Date: Wed, 9 Oct 2024 19:49:45 +0200 Subject: [PATCH] Fix: Use integer positions for workspaces This commit changes the `position` column in the `workspaces` table to be an `INTEGER` instead of a `REAL` data type. This change is made to ensure that workspace positions are always whole numbers, which prevents issues with floating-point precision and ensures consistent ordering of workspaces. Additionally, it updates the logic for calculating new workspace positions to use `Math.floor` to round down to the nearest integer, ensuring that positions are always integers. This change also adjusts the `minGap` constant used in the `shouldReorderWorkspaces` function to `1`, which reflects the minimum allowed gap between workspace positions now that they are integers. --- src/ZenWorkspacesStorage.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ZenWorkspacesStorage.mjs b/src/ZenWorkspacesStorage.mjs index fec293a..caf62b0 100644 --- a/src/ZenWorkspacesStorage.mjs +++ b/src/ZenWorkspacesStorage.mjs @@ -15,7 +15,7 @@ var ZenWorkspacesStorage = { icon TEXT, is_default INTEGER NOT NULL DEFAULT 0, container_id INTEGER, - position REAL NOT NULL DEFAULT 0, + position INTEGER NOT NULL DEFAULT 0, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL ) @@ -280,13 +280,13 @@ var ZenWorkspacesStorage = { newPosition = 1000; } else if (beforePosition === null) { // This will be the first workspace - newPosition = afterPosition / 2; + newPosition = Math.floor(afterPosition / 2); } else if (afterPosition === null) { // This will be the last workspace newPosition = beforePosition + 1000; } else { // This workspace will be between two others - newPosition = (beforePosition + afterPosition) / 2; + newPosition = Math.floor((beforePosition + afterPosition) / 2); } // Update the workspace's position @@ -320,7 +320,7 @@ var ZenWorkspacesStorage = { }, shouldReorderWorkspaces(before, current, after) { - const minGap = 0.001; // Minimum allowed gap between positions + const minGap = 1; // Minimum allowed gap between positions return (before !== null && current - before < minGap) || (after !== null && after - current < minGap); },