({
workingDir,
className,
readOnly = false,
})
| 202 | ) |
| 203 | } |
| 204 | |
| 205 | export interface EditorViewHandle { |
| 206 | openFile: (path: string, line?: number, column?: number) => void |
| 207 | } |
| 208 | |
| 209 | type PendingLocation = { |
| 210 | path: string |
| 211 | line: number |
| 212 | column?: number |
| 213 | } |
| 214 | |
| 215 | export const EditorView = React.forwardRef<EditorViewHandle, { workingDir?: string; className?: string; readOnly?: boolean }>(function EditorView({ |
| 216 | workingDir, |
| 217 | className, |
| 218 | readOnly = false, |
| 219 | }, ref) { |
| 220 | const { t } = useI18n() |
| 221 | const [tabs, setTabs] = useState<OpenTab[]>([]) |
| 222 | const [activePath, setActivePath] = useState<string | null>(null) |
| 223 | const [editorReady, setEditorReady] = useState(false) |
| 224 | const [editorLoadFailed, setEditorLoadFailed] = useState(false) |
| 225 | const [editorMountVersion, setEditorMountVersion] = useState(0) |
| 226 | const [pendingLocation, setPendingLocation] = useState<PendingLocation | null>(null) |
| 227 | const editorInstanceRef = useRef<MonacoEditor.IStandaloneCodeEditor | null>(null) |
| 228 | const saveMutation = useSaveFile() |
| 229 | |
| 230 | useEffect(() => { |
| 231 | let cancelled = false |
| 232 | void import('@/lib/monaco') |
| 233 | .then(({ preloadMonaco }) => preloadMonaco()) |
| 234 | .then(() => { |
| 235 | if (!cancelled) setEditorReady(true) |
| 236 | }) |
| 237 | .catch(() => { |
| 238 | if (!cancelled) setEditorLoadFailed(true) |
| 239 | }) |
| 240 | return () => { |
| 241 | cancelled = true |
| 242 | } |
| 243 | }, []) |
| 244 | |
| 245 | // File tree width & collapse state |
| 246 | const [treeWidth, setTreeWidth] = useState(280) |
| 247 | const [treeCollapsed, setTreeCollapsed] = useState(false) |
| 248 | const [isDragging, setIsDragging] = useState(false) |
| 249 | const treeWidthBeforeCollapse = useRef(280) |
| 250 | |
| 251 | const toggleCollapse = useCallback(() => { |
| 252 | setTreeCollapsed((prev) => { |
| 253 | if (!prev) treeWidthBeforeCollapse.current = treeWidth |
| 254 | else setTreeWidth(treeWidthBeforeCollapse.current) |
| 255 | return !prev |
| 256 | }) |
| 257 | }, [treeWidth]) |
| 258 | |
| 259 | // Drag-to-resize logic |
| 260 | const onDragStart = useCallback((e: React.MouseEvent) => { |
| 261 | e.preventDefault() |
nothing calls this directly
no test coverage detected