mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-25 01:54:49 +00:00
fix(app): can't scroll files
This commit is contained in:
@@ -446,9 +446,9 @@ export function FileTabContent(props: { tab: string }) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tabs.Content value={props.tab} class="mt-3 relative h-full">
|
<Tabs.Content value={props.tab} class="mt-3 relative flex h-full min-h-0 flex-col overflow-hidden contain-strict">
|
||||||
<ScrollView
|
<ScrollView
|
||||||
class="h-full"
|
class="h-full min-h-0 flex-1"
|
||||||
viewportRef={(el: HTMLDivElement) => {
|
viewportRef={(el: HTMLDivElement) => {
|
||||||
scroll = el
|
scroll = el
|
||||||
restoreScroll()
|
restoreScroll()
|
||||||
|
|||||||
@@ -347,6 +347,7 @@ export function MessageTimeline(props: {
|
|||||||
placeholderTitle={placeholderTitle}
|
placeholderTitle={placeholderTitle}
|
||||||
/>
|
/>
|
||||||
<ScrollView
|
<ScrollView
|
||||||
|
reverse
|
||||||
viewportRef={props.setScrollRef}
|
viewportRef={props.setScrollRef}
|
||||||
onWheel={(e) => {
|
onWheel={(e) => {
|
||||||
const root = e.currentTarget
|
const root = e.currentTarget
|
||||||
|
|||||||
@@ -9,9 +9,13 @@
|
|||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
scrollbar-width: none;
|
scrollbar-width: none;
|
||||||
outline: none;
|
outline: none;
|
||||||
|
display: block;
|
||||||
|
overflow-anchor: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scroll-view__viewport[data-reverse="true"] {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column-reverse;
|
flex-direction: column-reverse;
|
||||||
overflow-anchor: none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.scroll-view__viewport::-webkit-scrollbar {
|
.scroll-view__viewport::-webkit-scrollbar {
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ import { FAST_SPRING } from "./motion"
|
|||||||
|
|
||||||
export interface ScrollViewProps extends ComponentProps<"div"> {
|
export interface ScrollViewProps extends ComponentProps<"div"> {
|
||||||
viewportRef?: (el: HTMLDivElement) => void
|
viewportRef?: (el: HTMLDivElement) => void
|
||||||
|
reverse?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ScrollView(props: ScrollViewProps) {
|
export function ScrollView(props: ScrollViewProps) {
|
||||||
const i18n = useI18n()
|
const i18n = useI18n()
|
||||||
const [local, events, rest] = splitProps(
|
const [local, events, rest] = splitProps(
|
||||||
props,
|
props,
|
||||||
["class", "children", "viewportRef", "style"],
|
["class", "children", "viewportRef", "style", "reverse"],
|
||||||
[
|
[
|
||||||
"onScroll",
|
"onScroll",
|
||||||
"onWheel",
|
"onWheel",
|
||||||
@@ -36,6 +37,8 @@ export function ScrollView(props: ScrollViewProps) {
|
|||||||
const [thumbTop, setThumbTop] = createSignal(0)
|
const [thumbTop, setThumbTop] = createSignal(0)
|
||||||
const [showThumb, setShowThumb] = createSignal(false)
|
const [showThumb, setShowThumb] = createSignal(false)
|
||||||
|
|
||||||
|
const reverse = () => local.reverse === true
|
||||||
|
|
||||||
const updateThumb = () => {
|
const updateThumb = () => {
|
||||||
if (!viewportRef) return
|
if (!viewportRef) return
|
||||||
const { scrollTop, scrollHeight, clientHeight } = viewportRef
|
const { scrollTop, scrollHeight, clientHeight } = viewportRef
|
||||||
@@ -57,10 +60,11 @@ export function ScrollView(props: ScrollViewProps) {
|
|||||||
const maxScrollTop = scrollHeight - clientHeight
|
const maxScrollTop = scrollHeight - clientHeight
|
||||||
const maxThumbTop = trackHeight - height
|
const maxThumbTop = trackHeight - height
|
||||||
|
|
||||||
// With column-reverse: scrollTop=0 is at bottom, negative = scrolled up
|
const top = (() => {
|
||||||
// Normalize so 0 = at top, maxScrollTop = at bottom
|
if (maxScrollTop <= 0) return 0
|
||||||
const normalizedScrollTop = maxScrollTop + scrollTop
|
if (!reverse()) return (scrollTop / maxScrollTop) * maxThumbTop
|
||||||
const top = maxScrollTop > 0 ? (normalizedScrollTop / maxScrollTop) * maxThumbTop : 0
|
return ((maxScrollTop + scrollTop) / maxScrollTop) * maxThumbTop
|
||||||
|
})()
|
||||||
|
|
||||||
// Ensure thumb stays within bounds
|
// Ensure thumb stays within bounds
|
||||||
const boundedTop = trackPadding + Math.max(0, Math.min(top, maxThumbTop))
|
const boundedTop = trackPadding + Math.max(0, Math.min(top, maxThumbTop))
|
||||||
@@ -135,7 +139,8 @@ export function ScrollView(props: ScrollViewProps) {
|
|||||||
|
|
||||||
const limit = (top: number) => {
|
const limit = (top: number) => {
|
||||||
const max = viewportRef.scrollHeight - viewportRef.clientHeight
|
const max = viewportRef.scrollHeight - viewportRef.clientHeight
|
||||||
return Math.max(-max, Math.min(0, top))
|
if (reverse()) return Math.max(-max, Math.min(0, top))
|
||||||
|
return Math.max(0, Math.min(max, top))
|
||||||
}
|
}
|
||||||
|
|
||||||
const glide = (top: number) => {
|
const glide = (top: number) => {
|
||||||
@@ -175,13 +180,11 @@ export function ScrollView(props: ScrollViewProps) {
|
|||||||
break
|
break
|
||||||
case "Home":
|
case "Home":
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
// With column-reverse, top of content = -(scrollHeight - clientHeight)
|
glide(reverse() ? -(viewportRef.scrollHeight - viewportRef.clientHeight) : 0)
|
||||||
glide(-(viewportRef.scrollHeight - viewportRef.clientHeight))
|
|
||||||
break
|
break
|
||||||
case "End":
|
case "End":
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
// With column-reverse, bottom of content = 0
|
glide(reverse() ? 0 : viewportRef.scrollHeight - viewportRef.clientHeight)
|
||||||
glide(0)
|
|
||||||
break
|
break
|
||||||
case "ArrowUp":
|
case "ArrowUp":
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -206,6 +209,7 @@ export function ScrollView(props: ScrollViewProps) {
|
|||||||
<div
|
<div
|
||||||
ref={viewportRef}
|
ref={viewportRef}
|
||||||
class="scroll-view__viewport"
|
class="scroll-view__viewport"
|
||||||
|
data-reverse={reverse() ? "true" : undefined}
|
||||||
onScroll={(e) => {
|
onScroll={(e) => {
|
||||||
updateThumb()
|
updateThumb()
|
||||||
if (typeof events.onScroll === "function") events.onScroll(e as any)
|
if (typeof events.onScroll === "function") events.onScroll(e as any)
|
||||||
|
|||||||
Reference in New Issue
Block a user