11import { sampledChecksum } from "@opencode-ai/util/encode"
22import {
3- DEFAULT_VIRTUAL_FILE_METRICS ,
43 type DiffLineAnnotation ,
54 type FileContents ,
65 type FileDiffMetadata ,
@@ -10,10 +9,6 @@ import {
109 type FileOptions ,
1110 type LineAnnotation ,
1211 type SelectedLineRange ,
13- type VirtualFileMetrics ,
14- VirtualizedFile ,
15- VirtualizedFileDiff ,
16- Virtualizer ,
1712} from "@pierre/diffs"
1813import { type PreloadFileDiffResult , type PreloadMultiFileDiffResult } from "@pierre/diffs/ssr"
1914import { createMediaQuery } from "@solid-primitives/media"
@@ -40,19 +35,10 @@ import {
4035 readShadowLineSelection ,
4136} from "../pierre/file-selection"
4237import { createLineNumberSelectionBridge , restoreShadowTextSelection } from "../pierre/selection-bridge"
43- import { acquireVirtualizer , virtualMetrics } from "../pierre/virtualizer"
4438import { getWorkerPool } from "../pierre/worker"
4539import { FileMedia , type FileMediaOptions } from "./file-media"
4640import { FileSearchBar } from "./file-search"
4741
48- const VIRTUALIZE_BYTES = 500_000
49-
50- const codeMetrics = {
51- ...DEFAULT_VIRTUAL_FILE_METRICS ,
52- lineHeight : 24 ,
53- fileGap : 0 ,
54- } satisfies Partial < VirtualFileMetrics >
55-
5642type SharedProps < T > = {
5743 annotations ?: LineAnnotation < T > [ ] | DiffLineAnnotation < T > [ ]
5844 selectedLines ?: SelectedLineRange | null
@@ -386,11 +372,6 @@ type AnnotationTarget<A> = {
386372 rerender : ( ) => void
387373}
388374
389- type VirtualStrategy = {
390- get : ( ) => Virtualizer | undefined
391- cleanup : ( ) => void
392- }
393-
394375function useModeViewer ( config : ModeConfig , adapter : ModeAdapter ) {
395376 return useFileViewer ( {
396377 enableLineSelection : config . enableLineSelection ,
@@ -532,64 +513,6 @@ function scrollParent(el: HTMLElement): HTMLElement | undefined {
532513 }
533514}
534515
535- function createLocalVirtualStrategy ( host : ( ) => HTMLDivElement | undefined , enabled : ( ) => boolean ) : VirtualStrategy {
536- let virtualizer : Virtualizer | undefined
537- let root : Document | HTMLElement | undefined
538-
539- const release = ( ) => {
540- virtualizer ?. cleanUp ( )
541- virtualizer = undefined
542- root = undefined
543- }
544-
545- return {
546- get : ( ) => {
547- if ( ! enabled ( ) ) {
548- release ( )
549- return
550- }
551- if ( typeof document === "undefined" ) return
552-
553- const wrapper = host ( )
554- if ( ! wrapper ) return
555-
556- const next = scrollParent ( wrapper ) ?? document
557- if ( virtualizer && root === next ) return virtualizer
558-
559- release ( )
560- virtualizer = new Virtualizer ( )
561- root = next
562- virtualizer . setup ( next , next instanceof Document ? undefined : wrapper )
563- return virtualizer
564- } ,
565- cleanup : release ,
566- }
567- }
568-
569- function createSharedVirtualStrategy ( host : ( ) => HTMLDivElement | undefined ) : VirtualStrategy {
570- let shared : NonNullable < ReturnType < typeof acquireVirtualizer > > | undefined
571-
572- const release = ( ) => {
573- shared ?. release ( )
574- shared = undefined
575- }
576-
577- return {
578- get : ( ) => {
579- if ( shared ) return shared . virtualizer
580-
581- const container = host ( )
582- if ( ! container ) return
583-
584- const result = acquireVirtualizer ( container )
585- if ( ! result ) return
586- shared = result
587- return result . virtualizer
588- } ,
589- cleanup : release ,
590- }
591- }
592-
593516function parseLine ( node : HTMLElement ) {
594517 if ( ! node . dataset . line ) return
595518 const value = parseInt ( node . dataset . line , 10 )
@@ -688,7 +611,7 @@ function ViewerShell(props: {
688611// ---------------------------------------------------------------------------
689612
690613function TextViewer < T > ( props : TextFileProps < T > ) {
691- let instance : PierreFile < T > | VirtualizedFile < T > | undefined
614+ let instance : PierreFile < T > | undefined
692615 let viewer ! : Viewer
693616
694617 const [ local , others ] = splitProps ( props , textKeys )
@@ -707,34 +630,12 @@ function TextViewer<T>(props: TextFileProps<T>) {
707630 return Math . max ( 1 , total )
708631 }
709632
710- const bytes = createMemo ( ( ) => {
711- const value = local . file . contents as unknown
712- if ( typeof value === "string" ) return value . length
713- if ( Array . isArray ( value ) ) {
714- return value . reduce (
715- ( sum , part ) => sum + ( typeof part === "string" ? part . length + 1 : String ( part ) . length + 1 ) ,
716- 0 ,
717- )
718- }
719- if ( value == null ) return 0
720- return String ( value ) . length
721- } )
722-
723- const virtual = createMemo ( ( ) => bytes ( ) > VIRTUALIZE_BYTES )
724-
725- const virtuals = createLocalVirtualStrategy ( ( ) => viewer . wrapper , virtual )
726-
727633 const lineFromMouseEvent = ( event : MouseEvent ) : MouseHit => mouseHit ( event , parseLine )
728634
729635 const applySelection = ( range : SelectedLineRange | null ) => {
730636 const current = instance
731637 if ( ! current ) return false
732638
733- if ( virtual ( ) ) {
734- current . setSelectedLines ( range )
735- return true
736- }
737-
738639 const root = viewer . getRoot ( )
739640 if ( ! root ) return false
740641
@@ -833,10 +734,7 @@ function TextViewer<T>(props: TextFileProps<T>) {
833734 const notify = ( ) => {
834735 notifyRendered ( {
835736 viewer,
836- isReady : ( root ) => {
837- if ( virtual ( ) ) return root . querySelector ( "[data-line]" ) != null
838- return root . querySelectorAll ( "[data-line]" ) . length >= lineCount ( )
839- } ,
737+ isReady : ( root ) => root . querySelectorAll ( "[data-line]" ) . length >= lineCount ( ) ,
840738 onReady : ( ) => {
841739 applySelection ( viewer . lastSelection )
842740 viewer . find . refresh ( { reset : true } )
@@ -855,17 +753,11 @@ function TextViewer<T>(props: TextFileProps<T>) {
855753 createEffect ( ( ) => {
856754 const opts = options ( )
857755 const workerPool = getWorkerPool ( "unified" )
858- const isVirtual = virtual ( )
859-
860- const virtualizer = virtuals . get ( )
861756
862757 renderViewer ( {
863758 viewer,
864759 current : instance ,
865- create : ( ) =>
866- isVirtual && virtualizer
867- ? new VirtualizedFile < T > ( opts , virtualizer , codeMetrics , workerPool )
868- : new PierreFile < T > ( opts , workerPool ) ,
760+ create : ( ) => new PierreFile < T > ( opts , workerPool ) ,
869761 assign : ( value ) => {
870762 instance = value
871763 } ,
@@ -892,7 +784,6 @@ function TextViewer<T>(props: TextFileProps<T>) {
892784 onCleanup ( ( ) => {
893785 instance ?. cleanUp ( )
894786 instance = undefined
895- virtuals . cleanup ( )
896787 } )
897788
898789 return < ViewerShell mode = "text" viewer = { viewer } class = { local . class } classList = { local . classList } />
@@ -988,8 +879,6 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
988879 adapter ,
989880 )
990881
991- const virtuals = createSharedVirtualStrategy ( ( ) => viewer . container )
992-
993882 const large = createMemo ( ( ) => {
994883 if ( local . fileDiff ) {
995884 const before = local . fileDiff . deletionLines . join ( "" )
@@ -1052,7 +941,6 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
1052941 createEffect ( ( ) => {
1053942 const opts = options ( )
1054943 const workerPool = large ( ) ? getWorkerPool ( "unified" ) : getWorkerPool ( props . diffStyle )
1055- const virtualizer = virtuals . get ( )
1056944 const beforeContents = typeof local . before ?. contents === "string" ? local . before . contents : ""
1057945 const afterContents = typeof local . after ?. contents === "string" ? local . after . contents : ""
1058946 const done = preserve ( viewer )
@@ -1067,10 +955,7 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
1067955 renderViewer ( {
1068956 viewer,
1069957 current : instance ,
1070- create : ( ) =>
1071- virtualizer
1072- ? new VirtualizedFileDiff < T > ( opts , virtualizer , virtualMetrics , workerPool )
1073- : new FileDiff < T > ( opts , workerPool ) ,
958+ create : ( ) => new FileDiff < T > ( opts , workerPool ) ,
1074959 assign : ( value ) => {
1075960 instance = value
1076961 } ,
@@ -1108,7 +993,6 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
1108993 onCleanup ( ( ) => {
1109994 instance ?. cleanUp ( )
1110995 instance = undefined
1111- virtuals . cleanup ( )
1112996 dragSide = undefined
1113997 dragEndSide = undefined
1114998 } )
0 commit comments