mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 04:09:59 +02:00
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.
This commit is contained in:
parent
8ca8157e61
commit
b296405a45
1 changed files with 4 additions and 4 deletions
|
@ -15,7 +15,7 @@ var ZenWorkspacesStorage = {
|
||||||
icon TEXT,
|
icon TEXT,
|
||||||
is_default INTEGER NOT NULL DEFAULT 0,
|
is_default INTEGER NOT NULL DEFAULT 0,
|
||||||
container_id INTEGER,
|
container_id INTEGER,
|
||||||
position REAL NOT NULL DEFAULT 0,
|
position INTEGER NOT NULL DEFAULT 0,
|
||||||
created_at INTEGER NOT NULL,
|
created_at INTEGER NOT NULL,
|
||||||
updated_at INTEGER NOT NULL
|
updated_at INTEGER NOT NULL
|
||||||
)
|
)
|
||||||
|
@ -280,13 +280,13 @@ var ZenWorkspacesStorage = {
|
||||||
newPosition = 1000;
|
newPosition = 1000;
|
||||||
} else if (beforePosition === null) {
|
} else if (beforePosition === null) {
|
||||||
// This will be the first workspace
|
// This will be the first workspace
|
||||||
newPosition = afterPosition / 2;
|
newPosition = Math.floor(afterPosition / 2);
|
||||||
} else if (afterPosition === null) {
|
} else if (afterPosition === null) {
|
||||||
// This will be the last workspace
|
// This will be the last workspace
|
||||||
newPosition = beforePosition + 1000;
|
newPosition = beforePosition + 1000;
|
||||||
} else {
|
} else {
|
||||||
// This workspace will be between two others
|
// This workspace will be between two others
|
||||||
newPosition = (beforePosition + afterPosition) / 2;
|
newPosition = Math.floor((beforePosition + afterPosition) / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the workspace's position
|
// Update the workspace's position
|
||||||
|
@ -320,7 +320,7 @@ var ZenWorkspacesStorage = {
|
||||||
},
|
},
|
||||||
|
|
||||||
shouldReorderWorkspaces(before, current, after) {
|
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);
|
return (before !== null && current - before < minGap) || (after !== null && after - current < minGap);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue