|
1 | 1 | import { For, onCleanup, Show, Match, Switch, createMemo, createEffect, on } from "solid-js" |
2 | 2 | import { createMediaQuery } from "@solid-primitives/media" |
| 3 | +import { createResizeObserver } from "@solid-primitives/resize-observer" |
3 | 4 | import { Dynamic } from "solid-js/web" |
4 | 5 | import { useLocal } from "@/context/local" |
5 | 6 | import { selectionFromLines, useFile, type SelectedLineRange } from "@/context/file" |
@@ -248,6 +249,7 @@ export default function Page() { |
248 | 249 | messageId: undefined as string | undefined, |
249 | 250 | mobileTab: "session" as "session" | "review", |
250 | 251 | newSessionWorktree: "main", |
| 252 | + promptHeight: 0, |
251 | 253 | }) |
252 | 254 |
|
253 | 255 | const newSessionWorktree = createMemo(() => { |
@@ -289,6 +291,8 @@ export default function Page() { |
289 | 291 |
|
290 | 292 | const idle = { type: "idle" as const } |
291 | 293 | let inputRef!: HTMLDivElement |
| 294 | + let promptDock: HTMLDivElement | undefined |
| 295 | + let scroller: HTMLDivElement | undefined |
292 | 296 |
|
293 | 297 | createEffect(() => { |
294 | 298 | if (!params.id) return |
@@ -668,9 +672,30 @@ export default function Page() { |
668 | 672 | const anchor = (id: string) => `message-${id}` |
669 | 673 |
|
670 | 674 | const setScrollRef = (el: HTMLDivElement | undefined) => { |
| 675 | + scroller = el |
671 | 676 | autoScroll.scrollRef(el) |
672 | 677 | } |
673 | 678 |
|
| 679 | + createResizeObserver( |
| 680 | + () => promptDock, |
| 681 | + ({ height }) => { |
| 682 | + const next = Math.ceil(height) |
| 683 | + |
| 684 | + if (next === store.promptHeight) return |
| 685 | + |
| 686 | + const el = scroller |
| 687 | + const stick = el ? el.scrollHeight - el.clientHeight - el.scrollTop < 10 : false |
| 688 | + |
| 689 | + setStore("promptHeight", next) |
| 690 | + |
| 691 | + if (stick && el) { |
| 692 | + requestAnimationFrame(() => { |
| 693 | + el.scrollTo({ top: el.scrollHeight, behavior: "auto" }) |
| 694 | + }) |
| 695 | + } |
| 696 | + }, |
| 697 | + ) |
| 698 | + |
674 | 699 | const updateHash = (id: string) => { |
675 | 700 | window.history.replaceState(null, "", `#${anchor(id)}`) |
676 | 701 | } |
@@ -776,7 +801,10 @@ export default function Page() { |
776 | 801 | "@container relative shrink-0 flex flex-col min-h-0 h-full bg-background-stronger": true, |
777 | 802 | "flex-1 md:flex-none py-6 md:py-3": true, |
778 | 803 | }} |
779 | | - style={{ width: isDesktop() && showTabs() ? `${layout.session.width()}px` : "100%" }} |
| 804 | + style={{ |
| 805 | + width: isDesktop() && showTabs() ? `${layout.session.width()}px` : "100%", |
| 806 | + "--prompt-height": store.promptHeight ? `${store.promptHeight}px` : undefined, |
| 807 | + }} |
780 | 808 | > |
781 | 809 | <div class="flex-1 min-h-0 overflow-hidden"> |
782 | 810 | <Switch> |
@@ -791,7 +819,7 @@ export default function Page() { |
791 | 819 | view={view} |
792 | 820 | diffStyle="unified" |
793 | 821 | classes={{ |
794 | | - root: "pb-32", |
| 822 | + root: "pb-[calc(var(--prompt-height,8rem)+32px)]", |
795 | 823 | header: "px-4", |
796 | 824 | container: "px-4", |
797 | 825 | }} |
@@ -822,7 +850,7 @@ export default function Page() { |
822 | 850 | > |
823 | 851 | <div |
824 | 852 | ref={autoScroll.contentRef} |
825 | | - class="flex flex-col gap-32 items-start justify-start pb-32 md:pb-40 transition-[margin]" |
| 853 | + class="flex flex-col gap-32 items-start justify-start pb-[calc(var(--prompt-height,8rem)+64px)] md:pb-[calc(var(--prompt-height,10rem)+64px)] transition-[margin]" |
826 | 854 | classList={{ |
827 | 855 | "mt-0.5": !showTabs(), |
828 | 856 | "mt-0": showTabs(), |
@@ -894,7 +922,10 @@ export default function Page() { |
894 | 922 | </div> |
895 | 923 |
|
896 | 924 | {/* Prompt input */} |
897 | | - <div class="absolute inset-x-0 bottom-0 pt-12 pb-4 md:pb-8 flex flex-col justify-center items-center z-50 px-4 md:px-0 bg-gradient-to-t from-background-stronger via-background-stronger to-transparent pointer-events-none"> |
| 925 | + <div |
| 926 | + ref={(el) => (promptDock = el)} |
| 927 | + class="absolute inset-x-0 bottom-0 pt-12 pb-4 md:pb-8 flex flex-col justify-center items-center z-50 px-4 md:px-0 bg-gradient-to-t from-background-stronger via-background-stronger to-transparent pointer-events-none" |
| 928 | + > |
898 | 929 | <div |
899 | 930 | classList={{ |
900 | 931 | "w-full md:px-6 pointer-events-auto": true, |
|