Improve editor, plugin updates, and window transfers for 0.1.41
This commit is contained in:
@@ -4,6 +4,13 @@
|
||||
import { actionMenu, type ActionMenuItem } from "$lib/ui/actionMenu";
|
||||
import { actionIcons } from "$lib/ui/actionIcons";
|
||||
import TabIcon from "$lib/ui/TabIcon.svelte";
|
||||
import { attachTooltip } from "$lib/ui/tooltip";
|
||||
|
||||
function tabTooltip(node: HTMLElement, label: string) {
|
||||
let text = label;
|
||||
const dispose = attachTooltip(node, () => text);
|
||||
return { update(value: string) { text = value; }, destroy: dispose };
|
||||
}
|
||||
import { tabsToClose, type TabCloseScope } from "$lib/workspace/tabActions";
|
||||
import type { WorkbenchTab } from "$lib/workspace/workbenchTabs";
|
||||
|
||||
@@ -35,6 +42,16 @@
|
||||
let menuAnchor: HTMLButtonElement | undefined;
|
||||
let menuPath = $state<string | null>(null);
|
||||
let receiving = $state(false);
|
||||
let transferFrame = 0;
|
||||
let transferX = 0;
|
||||
|
||||
function scrollTransfer() {
|
||||
if (!receiving) { transferFrame = 0; return; }
|
||||
const bounds = bar.getBoundingClientRect();
|
||||
const speed = transferX < bounds.left + 28 ? -10 : transferX > bounds.right - 28 ? 10 : 0;
|
||||
if (speed) { bar.scrollLeft += speed; transferIndex(transferX); }
|
||||
transferFrame = requestAnimationFrame(scrollTransfer);
|
||||
}
|
||||
|
||||
function startTabTransfer(event: DragEvent, tab: WorkbenchTab) {
|
||||
const data = tabDragData(tab);
|
||||
@@ -59,13 +76,18 @@
|
||||
event.preventDefault();
|
||||
event.dataTransfer.dropEffect = "move";
|
||||
receiving = true;
|
||||
transferX = event.clientX;
|
||||
if (!transferFrame) transferFrame = requestAnimationFrame(scrollTransfer);
|
||||
const bounds = bar.getBoundingClientRect();
|
||||
if (event.clientX < bounds.left + 28) bar.scrollLeft -= 10;
|
||||
else if (event.clientX > bounds.right - 28) bar.scrollLeft += 10;
|
||||
transferIndex(event.clientX);
|
||||
}
|
||||
|
||||
function finishTabTransfer() { dragged = dropBefore = dropAfter = null; receiving = false; suppressClick = false; }
|
||||
function finishTabTransfer() {
|
||||
dragged = dropBefore = dropAfter = null; receiving = false; suppressClick = false;
|
||||
cancelAnimationFrame(transferFrame); transferFrame = 0;
|
||||
}
|
||||
|
||||
function dropTab(event: DragEvent) {
|
||||
const data = event.dataTransfer?.getData(transferType);
|
||||
@@ -237,7 +259,7 @@
|
||||
window.addEventListener("keydown", onEscape, true);
|
||||
}
|
||||
|
||||
onDestroy(() => { cancelDrag(); closeMenu(); });
|
||||
onDestroy(() => { cancelDrag(); finishTabTransfer(); closeMenu(); });
|
||||
|
||||
function onMiddleDown(event: MouseEvent) {
|
||||
if (event.button === 1) {
|
||||
@@ -271,7 +293,7 @@
|
||||
aria-controls={tab.panelId}
|
||||
aria-describedby={tab.pinned ? `tab-pin-${tab.id}` : undefined}
|
||||
aria-keyshortcuts="Alt+Shift+ArrowLeft Alt+Shift+ArrowRight"
|
||||
title={`${tab.title}\n${tab.draggable ? $t("Drag to reorder or move to another RuneStone window.") : $t("Drag to reorder.")} ${$t("Right-click for tab actions.")}`}
|
||||
use:tabTooltip={`${tab.title}\n${tab.draggable ? $t("Drag to reorder or move to another RuneStone window.") : $t("Drag to reorder.")} ${$t("Right-click for tab actions.")}`}
|
||||
onclick={() => { if (suppressClick) { suppressClick = false; return; } onSelect(tab.relPath); }}
|
||||
onpointerdown={(event) => { if (!tab.draggable) startDrag(event, tab.relPath); else suppressClick = false; }}
|
||||
draggable={!!tab.draggable}
|
||||
@@ -295,7 +317,7 @@
|
||||
class="close"
|
||||
type="button"
|
||||
aria-label={$t("Close {name}", { name: tab.name })}
|
||||
title={$t("Close {name}", { name: tab.name })}
|
||||
use:tabTooltip={$t("Close {name}", { name: tab.name })}
|
||||
onclick={() => onClose(tab.relPath)}
|
||||
onmousedown={onMiddleDown}
|
||||
onmouseup={(event) => onMiddleUp(event, tab.relPath)}
|
||||
|
||||
Reference in New Issue
Block a user