Skip to content

Commit 9dac7bc

Browse files
committed
fix: Fixed drag and dropping from pinned to normal not being consistent, b=no-bug, c=tabs, folders
1 parent cbe04c2 commit 9dac7bc

File tree

5 files changed

+50
-36
lines changed

5 files changed

+50
-36
lines changed

src/browser/components/tabbrowser/content/tabs-js.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/browser/components/tabbrowser/content/tabs.js b/browser/components/tabbrowser/content/tabs.js
2-
index 1fcebe3962398ff1b7cadef657ac8b68a80e720d..49cb1c803b3b4384d948103f6352058e543081de 100644
2+
index 1fcebe3962398ff1b7cadef657ac8b68a80e720d..bc971287bbd0d799700cdd8f25f1191422af1b92 100644
33
--- a/browser/components/tabbrowser/content/tabs.js
44
+++ b/browser/components/tabbrowser/content/tabs.js
55
@@ -289,6 +289,7 @@
@@ -435,7 +435,7 @@ index 1fcebe3962398ff1b7cadef657ac8b68a80e720d..49cb1c803b3b4384d948103f6352058e
435435

436436
let dropElement = getOverlappedElement();
437437
+ if (dropElement?.hasAttribute("split-view-group")) dropElement = dropElement.labelElement;
438-
+ gZenPinnedTabManager.animateSeparatorMove(draggedTab, dropElement, isPinned);
438+
+ gZenPinnedTabManager.animateSeparatorMove(draggedTab, dropElement, isPinned, event);
439439

440440
let newDropElementIndex;
441441
if (dropElement) {

src/zen/folders/ZenFolder.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
}
159159

