mirror of
https://litchi.icu/ngc2207/judge.git
synced 2025-05-19 05:26:33 +00:00
feat: enhance code editor with improved options and multilingual support
This commit is contained in:
parent
6a88409a32
commit
3cf2cd156a
Binary file not shown.
@ -4,6 +4,7 @@ import {
|
|||||||
DEFAULT_EDITOR_LANGUAGE,
|
DEFAULT_EDITOR_LANGUAGE,
|
||||||
} from "@/config";
|
} from "@/config";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import * as monaco from "monaco-editor";
|
||||||
import { highlighter } from "@/lib/shiki";
|
import { highlighter } from "@/lib/shiki";
|
||||||
import { Bot, CodeXml } from "lucide-react";
|
import { Bot, CodeXml } from "lucide-react";
|
||||||
import { shikiToMonaco } from "@shikijs/monaco";
|
import { shikiToMonaco } from "@shikijs/monaco";
|
||||||
@ -31,7 +32,7 @@ function App() {
|
|||||||
strokeWidth={2}
|
strokeWidth={2}
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
/>
|
/>
|
||||||
Code
|
代码
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
<TabsTrigger
|
<TabsTrigger
|
||||||
value="diff-editor"
|
value="diff-editor"
|
||||||
@ -43,21 +44,45 @@ function App() {
|
|||||||
strokeWidth={2}
|
strokeWidth={2}
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
/>
|
/>
|
||||||
AI Assistant
|
AI 助教
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
</TabsList>
|
</TabsList>
|
||||||
<ScrollBar orientation="horizontal" />
|
<ScrollBar orientation="horizontal" />
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
<TabsContent value="code-editor" className="h-full">
|
<TabsContent value="code-editor" className="h-full mt-0">
|
||||||
<Editor
|
<Editor
|
||||||
theme={theme}
|
theme={theme}
|
||||||
path={file.path}
|
path={file.path}
|
||||||
defaultLanguage={file.language}
|
defaultLanguage={file.language}
|
||||||
defaultValue={file.value}
|
defaultValue={file.value}
|
||||||
options={{ automaticLayout: true, minimap: { enabled: false } }}
|
options={{
|
||||||
|
minimap: { enabled: false },
|
||||||
|
fontSize: 16,
|
||||||
|
tabSize: 2,
|
||||||
|
showFoldingControls: "always",
|
||||||
|
automaticLayout: true,
|
||||||
|
autoIndent: "full",
|
||||||
|
guides: {
|
||||||
|
bracketPairs: true,
|
||||||
|
indentation: true,
|
||||||
|
},
|
||||||
|
padding: { top: 8 },
|
||||||
|
}}
|
||||||
beforeMount={async (monaco: Monaco) => {
|
beforeMount={async (monaco: Monaco) => {
|
||||||
shikiToMonaco(await highlighter, monaco);
|
shikiToMonaco(await highlighter, monaco);
|
||||||
}}
|
}}
|
||||||
|
onMount={(
|
||||||
|
editor: monaco.editor.IStandaloneCodeEditor,
|
||||||
|
monaco: Monaco
|
||||||
|
) => {
|
||||||
|
const value = editor.getModel()?.getValue();
|
||||||
|
if (value !== undefined) {
|
||||||
|
window.parent.postMessage(
|
||||||
|
{ type: "editor-info", language, code: value },
|
||||||
|
"*"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
window.parent.postMessage(
|
window.parent.postMessage(
|
||||||
@ -68,13 +93,24 @@ function App() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
<TabsContent value="diff-editor" className="h-full">
|
<TabsContent value="diff-editor" className="h-full mt-0">
|
||||||
<DiffEditor
|
<DiffEditor
|
||||||
theme={theme}
|
theme={theme}
|
||||||
language={file.language}
|
language={file.language}
|
||||||
original={file.value}
|
original={file.value}
|
||||||
modified={file.value}
|
modified={file.value}
|
||||||
options={{ automaticLayout: true, minimap: { enabled: false } }}
|
options={{
|
||||||
|
minimap: { enabled: false },
|
||||||
|
fontSize: 16,
|
||||||
|
showFoldingControls: "always",
|
||||||
|
automaticLayout: true,
|
||||||
|
autoIndent: "full",
|
||||||
|
guides: {
|
||||||
|
bracketPairs: true,
|
||||||
|
indentation: true,
|
||||||
|
},
|
||||||
|
padding: { top: 8 },
|
||||||
|
}}
|
||||||
beforeMount={async (monaco: Monaco) => {
|
beforeMount={async (monaco: Monaco) => {
|
||||||
shikiToMonaco(await highlighter, monaco);
|
shikiToMonaco(await highlighter, monaco);
|
||||||
}}
|
}}
|
||||||
|
Loading…
Reference in New Issue
Block a user