mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Add line wrap toggle for file preview with mobile-first defaults and fix container height
This commit is contained in:
1 parent
eba7efc675
commit
94bdaf6f8f
4 files changed
+49
-15
No files matched your search
@@ -273,8 +273,8 @@ useEffect(() => {
|
||||
)}
|
||||
|
||||
{/* Mobile: Full width file listing, Desktop: Split view */}
|
||||
<div className="flex-1 flex overflow-hidden min-h-0">
|
||||
<div className={`${isMobile ? 'w-full' : 'w-1/2'} border-r border-border px-4 flex flex-col min-h-0`}>
|
||||
<div className="flex-1 flex overflow-hidden min-h-0 h-full">
|
||||
<div className={`${isMobile ? 'w-full' : 'w-[30%]'} border-r border-border px-4 flex flex-col min-h-0 h-full`}>
|
||||
<div className="flex items-center gap-2 mb-4 mt-4 flex-shrink-0">
|
||||
<Input
|
||||
placeholder="Search"
|
||||
@@ -320,11 +320,11 @@ useEffect(() => {
|
||||
|
||||
{/* Desktop only: Preview panel */}
|
||||
{!isMobile && (
|
||||
<div className="flex-1 overflow-y-auto min-h-0 pb-8">
|
||||
<div className="flex-1 overflow-y-auto min-h-0 h-full">
|
||||
{selectedFile && !selectedFile.isDirectory ? (
|
||||
<FilePreview file={selectedFile} />
|
||||
) : (
|
||||
<div className="flex items-center justify-center h-64 text-muted-foreground">
|
||||
<div className="flex items-center justify-center h-full text-muted-foreground">
|
||||
Select a file to preview
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -65,9 +65,9 @@ export function FileBrowserSheet({ isOpen, onClose, basePath = '', repoName, ini
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 bg-black/50 backdrop-blur-sm">
|
||||
<div className="absolute inset-0 bg-background">
|
||||
<div className="absolute inset-0 bg-background flex flex-col">
|
||||
{/* Header */}
|
||||
<div className="sticky top-0 z-10 border-b border-border bg-background backdrop-blur-sm px-4 py-1">
|
||||
<div className="flex-shrink-0 border-b border-border bg-background backdrop-blur-sm px-4 py-1">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
{(displayPath === '/' || !repoName) && (
|
||||
@@ -91,7 +91,7 @@ export function FileBrowserSheet({ isOpen, onClose, basePath = '', repoName, ini
|
||||
</div>
|
||||
|
||||
{/* File Browser Content */}
|
||||
<div className="h-[calc(100vh-73px)] overflow-hidden">
|
||||
<div className="flex-1 overflow-hidden min-h-0">
|
||||
<FileBrowser
|
||||
basePath={normalizedBasePath}
|
||||
embedded={true}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { useState, useCallback, useRef, useEffect } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Download, X, Edit3, Save, X as XIcon } from 'lucide-react'
|
||||
import { Download, X, Edit3, Save, X as XIcon, WrapText } from 'lucide-react'
|
||||
import type { FileInfo } from '@/types/files'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import { VirtualizedTextView, type VirtualizedTextViewHandle } from '@/components/ui/virtualized-text-view'
|
||||
import { useMobile } from '@/hooks/useMobile'
|
||||
|
||||
const API_BASE = API_BASE_URL
|
||||
|
||||
@@ -24,10 +25,16 @@ export function FilePreview({ file, hideHeader = false, isMobileModal = false, o
|
||||
const [isSaving, setIsSaving] = useState(false)
|
||||
const [hasVirtualizedChanges, setHasVirtualizedChanges] = useState(false)
|
||||
const [highlightedLine, setHighlightedLine] = useState<number | undefined>(initialLineNumber)
|
||||
const [lineWrap, setLineWrap] = useState(false)
|
||||
const virtualizedRef = useRef<VirtualizedTextViewHandle>(null)
|
||||
const contentRef = useRef<HTMLDivElement>(null)
|
||||
const isMobile = useMobile()
|
||||
|
||||
const shouldVirtualize = file.size > VIRTUALIZATION_THRESHOLD_BYTES && !file.mimeType?.startsWith('image/')
|
||||
|
||||
useEffect(() => {
|
||||
setLineWrap(isMobile)
|
||||
}, [isMobile])
|
||||
|
||||
useEffect(() => {
|
||||
if (initialLineNumber && contentRef.current && !shouldVirtualize) {
|
||||
@@ -170,6 +177,7 @@ export function FilePreview({ file, hideHeader = false, isMobileModal = false, o
|
||||
onSave={handleVirtualizedSave}
|
||||
className="h-full"
|
||||
initialLineNumber={initialLineNumber}
|
||||
lineWrap={lineWrap}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -182,7 +190,9 @@ export function FilePreview({ file, hideHeader = false, isMobileModal = false, o
|
||||
<textarea
|
||||
value={editContent}
|
||||
onChange={(e) => setEditContent(e.target.value)}
|
||||
className="text-[16px] bg-muted text-foreground p-2 rounded whitespace-pre-wrap font-mono break-words w-full resize-none focus:outline-none focus:ring-0 border-none block"
|
||||
className={`text-[16px] bg-muted text-foreground p-2 rounded font-mono w-full resize-none focus:outline-none focus:ring-0 border-none block ${
|
||||
lineWrap ? 'whitespace-pre-wrap break-all' : 'whitespace-pre overflow-x-auto'
|
||||
}`}
|
||||
style={{ minHeight: '95vh' }}
|
||||
placeholder="Edit file content..."
|
||||
autoFocus
|
||||
@@ -195,7 +205,9 @@ export function FilePreview({ file, hideHeader = false, isMobileModal = false, o
|
||||
const textContent = decodeBase64(file.content)
|
||||
const lines = textContent.split('\n')
|
||||
return (
|
||||
<div className="pb-[200px] text-sm bg-muted text-foreground rounded font-mono overflow-x-hidden">
|
||||
<div className={`pb-[200px] text-sm bg-muted text-foreground rounded font-mono ${
|
||||
lineWrap ? 'overflow-x-hidden' : 'overflow-x-auto'
|
||||
}`}>
|
||||
{lines.map((line, index) => {
|
||||
const lineNum = index + 1
|
||||
const isHighlighted = highlightedLine === lineNum
|
||||
@@ -208,7 +220,9 @@ export function FilePreview({ file, hideHeader = false, isMobileModal = false, o
|
||||
<span className="w-12 flex-shrink-0 text-right pr-3 text-muted-foreground select-none border-r border-border/50 text-xs">
|
||||
{lineNum}
|
||||
</span>
|
||||
<pre className="flex-1 pl-3 whitespace-pre-wrap break-all">
|
||||
<pre className={`flex-1 pl-3 ${
|
||||
lineWrap ? 'whitespace-pre-wrap break-words' : 'whitespace-pre'
|
||||
}`}>
|
||||
{line || ' '}
|
||||
</pre>
|
||||
</div>
|
||||
@@ -269,6 +283,18 @@ export function FilePreview({ file, hideHeader = false, isMobileModal = false, o
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1 flex-shrink-0 mt-1">
|
||||
{isTextFile && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={(e) => { e.stopPropagation(); e.preventDefault(); setLineWrap(!lineWrap) }}
|
||||
className={`h-7 w-7 p-0 ${lineWrap ? 'bg-primary text-primary-foreground' : ''}`}
|
||||
title={lineWrap ? "Disable line wrap" : "Enable line wrap"}
|
||||
>
|
||||
<WrapText className="w-3 h-3" />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{isTextFile && viewMode !== 'edit' && (
|
||||
<Button variant="outline" size="sm" onClick={(e) => { e.stopPropagation(); e.preventDefault(); handleEdit() }} className="h-7 w-7 p-0">
|
||||
<Edit3 className="w-3 h-3" />
|
||||
|
||||
@@ -10,6 +10,7 @@ interface VirtualizedTextViewProps {
|
||||
onSave?: () => void
|
||||
className?: string
|
||||
initialLineNumber?: number
|
||||
lineWrap?: boolean
|
||||
}
|
||||
|
||||
export interface VirtualizedTextViewHandle {
|
||||
@@ -17,7 +18,7 @@ export interface VirtualizedTextViewHandle {
|
||||
}
|
||||
|
||||
const LINE_HEIGHT = 20
|
||||
const GUTTER_WIDTH = 60
|
||||
const GUTTER_WIDTH = 40
|
||||
|
||||
export const VirtualizedTextView = forwardRef<VirtualizedTextViewHandle, VirtualizedTextViewProps>(function VirtualizedTextView({
|
||||
filePath,
|
||||
@@ -28,6 +29,7 @@ export const VirtualizedTextView = forwardRef<VirtualizedTextViewHandle, Virtual
|
||||
onSave,
|
||||
className = '',
|
||||
initialLineNumber,
|
||||
lineWrap = false,
|
||||
}, ref) {
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
const [scrollTop, setScrollTop] = useState(0)
|
||||
@@ -156,7 +158,9 @@ export const VirtualizedTextView = forwardRef<VirtualizedTextViewHandle, Virtual
|
||||
return (
|
||||
<div
|
||||
ref={containerRef}
|
||||
className={`relative overflow-auto font-mono text-sm ${className}`}
|
||||
className={`relative font-mono text-sm ${className} ${
|
||||
lineWrap ? 'overflow-x-hidden' : 'overflow-auto'
|
||||
}`}
|
||||
onScroll={handleScroll}
|
||||
onKeyDown={handleKeyDown}
|
||||
style={{ height: '100%' }}
|
||||
@@ -176,7 +180,7 @@ export const VirtualizedTextView = forwardRef<VirtualizedTextViewHandle, Virtual
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="flex-shrink-0 text-right pr-3 text-muted-foreground select-none bg-muted/50 border-r border-border"
|
||||
className="flex-shrink-0 text-center text-muted-foreground select-none bg-muted/50 border-r border-border"
|
||||
style={{ width: GUTTER_WIDTH }}
|
||||
>
|
||||
{lineNum + 1}
|
||||
@@ -189,12 +193,16 @@ export const VirtualizedTextView = forwardRef<VirtualizedTextViewHandle, Virtual
|
||||
onChange={(e) => handleLineChange(lineNum, e.target.value)}
|
||||
className={`flex-1 bg-transparent outline-none pl-2 ${
|
||||
isEdited ? 'bg-yellow-500/10' : ''
|
||||
} ${
|
||||
lineWrap ? 'whitespace-pre-wrap break-all' : 'whitespace-pre'
|
||||
}`}
|
||||
style={{ lineHeight: `${lineHeight}px` }}
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
className="flex-1 pl-2 whitespace-pre overflow-hidden text-ellipsis"
|
||||
className={`flex-1 pl-2 ${
|
||||
lineWrap ? 'whitespace-pre-wrap break-words' : 'whitespace-pre overflow-hidden text-ellipsis'
|
||||
}`}
|
||||
style={{ lineHeight: `${lineHeight}px` }}
|
||||
>
|
||||
{content}
|
||||
|
||||
Reference in new issue
Block a user