Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changeset/panel-resize-fps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Bug Fixes

- **Smooth panel resizing** - Dragging the terminal dock, sidebars or a split pane no longer refits the terminal and reallocates the data grid on every frame. The terminal holds its grid during the drag and refits once on release, and window resizes fit once the drag settles. The terminal dock has a proper handle with a wider grab area, and double-clicking it resets the height.
6 changes: 4 additions & 2 deletions src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,11 @@ html[data-os="linux"] { --window-radius: 8px; }

/* Lock cursor globally while drag is active so it never flickers mid-drag */
body.is-resizing-x,
body.is-resizing-x * { cursor: col-resize !important; }
body.is-resizing-x * { cursor: col-resize !important; user-select: none !important; -webkit-user-select: none !important; }
body.is-resizing-y,
body.is-resizing-y * { cursor: row-resize !important; }
body.is-resizing-y * { cursor: row-resize !important; user-select: none !important; -webkit-user-select: none !important; }
/* Skip xterm hit-testing while dragging any panel resize handle */
html[data-resizing] .xterm { pointer-events: none !important; }

/* An open modal dialog locks `pointer-events: none` on <body> (bits-ui), and
only the dialog's own content/overlay opt back in. Dialogs that inset
Expand Down
37 changes: 23 additions & 14 deletions src/lib/components/DataTable.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script>
import { isReadOnly, guardWrite } from '$lib/stores/read-only.js';
import { isPanelResizing } from '$lib/panel-motion.js';
import { tick, onDestroy, untrack } from "svelte";
import {
pgArrayElem, pgArrayText, isSqlArrayType, isVectorType, foldLines, valuesEqual,
Expand Down Expand Up @@ -8059,7 +8060,15 @@ import FilterX from "@lucide/svelte/icons/filter-x";
// the viewport has been, clipped by the scroll container - but never taller
// than the content, so it can never add scroll range the table did not
// already have. Short tables still follow the viewport exactly.
if (_viewportHeight > _tallestViewportH) _tallestViewportH = _viewportHeight
if (_viewportHeight > _tallestViewportH) {
// Growing the canvas backing store clears and reallocates it. During a
// live panel drag (e.g. pulling the terminal dock down), step up in 256px
// increments so the drag reallocates at most once or twice instead of
// every single frame. Still capped by spacerHeight below.
_tallestViewportH = isPanelResizing()
? Math.ceil(_viewportHeight / 256) * 256
: _viewportHeight
}
const cssH = Math.max(1, Math.round(Math.max(_viewportHeight, Math.min(spacerHeight, _tallestViewportH))))
const dpr = Math.min(window.devicePixelRatio || 1, 2)
_surfaceDpr = dpr
Expand Down Expand Up @@ -8446,21 +8455,21 @@ import FilterX from "@lucide/svelte/icons/filter-x";
void zoomState.value; void canvasZoom
const { ok, resized } = syncCanvasSurface()
// The canvas can outgrow the viewport (see syncCanvasSurface), and what sits
// below the fold is stale - a dock closing has to paint it in the same frame.
const vhChanged = _viewportHeight !== _lastLayoutVh
// below the fold is stale - a dock closing or shrinking downward has to paint
// the newly revealed rows in the same frame. Shrinking the viewport while
// dragging a bottom dock upward only clips already-painted rows, so skip the
// redundant repaint. And when draw() already ran synchronously, don't queue a
// duplicate rAF scheduleDraw() right behind it.
const vhGrew = _viewportHeight > _lastLayoutVh
const vhShrank = _viewportHeight < _lastLayoutVh
_lastLayoutVh = _viewportHeight
if (ok) {
// Paint synchronously only on the FIRST mount (so a fresh canvas never
// composites as an untransformed, unpainted "black" grid) and whenever the
// backing store was actually resized (assigning canvas.width/height clears
// it - without a sync repaint the grid would blank for a frame). Every other
// structural change leaves the last frame's pixels intact, so the
// rAF-coalesced scheduleDraw() below is enough and the previously
// unconditional synchronous draw() (which double-painted every update) is
// skipped.
if (!_firstPaintDone || resized || vhChanged) draw()
_firstPaintDone = true
scheduleDraw()
if (!_firstPaintDone || resized || vhGrew) {
draw()
_firstPaintDone = true
} else if (!(vhShrank && isPanelResizing())) {
scheduleDraw()
}
}
})

Expand Down
34 changes: 25 additions & 9 deletions src/lib/components/PaneLayout.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import Self from './PaneLayout.svelte'
import { cn } from '$lib/utils.js'
import { beginPanelResize, endPanelResize } from '$lib/panel-motion.js'

/** @typedef {import('$lib/pane-layout.js').PaneNode} PaneNode */
/** @typedef {import('$lib/pane-layout.js').GroupNode} GroupNode */
Expand Down Expand Up @@ -29,11 +30,18 @@
/** @param {PointerEvent} e */
function startResize(e) {
if (!splitEl || node.type !== 'split') return
if (e.button !== 0) return
e.preventDefault()
const el = /** @type {HTMLElement} */ (e.currentTarget)
try { el.setPointerCapture(e.pointerId) } catch { /* synthetic or detached pointer */ }
const rect = splitEl.getBoundingClientRect()
const horizontal = node.dir === 'row'
const splitId = node.id
const bodyClass = horizontal ? 'is-resizing-x' : 'is-resizing-y'
document.body.classList.add(bodyClass)
beginPanelResize('pane')
let raf = 0
let ended = false
/** @type {number | null} */
let pendingPct = null
const flush = () => {
Expand All @@ -51,19 +59,27 @@
// grid) can't stall the drag - the splitter stays glued to the pointer.
if (!raf) raf = requestAnimationFrame(flush)
}
const up = () => {
/** @param {PointerEvent} ev */
const up = (ev) => {
if (ended) return
ended = true
if (raf) cancelAnimationFrame(raf)
raf = 0
if (pendingPct != null) onresize(splitId, [pendingPct, 100 - pendingPct])
window.removeEventListener('pointermove', move)
window.removeEventListener('pointerup', up)
document.body.style.userSelect = ''
document.body.style.cursor = ''
document.body.classList.remove(bodyClass)
try {
if (el.hasPointerCapture?.(ev.pointerId)) el.releasePointerCapture(ev.pointerId)
} catch { /* already released */ }
el.removeEventListener('pointermove', move)
el.removeEventListener('pointerup', up)
el.removeEventListener('pointercancel', up)
el.removeEventListener('lostpointercapture', up)
endPanelResize()
}
document.body.style.userSelect = 'none'
document.body.style.cursor = horizontal ? 'col-resize' : 'row-resize'
window.addEventListener('pointermove', move)
window.addEventListener('pointerup', up)
el.addEventListener('pointermove', move)
el.addEventListener('pointerup', up)
el.addEventListener('pointercancel', up)
el.addEventListener('lostpointercapture', up)
}

/** Position/size of the drop-hint overlay for a given edge (translucent preview). */
Expand Down
30 changes: 27 additions & 3 deletions src/lib/components/ResizeHandle.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<script>
import { cn } from '$lib/utils.js'
import { beginPanelResize, endPanelResize } from '$lib/panel-motion.js'

let {
/** @type {'x' | 'y'} */
axis = 'x',
/** @type {'start' | 'end'} */
edge = 'end',
/** Optional double-click handler to reset the panel to its default size. @type {(() => void) | undefined} */
onreset = undefined,
/** Extra classes on the handle root. */
class: className = '',
onresizestart = () => {},
onresize = () => {},
onresizeend = () => {},
Expand All @@ -19,9 +24,10 @@

const bodyClass = axis === 'x' ? 'is-resizing-x' : 'is-resizing-y'
document.body.classList.add(bodyClass)
beginPanelResize(axis)

const el = /** @type {HTMLElement} */ (e.currentTarget)
el.setPointerCapture(e.pointerId)
try { el.setPointerCapture(e.pointerId) } catch { /* synthetic or detached pointer */ }
const startX = e.clientX
const startY = e.clientY

Expand All @@ -41,6 +47,7 @@
let rafId = 0
let pending = 0
let hasPending = false
let ended = false

const flush = () => {
rafId = 0
Expand All @@ -59,21 +66,28 @@

/** @param {PointerEvent} ev */
function onUp(ev) {
if (ended) return
ended = true
document.body.classList.remove(bodyClass)
el.releasePointerCapture(ev.pointerId)
try {
if (el.hasPointerCapture?.(ev.pointerId)) el.releasePointerCapture(ev.pointerId)
} catch { /* already released */ }
el.removeEventListener('pointermove', onMove)
el.removeEventListener('pointerup', onUp)
el.removeEventListener('pointercancel', onUp)
el.removeEventListener('lostpointercapture', onUp)
// Land on the last position the pointer actually reached, rather than on
// whichever frame happened to win the race with pointerup.
if (rafId) cancelAnimationFrame(rafId)
flush()
onresizeend()
endPanelResize()
}

el.addEventListener('pointermove', onMove)
el.addEventListener('pointerup', onUp)
el.addEventListener('pointercancel', onUp)
el.addEventListener('lostpointercapture', onUp)
}

const STEP = 20
Expand Down Expand Up @@ -106,18 +120,28 @@
class={cn(
'studio-resize-handle group relative z-20 shrink-0 touch-none select-none focus-visible:outline-none',
axis === 'x' ? 'h-full w-1 cursor-col-resize' : 'h-1 w-full cursor-row-resize',
className,
)}
onpointerdown={handlePointerDown}
onkeydown={handleKeydown}
ondblclick={onreset}
>
<!-- Invisible hit-area expansion along the hairline so grabbing the edge feels effortless. -->
<div
class={cn(
'absolute',
axis === 'x' && (edge === 'start' ? 'inset-y-0 -left-1.5 right-0' : 'inset-y-0 left-0 -right-1.5'),
axis === 'y' && (edge === 'start' ? 'inset-x-0 -top-1.5 bottom-0' : 'inset-x-0 top-0 -bottom-1.5'),
)}
></div>
<!-- Visual-only line, pointer-events-none so it never shadows the cursor -->
<div
class={cn(
// A full-length hairline exactly on the panel's edge, so it meets the
// title bar's edge line above it. It used to be rounded, translucent,
// inset 8px at each end and centred 2px inside the grab area: a short,
// soft line that never lined up with anything.
'pointer-events-none absolute bg-border/50 group-hover:bg-primary/70 group-active:bg-primary group-focus-visible:bg-primary/70',
'pointer-events-none absolute bg-border/50 transition-colors duration-75 group-hover:bg-primary/70 group-active:bg-primary group-focus-visible:bg-primary/70',
axis === 'x' && 'inset-y-0 w-px',
axis === 'x' && (edge === 'start' ? 'left-0' : 'right-0'),
axis === 'y' && 'inset-x-0 h-px',
Expand Down
77 changes: 45 additions & 32 deletions src/lib/components/StudioShell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import Sidebar from './Sidebar.svelte'
import TabBar from './TabBar.svelte'
import PaneLayout from './PaneLayout.svelte'
import ResizeHandle from './ResizeHandle.svelte'
import * as PaneTree from '$lib/pane-layout.js'
import TabLoading from './TabLoading.svelte'
import TableToolbar from './TableToolbar.svelte'
Expand Down Expand Up @@ -296,7 +297,10 @@
findForeignKeyForColumn,
normalizeForeignKeys,
} from '$lib/foreign-key-nav.js'
import { loadLayout, saveLayout, sidebarSideStore, setSidebarSide } from '$lib/stores/layout.js'
import {
loadLayout, saveLayout, sidebarSideStore, setSidebarSide,
TERMINAL_DOCK_MIN, TERMINAL_DOCK_DEFAULT, TERMINAL_DOCK_CONTENT_MIN, clampTerminalDockHeight,
} from '$lib/stores/layout.js'
import {
getLastConnection,
withSecrets,
Expand Down Expand Up @@ -3956,34 +3960,35 @@ let rowSearch = $state('')
window.addEventListener('stroke:redis-nav', on)
return () => window.removeEventListener('stroke:redis-nav', on)
})
/** Drag the hairline to resize; the height is kept across launches. @param {PointerEvent} e */
function startTerminalDockResize(e) {
e.preventDefault()
const startY = e.clientY
const startH = terminalDockHeight
const max = Math.max(160, window.innerHeight - 220)
// One layout per frame at most: pointermove fires faster than the display,
// and every height change re-lays the page above and the terminal below.
let frame = 0
let nextH = startH
/** @param {PointerEvent} ev */
const move = (ev) => {
nextH = Math.round(Math.min(max, Math.max(120, startH + (startY - ev.clientY))))
// Straight to the element: no app state change per frame, just one style write.
if (!frame) frame = requestAnimationFrame(() => { frame = 0; if (terminalDockEl) terminalDockEl.style.height = `${nextH}px` })
}
const up = () => {
window.removeEventListener('pointermove', move)
window.removeEventListener('pointerup', up)
cancelAnimationFrame(frame)
terminalDockHeight = nextH
document.documentElement.removeAttribute('data-resizing')
saveLayout({ terminalDockHeight })
}
// The terminal holds its grid while this is set and refits once at the end.
document.documentElement.setAttribute('data-resizing', 'terminal-dock')
window.addEventListener('pointermove', move)
window.addEventListener('pointerup', up)
let terminalDockDragStartH = 0
let terminalDockDragMaxH = 0
let terminalDockPendingH = 0

function beginTerminalDockResize() {
const parentH = terminalDockEl?.parentElement?.clientHeight || window.innerHeight
terminalDockDragStartH = terminalDockEl ? Math.round(terminalDockEl.getBoundingClientRect().height) : terminalDockHeight
terminalDockDragMaxH = Math.max(TERMINAL_DOCK_MIN, parentH - TERMINAL_DOCK_CONTENT_MIN)
terminalDockPendingH = terminalDockDragStartH
}

/** @param {number} dy */
function resizeTerminalDock(dy) {
terminalDockPendingH = Math.round(Math.min(terminalDockDragMaxH, Math.max(TERMINAL_DOCK_MIN, terminalDockDragStartH + dy)))
// Straight to the element: no Svelte state write per frame, just one style write.
if (terminalDockEl) terminalDockEl.style.height = `${terminalDockPendingH}px`
}

function finishTerminalDockResize() {
terminalDockHeight = terminalDockPendingH
if (terminalDockEl) terminalDockEl.style.height = `${terminalDockHeight}px`
saveLayout({ terminalDockHeight })
}

function resetTerminalDockHeight() {
const parentH = terminalDockEl?.parentElement?.clientHeight || window.innerHeight
terminalDockHeight = clampTerminalDockHeight(TERMINAL_DOCK_DEFAULT, parentH)
if (terminalDockEl) terminalDockEl.style.height = `${terminalDockHeight}px`
saveLayout({ terminalDockHeight })
}
createCommandHotkey('view.terminalDock', (e) => {
if (!connection) return
Expand Down Expand Up @@ -12670,12 +12675,20 @@ let rowSearch = $state('')
actions float at the top-right of the terminal itself. -->
<div
bind:this={terminalDockEl}
class={!terminalDockShown ? 'hidden' : terminalDockOverlay ? 'absolute inset-x-0 bottom-0 z-20 flex flex-col border-t border-border/60 bg-panel will-change-transform' : 'relative flex shrink-0 flex-col border-t border-border/60 bg-panel'}
class={!terminalDockShown ? 'hidden' : terminalDockOverlay ? 'absolute inset-x-0 bottom-0 z-20 flex max-h-[calc(100%-7.5rem)] flex-col bg-panel will-change-transform' : 'relative flex max-h-[calc(100%-7.5rem)] shrink-0 flex-col bg-panel'}
style:height="{terminalDockHeight}px"
inert={!terminalDockOpen || undefined}
>
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div class="absolute inset-x-0 -top-1 z-10 h-2 cursor-row-resize" onpointerdown={startTerminalDockResize}></div>
<div class="absolute inset-x-0 top-0 z-20">
<ResizeHandle
axis="y"
edge="start"
onresizestart={beginTerminalDockResize}
onresize={resizeTerminalDock}
onresizeend={finishTerminalDockResize}
onreset={resetTerminalDockHeight}
/>
</div>
<div class="absolute inset-0 flex flex-col">
<svelte:boundary failed={tabError}>
{#await import('./TerminalPage.svelte')}<TabLoading />{:then { default: TerminalPage }}
Expand Down
Loading
Loading