Skip to content

Commit 7142418

Browse files
committed
fix open issue
1 parent 933b1c5 commit 7142418

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

frontend/.eslintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": [
3+
"next/core-web-vitals",
4+
"next/typescript"
5+
]
6+
}

frontend/src/app/page.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ import EditorPane from "@/components/EditorPane";
1616
import PreviewPane from "@/components/PreviewPane";
1717
import AIPanel from "@/components/AIPanel";
1818
import StatusBar from "@/components/StatusBar";
19-
import RecentFilesMenu from "@/components/RecentFilesMenu";
20-
import { Files } from "@/lib/api";
2119

2220
export default function HomePage() {
2321
const editor = useEditor();
24-
const [showPreview, setShowPreview] = useState(true);
22+
const [showPreview] = useState(true);
2523
const [showAIPanel, setShowAIPanel] = useState(false);
26-
const [showRecent, setShowRecent] = useState(false);
2724
const monacoRef = useRef<MonacoEditor.IStandaloneCodeEditor | null>(null);
2825

2926
// Load recent files on mount and initialise preview
@@ -61,13 +58,8 @@ export default function HomePage() {
6158
if (!file) return;
6259
// For browser mode read directly; for Tauri we'd have a native path
6360
const text = await file.text();
64-
const name = file.name;
65-
// In pure browser we don't have an absolute path — use the filename as label
66-
const id = `tab-upload-${Date.now()}`;
67-
editor.newTab();
68-
setTimeout(() => {
69-
editor.handleContentChange(text);
70-
}, 0);
61+
// In pure browser we don't have an absolute path — use filename as tab label.
62+
editor.openTextAsTab(file.name, text, null);
7163
e.target.value = "";
7264
};
7365

frontend/src/hooks/useEditor.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ export function useEditor() {
102102
[tabs, refreshPreview]
103103
);
104104

105+
const openTextAsTab = useCallback(
106+
(label: string, content: string, filePath: string | null = null) => {
107+
const id = nextTabId();
108+
const tabLabel = label.trim() || "Untitled";
109+
const newTab = makeTab(id, tabLabel, content, filePath);
110+
setTabs((prev) => [...prev, newTab]);
111+
setActiveTabId(id);
112+
refreshPreview(content, filePath ?? undefined);
113+
},
114+
[refreshPreview]
115+
);
116+
105117
const saveFile = useCallback(
106118
async (filePath?: string) => {
107119
const path = filePath ?? activeTab.filePath;
@@ -174,6 +186,7 @@ export function useEditor() {
174186
setFontSize,
175187
handleContentChange,
176188
openFile,
189+
openTextAsTab,
177190
saveFile,
178191
newTab,
179192
closeTab,

0 commit comments

Comments
 (0)