160160
async delete() {
161-
for (const tab of this.tabs) {
161+
for (const tab of this.allItemsRecursive) {
162162
await ZenPinnedTabsStorage.removePin(tab.getAttribute('zen-pin-id'));
163163
if (tab.hasAttribute('zen-empty-tab')) {
164164
// Manually remove the empty tabs as removeTabs() inside removeTabGroup
@@ -169,6 +169,18 @@
169169
await gBrowser.removeTabGroup(this, { isUserTriggered: true });
170170
}
171171

172+
get allItemsRecursive() {
173+
const items = [];
174+
for (const item of this.allItems) {
175+
if (item.isZenFolder) {
176+
items.push(item, ...item.allItemsRecursive);
177+
} else {
178+
items.push(item);
179+
}
180+
}
181+
return items;
182+
}
183+
172184
get level() {
173185
return this.group?.level + 1 || 0;
174186
}

src/zen/folders/ZenFolders.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,19 +874,22 @@
874874
return [];
875875
}
876876

877-
setFolderIndentation(tab, group = undefined, dropBefore = false) {
877+
setFolderIndentation(tab, group = undefined) {
878878
if (!gZenPinnedTabManager.expandedSidebarMode) {
879879
return;
880880
}
881881
let isTab = false;
882882
if (!group && tab?.group) {
883883
group = tab; // So we can set isTab later
884884
}
885-
if (gBrowser.isTab(group)) {
885+
if (gBrowser.isTab(group) && !group.hasAttribute('zen-empty-tab')) {
886886
group = group.group;
887887
isTab = true;
888888
}
889-
const level = group?.level + 1 - (dropBefore && !isTab ? 1 : 0) || 0;
889+
if (!isTab && !group?.hasAttribute('selected')) {
890+
group = null; // Don't indent if the group is not selected
891+
}
892+
const level = group?.level + 1 || 0;
890893
const baseSpacing = 14; // Base spacing for each level
891894
const tabLevel = tab?.group?.level || 0;
892895
const spacing = (level - tabLevel) * baseSpacing;

src/zen/tabs/ZenPinnedTabManager.mjs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
class nsZenPinnedTabManager extends nsZenDOMOperatedFeature {
6969
MAX_ESSENTIALS_TABS = 12;
7070

71+
#hasInitializedPins = false;
72+
7173
async init() {
7274
if (!this.enabled) {
7375
return;
@@ -351,6 +353,10 @@
351353

352354
gBrowser._updateTabBarForPinnedTabs();
353355
gZenUIManager.updateTabsToolbar();
356+
357+
setTimeout(() => {
358+
this.#hasInitializedPins = true;
359+
}, 0);
354360
}
355361

356362
_onPinnedTabEvent(action, event) {
@@ -693,6 +699,9 @@
693699
}
694700

695701
async savePin(pin, notifyObservers = true) {
702+
if (!this.#hasInitializedPins) {
703+
return;
704+
}
696705
const existingPin = this._pinsCache.find((p) => p.uuid === pin.uuid);
697706
if (existingPin) {
698707
Object.assign(existingPin, pin);
@@ -1163,24 +1172,23 @@
11631172
: [separator];
11641173
}
11651174

1166-
animateSeparatorMove(draggedTab, dropElement, isPinned) {
1175+
animateSeparatorMove(draggedTab, dropElement, isPinned, event) {
11671176
if (draggedTab?.group?.hasAttribute('split-view-group')) {
11681177
draggedTab = draggedTab.group;
11691178
}
11701179
const itemsToCheck = this.dragShiftableItems;
1171-
const separatorHeight = window.windowUtils.getBoundsWithoutFlushing(itemsToCheck[0]).height;
1172-
const tabRect = window.windowUtils.getBoundsWithoutFlushing(draggedTab);
1173-
const translate = tabRect.top - tabRect.height / 2;
1174-
const topToNormalTabs =
1175-
window.windowUtils.getBoundsWithoutFlushing(itemsToCheck[0]).top - separatorHeight / 2;
1180+
const translate = event.screenY;
1181+
const draggingTabHeight = window.windowUtils.getBoundsWithoutFlushing(draggedTab).height;
1182+
let topToNormalTabs = itemsToCheck[0].screenY;
1183+
if (!isPinned) {
1184+
topToNormalTabs += draggedTab.getBoundingClientRect().height;
1185+
}
11761186
const isGoingToPinnedTabs = translate < topToNormalTabs;
11771187
const multiplier = isGoingToPinnedTabs !== isPinned ? (isGoingToPinnedTabs ? 1 : -1) : 0;
1178-
const draggingTabHeight =
1179-
window.windowUtils.getBoundsWithoutFlushing(draggedTab).height * multiplier;
11801188
this._isGoingToPinnedTabs = isGoingToPinnedTabs;
11811189
if (!dropElement) {
11821190
itemsToCheck.forEach((item) => {
1183-
item.style.transform = `translateY(${draggingTabHeight}px)`;
1191+
item.style.transform = `translateY(${draggingTabHeight * multiplier}px)`;
11841192
});
11851193
}
11861194
}

src/zen/tabs/zen-tabs/vertical-tabs.css

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -156,40 +156,31 @@
156156
Pinned Tabs Separator
157157
========================================================================== */
158158
.pinned-tabs-container-separator {
159-
margin: 0 auto; /* Center vertically */
160-
padding: 8px 0;
159+
background: light-dark(rgba(1, 1, 1, 0.075), rgba(255, 255, 255, 0.1));
160+
margin: 8px auto;
161+
border: none;
161162
height: 1px;
162163
max-height: 1px;
163164
width: 98%; /* Slightly less than full width */
164165
transition:
165-
padding 0.1s ease-in-out,
166-
max-height 0.2s ease-in-out,
167-
opacity 0.1s ease-in-out;
166+
margin 0.2s ease-in-out,
167+
background 0.2s ease-in-out,
168+
max-height 0.2s ease-in-out;
168169
overflow: hidden;
169170
position: relative;
170171
opacity: 1;
171172

172173
#tabbrowser-tabs[movingtab] & {
173-
transition: transform 0.1s ease-in-out;
174-
}
175-
176-
&::before {
177-
background: light-dark(rgba(1, 1, 1, 0.075), rgba(255, 255, 255, 0.1));
178-
content: '';
179-
height: 1px;
180-
width: 100%;
181-
margin: 0 auto; /* Center the line */
182-
position: absolute;
183-
top: 50%;
184-
left: 50%;
185-
transform: translate(-50%, -50%);
174+
transition:
175+
margin 0.2s ease-in-out,
176+
background 0.2s ease-in-out,
177+
max-height 0.2s ease-in-out,
178+
transform 0.1s ease-in-out;
186179
}
187180

188-
/* Hide separator when specified by parent container attribute */
189181
.zen-workspace-pinned-tabs-section[hide-separator] & {
190182
max-height: 0;
191-
padding: 0;
192-
opacity: 0;
183+
margin: 0 auto;
193184
}
194185
}
195186

0 commit comments

Comments
 (0)