feat(web): resize the file list in the Files pane

The split between the file browser and viewer was fixed. A separator
now drags it, with a 140px minimum and a 55% cap, and the arrow keys,
Home, and End do the same. The width survives a reload.

When the pane stacks the list above the viewer, the separator turns
horizontal and saves a separate height.
This commit is contained in:
vhaudiquet committed 2026-11-28 19:20:07 +01:00
1 parent ca333509a2
commit d4aac727ad
2 files changed
+264 -8

No files matched your search

+192 -3
View File
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import { ChevronLeft, ChevronRight, File, Folder, Link as LinkIcon } from 'lucide-vue-next'
import type { FileContentResponse, FileEntry, FileListResponse, GitSummaryResponse } from '~/types'
import { apiErrorMessage } from '~/utils/errors'
@@ -8,11 +8,40 @@ import { formatSize } from '~/utils/format'
const props = defineProps<{ roomId: string; roomName: string }>()
const api = useApi()
const FILES_WIDTH_KEY = 'together.files-list-width'
const FILES_HEIGHT_KEY = 'together.files-list-height'
const FILES_MIN_WIDTH = 140
const FILES_MIN_HEIGHT = 120
const FILES_DEFAULT_WIDTH_PERCENT = 0.34
const FILES_DEFAULT_HEIGHT_PERCENT = 0.38
const FILES_MAX_WIDTH_PERCENT = 0.55
const FILES_MAX_HEIGHT_PERCENT = 0.6
const FILES_STACKED_WIDTH = 430
const path = ref('.')
const entries = ref<FileEntry[]>([])
const loading = ref(false)
const error = ref('')
const filesEl = ref<HTMLElement | null>(null)
const browserEl = ref<HTMLElement | null>(null)
const filesWidth = ref(0)
const filesHeight = ref(0)
const listWidth = ref<number | null>(null)
const listHeight = ref<number | null>(null)
let filesObserver: ResizeObserver | null = null
type FilesDrag = {
pointerId: number
startX: number
startY: number
startSize: number
narrow: boolean
moved: boolean
}
let filesDrag: FilesDrag | null = null
const selected = ref<FileEntry | null>(null)
const file = ref<FileContentResponse | null>(null)
const fileLoading = ref(false)
@@ -25,6 +54,129 @@ const gitError = ref('')
let dirRequest = 0
let fileRequest = 0
const narrow = computed(() => filesWidth.value > 0 && filesWidth.value <= FILES_STACKED_WIDTH)
function fileListRange(stacked: boolean): { min: number; max: number } {
const total = stacked ? filesHeight.value : filesWidth.value
const ratio = stacked ? FILES_MAX_HEIGHT_PERCENT : FILES_MAX_WIDTH_PERCENT
const minimum = stacked ? FILES_MIN_HEIGHT : FILES_MIN_WIDTH
return { min: minimum, max: Math.max(minimum, Math.floor(total * ratio)) }
}
function clampFileListSize(size: number, stacked = narrow.value): number {
const range = fileListRange(stacked)
return Math.min(Math.max(Math.round(size), range.min), range.max)
}
const fileListMax = computed(() => fileListRange(narrow.value).max)
const fileListValue = computed(() => {
const stored = narrow.value ? listHeight.value : listWidth.value
if (stored !== null) return clampFileListSize(stored)
const total = narrow.value ? filesHeight.value : filesWidth.value
const ratio = narrow.value ? FILES_DEFAULT_HEIGHT_PERCENT : FILES_DEFAULT_WIDTH_PERCENT
const minimum = narrow.value ? FILES_MIN_HEIGHT : FILES_MIN_WIDTH
return clampFileListSize(Math.round(total * ratio) || minimum)
})
const filesStyle = computed(() => {
const style: Record<string, string> = {}
if (narrow.value) {
if (listHeight.value !== null) {
style['--files-browser-height'] = `${clampFileListSize(listHeight.value)}px`
}
} else if (listWidth.value !== null) {
style['--files-browser-width'] = `${clampFileListSize(listWidth.value)}px`
}
return Object.keys(style).length > 0 ? style : undefined
})
function readSize(key: string): number | null {
if (typeof window === 'undefined') return null
try {
const raw = window.localStorage.getItem(key)
if (!raw) return null
const value = Number.parseInt(raw, 10)
return Number.isFinite(value) && value > 0 ? value : null
} catch {
return null
}
}
function saveSize(key: string, size: number) {
try {
window.localStorage.setItem(key, String(Math.round(size)))
} catch {
// A browser that refuses storage keeps the size for this visit.
}
}
function onFilesResizeStart(event: PointerEvent) {
if (event.button !== 0) return
const browser = browserEl.value
const container = filesEl.value
if (!browser || !container) return
event.preventDefault()
filesWidth.value = container.clientWidth
filesHeight.value = container.clientHeight
const isNarrow = narrow.value
const rect = browser.getBoundingClientRect()
filesDrag = {
pointerId: event.pointerId,
startX: event.clientX,
startY: event.clientY,
startSize: isNarrow ? rect.height : rect.width,
narrow: isNarrow,
moved: false,
}
;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)
document.body.classList.add(isNarrow ? 'files-resizing-y' : 'files-resizing-x')
}
function onFilesResizeMove(event: PointerEvent) {
if (!filesDrag || event.pointerId !== filesDrag.pointerId) return
const delta = filesDrag.narrow ? event.clientY - filesDrag.startY : event.clientX - filesDrag.startX
if (Math.abs(delta) >= 1) filesDrag.moved = true
const next = clampFileListSize(filesDrag.startSize + delta, filesDrag.narrow)
if (filesDrag.narrow) listHeight.value = next
else listWidth.value = next
}
function endFilesResize() {
if (!filesDrag) return
const { moved, narrow: wasNarrow } = filesDrag
filesDrag = null
document.body.classList.remove('files-resizing-x', 'files-resizing-y')
if (!moved) return
if (wasNarrow) {
if (listHeight.value !== null) saveSize(FILES_HEIGHT_KEY, listHeight.value)
} else if (listWidth.value !== null) {
saveSize(FILES_WIDTH_KEY, listWidth.value)
}
}
function onFilesResizeKey(event: KeyboardEvent) {
const isNarrow = narrow.value
const browser = browserEl.value
const current = isNarrow
? (browser?.getBoundingClientRect().height ?? fileListValue.value)
: (browser?.getBoundingClientRect().width ?? fileListValue.value)
const step = event.shiftKey ? 64 : 16
const decrease = isNarrow ? 'ArrowUp' : 'ArrowLeft'
const increase = isNarrow ? 'ArrowDown' : 'ArrowRight'
let next: number
if (event.key === decrease) next = current - step
else if (event.key === increase) next = current + step
else if (event.key === 'Home') next = isNarrow ? FILES_MIN_HEIGHT : FILES_MIN_WIDTH
else if (event.key === 'End') next = fileListMax.value
else return
event.preventDefault()
const clamped = clampFileListSize(next, isNarrow)
if (isNarrow) listHeight.value = clamped
else listWidth.value = clamped
saveSize(isNarrow ? FILES_HEIGHT_KEY : FILES_WIDTH_KEY, clamped)
}
const segments = computed(() => (path.value === '.' ? [] : path.value.split('/').filter(Boolean)))
const hasParent = computed(() => segments.value.length > 0)
@@ -103,15 +255,33 @@ async function loadGit() {
}
onMounted(() => {
listWidth.value = readSize(FILES_WIDTH_KEY)
listHeight.value = readSize(FILES_HEIGHT_KEY)
const element = filesEl.value
if (element) {
filesWidth.value = element.clientWidth
filesHeight.value = element.clientHeight
filesObserver = new ResizeObserver(() => {
filesWidth.value = filesEl.value?.clientWidth ?? 0
filesHeight.value = filesEl.value?.clientHeight ?? 0
})
filesObserver.observe(element)
}
void loadDir('')
void loadGit()
})
onBeforeUnmount(() => {
filesObserver?.disconnect()
filesObserver = null
document.body.classList.remove('files-resizing-x', 'files-resizing-y')
})
</script>
<template>
<div class="files-pane">
<div class="files">
<div class="files-browser">
<div ref="filesEl" class="files" :style="filesStyle">
<div ref="browserEl" class="files-browser">
<div class="crumbs">
<button v-if="hasParent" type="button" class="crumb-back" @click="goBack">
<ChevronLeft :size="12" aria-hidden="true" />
@@ -152,6 +322,25 @@ onMounted(() => {
</div>
</div>
<div
class="files-resizer"
role="separator"
:aria-orientation="narrow ? 'horizontal' : 'vertical'"
aria-label="Resize file list"
:aria-valuemin="narrow ? FILES_MIN_HEIGHT : FILES_MIN_WIDTH"
:aria-valuemax="fileListMax"
:aria-valuenow="fileListValue"
:aria-valuetext="`${fileListValue} pixels`"
title="Drag to resize. Arrow keys also work."
tabindex="0"
@pointerdown="onFilesResizeStart"
@pointermove="onFilesResizeMove"
@pointerup="endFilesResize"
@pointercancel="endFilesResize"
@lostpointercapture="endFilesResize"
@keydown="onFilesResizeKey"
></div>
<div class="files-viewer">
<template v-if="selected">
<div class="viewer-head">