mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-04-29 03:00:45 -04:00
* refactor session mgmt * defer file handling to runtime * add todo * refactor sessions a bit more * remove messages logic from FE * fix up socket handshake * refactor frontend auth a bit * first pass at redoing file explorer * implement directory suffix * fix up file tree * close agent on websocket close * remove session saving * move file refresh * remove getWorkspace * plumb path/code differently * fix build issues * fix the tests * fix npm build * add session rehydration * fix event serialization * logspam * fix user message rehydration * add get_event fn * agent state restoration * change history tracking for codeact * fix responsiveness of init * fix lint * lint * delint * fix prop * update tests * logspam * lint * fix test * revert codeact * change fileService to use API * fix up session loading * delint * delint * fix integration tests * revert test * fix up access to options endpoints * fix initial files load * delint * fix file initialization * fix mock server * fixl int * fix auth for html * Update frontend/src/i18n/translation.json Co-authored-by: Xingyao Wang <xingyao6@illinois.edu> * refactor sessions and sockets * avoid reinitializing the same session * fix reconnect issue * change up intro message * more guards on reinit * rename agent_session * delint * fix a bunch of tests * delint * fix last test * remove code editor context * fix build * fix any * fix dot notation * Update frontend/src/services/api.ts Co-authored-by: Boxuan Li <liboxuan@connect.hku.hk> * fix up error handling * Update opendevin/server/session/agent.py Co-authored-by: Boxuan Li <liboxuan@connect.hku.hk> * Update opendevin/server/session/agent.py Co-authored-by: Boxuan Li <liboxuan@connect.hku.hk> * Update frontend/src/services/session.ts Co-authored-by: Boxuan Li <liboxuan@connect.hku.hk> * fix build errs * fix else * add closed state * delint * Update opendevin/server/session/session.py Co-authored-by: Engel Nyst <enyst@users.noreply.github.com> --------- Co-authored-by: Xingyao Wang <xingyao6@illinois.edu> Co-authored-by: Graham Neubig <neubig@gmail.com> Co-authored-by: Boxuan Li <liboxuan@connect.hku.hk> Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
83 lines
2.6 KiB
TypeScript
83 lines
2.6 KiB
TypeScript
import Editor, { Monaco } from "@monaco-editor/react";
|
|
import { Tab, Tabs } from "@nextui-org/react";
|
|
import type { editor } from "monaco-editor";
|
|
import React, { useMemo } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { VscCode } from "react-icons/vsc";
|
|
import { useSelector } from "react-redux";
|
|
import { I18nKey } from "#/i18n/declaration";
|
|
import { RootState } from "#/store";
|
|
import FileExplorer from "./file-explorer/FileExplorer";
|
|
|
|
function CodeEditor(): JSX.Element {
|
|
const { t } = useTranslation();
|
|
const code = useSelector((state: RootState) => state.code.code);
|
|
const activeFilepath = useSelector((state: RootState) => state.code.path);
|
|
|
|
const selectedFileName = useMemo(() => {
|
|
const paths = activeFilepath.split("/");
|
|
return paths[paths.length - 1];
|
|
}, [activeFilepath]);
|
|
|
|
const handleEditorDidMount = (
|
|
editor: editor.IStandaloneCodeEditor,
|
|
monaco: Monaco,
|
|
) => {
|
|
// 定义一个自定义主题 - English: Define a custom theme
|
|
monaco.editor.defineTheme("my-theme", {
|
|
base: "vs-dark",
|
|
inherit: true,
|
|
rules: [],
|
|
colors: {
|
|
"editor.background": "#171717",
|
|
},
|
|
});
|
|
|
|
// 应用自定义主题 - English: apply custom theme
|
|
monaco.editor.setTheme("my-theme");
|
|
};
|
|
|
|
return (
|
|
<div className="flex h-full w-full bg-neutral-900 transition-all duration-500 ease-in-out">
|
|
<FileExplorer />
|
|
<div className="flex flex-col min-h-0 w-full">
|
|
<Tabs
|
|
disableCursorAnimation
|
|
classNames={{
|
|
base: "border-b border-divider border-neutral-600 mb-4",
|
|
tabList:
|
|
"w-full relative rounded-none bg-neutral-900 p-0 border-divider",
|
|
cursor: "w-full bg-neutral-600 rounded-none",
|
|
tab: "max-w-fit px-4 h-[36px]",
|
|
tabContent: "group-data-[selected=true]:text-white",
|
|
}}
|
|
aria-label="Options"
|
|
>
|
|
<Tab
|
|
key={selectedFileName.toLocaleLowerCase()}
|
|
title={selectedFileName}
|
|
/>
|
|
</Tabs>
|
|
<div className="flex grow items-center justify-center">
|
|
{selectedFileName === "" ? (
|
|
<div className="flex flex-col items-center text-neutral-400">
|
|
<VscCode size={100} />
|
|
{t(I18nKey.CODE_EDITOR$EMPTY_MESSAGE)}
|
|
</div>
|
|
) : (
|
|
<Editor
|
|
height="100%"
|
|
path={selectedFileName.toLocaleLowerCase()}
|
|
defaultValue=""
|
|
value={code}
|
|
onMount={handleEditorDidMount}
|
|
/>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default CodeEditor;
|