Skip to content

Commit 7ab6f2e

Browse files
committed
fix: make tabs draggable in Vivaldi browser (fixes #130)
1 parent fd2c402 commit 7ab6f2e

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

packages/yasgui/src/TabElements.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ $minTabHeight: 35px;
9494
position: relative;
9595
$activeColor: #337ab7;
9696
$hoverColor: color.adjust($activeColor, $lightness: 30%);
97+
user-select: none;
98+
-webkit-user-select: none;
99+
-moz-user-select: none;
100+
-ms-user-select: none;
97101

98102
// Distinguish managed-query tabs from legacy tabs via background.
99103
// Legacy tabs keep their current styling.
@@ -190,6 +194,19 @@ $minTabHeight: 35px;
190194
padding: 0px 24px 0px 30px;
191195
white-space: nowrap;
192196
overflow: hidden;
197+
user-select: none;
198+
-webkit-user-select: none;
199+
-moz-user-select: none;
200+
-ms-user-select: none;
201+
-webkit-user-drag: none;
202+
203+
span {
204+
user-select: none;
205+
-webkit-user-select: none;
206+
-moz-user-select: none;
207+
-ms-user-select: none;
208+
pointer-events: none;
209+
}
193210

194211
&:hover {
195212
border-bottom-color: $hoverColor;

packages/yasgui/src/TabElements.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class TabListEl {
107107
tabLinkEl.href = "#" + this.tabId;
108108
tabLinkEl.id = "tab-" + this.tabId; // use the id for the tabpanel which is tabId to set the actual tab id
109109
tabLinkEl.setAttribute("aria-controls", this.tabId); // respective tabPanel id
110-
tabLinkEl.draggable = false; // Prevent default link dragging that interferes with text selection
110+
// Note: draggable attribute removed - CSS user-select:none prevents text selection during drag
111111
tabLinkEl.addEventListener("blur", () => {
112112
if (!this.tabEl) return;
113113
if (this.tabEl.classList.contains("active")) {
@@ -133,6 +133,17 @@ export class TabListEl {
133133
this.yasgui.selectTabId(this.tabId);
134134
});
135135

136+
// Prevent anchor default drag behavior that interferes with SortableJS in some browsers
137+
tabLinkEl.addEventListener("dragstart", (e) => {
138+
e.preventDefault();
139+
});
140+
tabLinkEl.addEventListener("mousedown", (e) => {
141+
// Only prevent default on middle/right click to avoid navigation
142+
if (e.button !== 0) {
143+
e.preventDefault();
144+
}
145+
});
146+
136147
//tab name
137148
this.nameEl = document.createElement("span");
138149
this.nameEl.textContent = name;
@@ -326,12 +337,15 @@ export class TabList {
326337
sortablejs.create(this._tabsListEl, {
327338
group: "tabList",
328339
animation: 100,
340+
draggable: ".tab",
341+
forceFallback: true,
342+
fallbackTolerance: 3,
329343
onUpdate: (_ev: any) => {
330344
const tabs = this.deriveTabOrderFromEls();
331345
this.yasgui.emit("tabOrderChanged", this.yasgui, tabs);
332346
this.yasgui.persistentConfig.setTabOrder(tabs);
333347
},
334-
filter: ".queryBrowserToggle, .addTab, input, .renaming",
348+
filter: ".queryBrowserToggle, .addTab, input, .renaming, .closeTab",
335349
preventOnFilter: false,
336350
onMove: (ev: any, _origEv: any) => {
337351
return hasClass(ev.related, "tab");

0 commit comments

Comments
 (0)