Skip to content

Commit 3f86a85

Browse files
committed
Add "open new file" in menu
1 parent d283d9b commit 3f86a85

File tree

7 files changed

+252
-212
lines changed

7 files changed

+252
-212
lines changed

android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
minSdkVersion rootProject.ext.minSdkVersion
99
targetSdkVersion rootProject.ext.targetSdkVersion
1010
versionCode 1
11-
versionName "1.0"
11+
versionName "v0.0.1-alpha"
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
aaptOptions {
1414
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.

components/nav-menu.tsx

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ export default function NavMenu({
6868

6969
const editorContext = useContext(EditorContext);
7070

71+
function openDocumentInView(doc: ViewDocument) {
72+
const view = new View(ViewTypeEnum.Code, doc);
73+
// Notify state update
74+
editorContext?.setViewManager((prev) => {
75+
const newVM = ViewManager.copy(prev);
76+
newVM?.clearView();
77+
// Add view to view manager
78+
newVM?.addView(view);
79+
// Set the view as active
80+
newVM?.setActiveView(view);
81+
return newVM;
82+
});
83+
84+
setIsMenuOpen(false);
85+
}
86+
7187
return (
7288
<AnimatePresence>
7389
{isMenuOpen && (
@@ -81,7 +97,18 @@ export default function NavMenu({
8197
Open Project
8298
</Button>
8399
<Button className="w-40">Save Project</Button>
84-
<Button className="w-40">New File</Button>
100+
<Button
101+
className="w-40"
102+
onPress={() => {
103+
const viewDocument: ViewDocument = {
104+
fileContent: "",
105+
filePath: "Untitled",
106+
};
107+
openDocumentInView(viewDocument);
108+
}}
109+
>
110+
New File
111+
</Button>
85112
<Button
86113
className="w-40"
87114
onPress={() => {
@@ -93,23 +120,7 @@ export default function NavMenu({
93120
fileContent: text,
94121
filePath: file.name,
95122
};
96-
const view = new View(
97-
ViewTypeEnum.Code,
98-
viewDocument,
99-
);
100-
101-
// Notify state update
102-
editorContext?.setViewManager((prev) => {
103-
const newVM = ViewManager.copy(prev);
104-
newVM?.clearView();
105-
// Add view to view manager
106-
newVM?.addView(view);
107-
// Set the view as active
108-
newVM?.setActiveView(view);
109-
return newVM;
110-
});
111-
112-
setIsMenuOpen(false);
123+
openDocumentInView(viewDocument);
113124
});
114125
});
115126
}}

components/views/code-editor-view.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ const CodeEditorView = forwardRef(
382382
javascript({ jsx: true }),
383383
codeInlineSuggestionExtension({
384384
delay: 1000,
385-
agent: inlineSuggestionAgentRef.current!,
385+
agent: inlineSuggestionAgentRef.current,
386386
}),
387387
]}
388388
theme={theme}

lib/codemirror-extensions/code-inline-suggestion.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ import {
1313
ViewUpdate,
1414
WidgetType,
1515
} from "@uiw/react-codemirror";
16+
import toast from "react-hot-toast";
1617

1718
/* A config facet for various inline suggestion settings */
1819
const codeInlineSuggestionConfig = Facet.define<
1920
{
2021
delay?: number;
21-
agent: InlineSuggestionAgent;
22+
agent?: InlineSuggestionAgent;
2223
},
2324
{
2425
delay?: number;
25-
agent: InlineSuggestionAgent;
26+
agent?: InlineSuggestionAgent;
2627
}
2728
>({
2829
combine(configs) {
@@ -157,6 +158,13 @@ const getSuggestionPlugin = ViewPlugin.fromClass(
157158
codeInlineSuggestionConfig,
158159
);
159160

161+
if (!agent) {
162+
toast.error("LLM not configured for code completion.", {
163+
id: "llm-not-configured",
164+
});
165+
return;
166+
}
167+
160168
this.getSuggestion(agent, doc.toString(), cursorX, cursorY, 1, delay)
161169
.then((suggestion) => {
162170
// Dispatch effect to update the StateField
@@ -328,7 +336,7 @@ export function codeInlineSuggestionExtension({
328336
agent,
329337
}: {
330338
delay: number;
331-
agent: InlineSuggestionAgent;
339+
agent?: InlineSuggestionAgent;
332340
}) {
333341
const config = codeInlineSuggestionConfig.of({ delay, agent });
334342
return [

0 commit comments

Comments
 (0)