mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
* fix(files): resolve workspace paths and add sandboxed HTML preview Accept workspace-absolute paths in the file service and return repo-relative paths for file reads and directory listings. Serve raw content under a CSP sandbox and preview HTML files in a sandboxed iframe with a raw toggle. Resolve file-click paths from the session directory and repo local path, detect absolute and html/htm file references while ignoring URLs, accept the legacy filePath input key and filediff metadata, fix the file browser navigating into an initially selected directory, and use focus-visible rings across shared UI primitives. * fix(files): address review feedback on navigation and path fallback Key initial directory navigation to the initial selection so viewport changes do not reset it, and open the mobile preview from a separate effect. Fall back to the legacy filePath input when path is empty, and cover both with regression tests.
34 lines
948 B
TypeScript
34 lines
948 B
TypeScript
export interface FileReference {
|
|
filePath: string
|
|
lineNumber?: number
|
|
startIndex: number
|
|
endIndex: number
|
|
fullMatch: string
|
|
}
|
|
|
|
const FILE_REFERENCE_PATTERN = /(?<![\w\-./:])([\w\-./]+\.(ts|tsx|js|jsx|py|java|cpp|c|h|hpp|go|rs|rb|php|swift|kt|cs|vue|svelte|css|scss|sass|less|html|htm|xml|json|yaml|yml|md|txt|sh|bash|sql|graphql|proto|toml|ini|conf|env))(?::(\d+))?\b/gi
|
|
|
|
export function detectFileReferences(text: string): FileReference[] {
|
|
const references: FileReference[] = []
|
|
const regex = new RegExp(FILE_REFERENCE_PATTERN)
|
|
let match: RegExpExecArray | null
|
|
|
|
while ((match = regex.exec(text)) !== null) {
|
|
const fullMatch = match[0]
|
|
const filePath = match[1]
|
|
const lineNumber = match[3] ? parseInt(match[3], 10) : undefined
|
|
|
|
references.push({
|
|
filePath,
|
|
lineNumber,
|
|
startIndex: match.index,
|
|
endIndex: match.index + fullMatch.length,
|
|
fullMatch,
|
|
})
|
|
}
|
|
|
|
return references
|
|
}
|
|
|
|
|