Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,21 @@ const GitExplorerComponent: React.FC = () => {
if (!exp && (!entry.children || entry.children.length === 0)) await loadDirectory(entry.path, entry.path);
} else {
const bins = [".png",".jpg",".jpeg",".gif",".exe",".dll",".bin",".zip",".pdf",".ico",".woff",".woff2",".ttf"];
if (bins.some((e) => entry.name.toLowerCase().endsWith(e))) return;
try { const c = await invoke("read_file", { path: entry.path }); openFile(entry.path, entry.name, c); }
catch (e) { if (typeof e === "string" && e.includes("UTF-8")) openFile(entry.path, entry.name, t('editor.bin_file')); }
if (bins.some((e) => entry.name.toLowerCase().endsWith(e))) {
openFile(entry.path, entry.name, "", "binary");
return;
}
try {
const c = await invoke("read_file", { path: entry.path }, { silent: true });
openFile(entry.path, entry.name, c);
} catch (e) {
const msg = typeof e === "string" ? e : String(e);
if (msg.includes("UTF-8")) {
openFile(entry.path, entry.name, "", "binary");
} else {
console.error("[GitExplorer] Failed to read file", entry.path, e);
}
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/api/builtin.l10n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export function registerBuiltinTranslations() {
'terminal.error_connect': 'Error connecting to terminal: ',
'editor.empty_desc': 'Select a file from the explorer to begin',
'editor.view_not_found': 'View not found',
'editor.bin_file': '--- BINARY ---',
'editor.bin_file': 'The file is not displayed in the text editor because it is either binary or uses an unsupported text encoding.',

'onboarding.welcome': 'Welcome',
'onboarding.language': 'Language',
Expand Down Expand Up @@ -557,7 +557,7 @@ export function registerBuiltinTranslations() {
'terminal.error_connect': 'Error al conectar con la terminal: ',
'editor.empty_desc': 'Selecciona un archivo del explorador para comenzar',
'editor.view_not_found': 'Vista no encontrada',
'editor.bin_file': '--- BINARIO ---',
'editor.bin_file': 'El archivo no se muestra en el editor de texto porque es binario o utiliza una codificación de texto no compatible.',

'onboarding.welcome': 'Bienvenida',
'onboarding.language': 'Idioma',
Expand Down
7 changes: 7 additions & 0 deletions apps/desktop/src/components/EditorArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const EditorArea: React.FC = () => {

// Check if current tab is a virtual tab
const isVirtualTab = currentFile?.type === "virtual";
const isBinaryTab = currentFile?.type === "binary";

// Render virtual views
const renderVirtualView = () => {
Expand All @@ -173,6 +174,12 @@ const EditorArea: React.FC = () => {
<div className="flex-1 overflow-hidden relative" ref={containerRef}>
{isVirtualTab ? (
renderVirtualView()
) : isBinaryTab ? (
<div className="flex-1 h-full flex items-center justify-center p-8">
<p className="text-[13px] text-[#888] max-w-md text-center leading-relaxed">
{t('editor.bin_file')}
</p>
</div>
) : currentFile ? (
<MonacoEditor
height="100%"
Expand Down
9 changes: 6 additions & 3 deletions apps/desktop/src/context/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface FileState {
content: string;
isModified: boolean;
language: string;
type?: "file" | "virtual";
type?: "file" | "virtual" | "binary";
}

interface AppContextType {
Expand All @@ -25,7 +25,7 @@ interface AppContextType {

setLocale: (locale: string) => void;

openFile: (path: string, name: string, content: string, type?: "file" | "virtual") => void;
openFile: (path: string, name: string, content: string, type?: "file" | "virtual" | "binary") => void;
closeFile: (path: string) => void;
setCurrentFile: (file: FileState | null) => void;
updateFileContent: (path: string, content: string) => void;
Expand Down Expand Up @@ -371,7 +371,7 @@ export const AppProvider: React.FC<{ children: React.ReactNode }> = ({ children



const openFile = useCallback((path: string, name: string, content: string, type: "file" | "virtual" = "file") => {
const openFile = useCallback((path: string, name: string, content: string, type: "file" | "virtual" | "binary" = "file") => {
setOpenFiles((prev) => {
const existing = prev.find((f) => f.path === path);
Comment thread
matiaspalmac marked this conversation as resolved.
if (existing) {
Expand Down Expand Up @@ -421,6 +421,9 @@ export const AppProvider: React.FC<{ children: React.ReactNode }> = ({ children

const saveCurrentFile = async () => {
if (!currentFile) return;
// Only real file tabs are writable. Virtual tabs have no on-disk path,
// and binary tabs carry an empty content string that would overwrite the file.
if (currentFile.type && currentFile.type !== "file") return;
try {
const { invoke } = await import("@tauri-apps/api/core");
await invoke("write_file", { path: currentFile.path, content: currentFile.content });
Expand Down
Loading