feat(playground): add minimap checkbox component and integrate minimap functionality in code editor
This commit is contained in:
parent
a9ddf03e93
commit
1afa7a1a5d
@ -10,6 +10,9 @@
|
|||||||
},
|
},
|
||||||
"ligaturesCheckbox": {
|
"ligaturesCheckbox": {
|
||||||
"label": "Font Ligatures"
|
"label": "Font Ligatures"
|
||||||
|
},
|
||||||
|
"minimapCheckbox": {
|
||||||
|
"label": "Open Minimap"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
},
|
},
|
||||||
"ligaturesCheckbox": {
|
"ligaturesCheckbox": {
|
||||||
"label": "连字"
|
"label": "连字"
|
||||||
|
},
|
||||||
|
"minimapCheckbox": {
|
||||||
|
"label": "打开缩略图"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,8 @@ const ADDITIONAL_LANGUAGES = [
|
|||||||
export function CodeEditor() {
|
export function CodeEditor() {
|
||||||
const monacoRef = useRef<Monaco | null>(null);
|
const monacoRef = useRef<Monaco | null>(null);
|
||||||
const editorRef = useRef<editor.IStandaloneCodeEditor | null>(null);
|
const editorRef = useRef<editor.IStandaloneCodeEditor | null>(null);
|
||||||
const { lang, path, theme, value, isLigature } = useCodeEditorStore();
|
const { lang, path, theme, value, isMinimap, isLigature } =
|
||||||
|
useCodeEditorStore();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (monacoRef.current && editorRef.current) {
|
if (monacoRef.current && editorRef.current) {
|
||||||
@ -44,20 +45,22 @@ export function CodeEditor() {
|
|||||||
}, [theme]);
|
}, [theme]);
|
||||||
|
|
||||||
const options = useMemo(
|
const options = useMemo(
|
||||||
() => ({
|
() =>
|
||||||
minimap: { enabled: false },
|
({
|
||||||
fontSize: 14,
|
minimap: { enabled: isMinimap, size: "fit" },
|
||||||
fontFamily: "Fira Code Variable, monospace",
|
fontSize: 14,
|
||||||
tabSize: 4,
|
fontFamily: "Fira Code Variable, monospace",
|
||||||
showFoldingControls: "always" as const,
|
tabSize: 4,
|
||||||
fontLigatures: isLigature,
|
showFoldingControls: "always",
|
||||||
automaticLayout: true,
|
fontLigatures: isLigature,
|
||||||
guides: {
|
automaticLayout: true,
|
||||||
bracketPairs: true,
|
autoIndent: "full",
|
||||||
indentation: true,
|
guides: {
|
||||||
},
|
bracketPairs: true,
|
||||||
}),
|
indentation: true,
|
||||||
[isLigature]
|
},
|
||||||
|
} as editor.IStandaloneEditorConstructionOptions),
|
||||||
|
[isMinimap, isLigature]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleEditorMount = async (
|
const handleEditorMount = async (
|
||||||
|
18
src/app/playground/components/minimap-checkbox.tsx
Normal file
18
src/app/playground/components/minimap-checkbox.tsx
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
|
import { useCodeEditorStore } from "@/store/codeEditorStore";
|
||||||
|
|
||||||
|
export default function MinimapCheckbox() {
|
||||||
|
const t = useTranslations("Page.PlaygroundPage.Components.minimapCheckbox");
|
||||||
|
const { setIsMinimap } = useCodeEditorStore();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Checkbox onCheckedChange={setIsMinimap} />
|
||||||
|
<Label>{t("label")}</Label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
@ -10,6 +10,7 @@ import { ModeSwitcher } from "@/components/mode-switcher";
|
|||||||
import LanguageSwitcher from "@/components/language-switcher";
|
import LanguageSwitcher from "@/components/language-switcher";
|
||||||
import LigaturesCheckbox from "./components/ligatures-checkbox";
|
import LigaturesCheckbox from "./components/ligatures-checkbox";
|
||||||
import { PlaygroundSidebar } from "@/app/playground/components/playground-sidebar";
|
import { PlaygroundSidebar } from "@/app/playground/components/playground-sidebar";
|
||||||
|
import MinimapCheckbox from "./components/minimap-checkbox";
|
||||||
|
|
||||||
export default function PlaygroundLayout({
|
export default function PlaygroundLayout({
|
||||||
children,
|
children,
|
||||||
@ -26,6 +27,7 @@ export default function PlaygroundLayout({
|
|||||||
<Separator orientation="vertical" className="mr-2 h-4" />
|
<Separator orientation="vertical" className="mr-2 h-4" />
|
||||||
<ThemeSelector />
|
<ThemeSelector />
|
||||||
<LigaturesCheckbox />
|
<LigaturesCheckbox />
|
||||||
|
<MinimapCheckbox />
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-auto px-3">
|
<div className="ml-auto px-3">
|
||||||
<LanguageSwitcher />
|
<LanguageSwitcher />
|
||||||
|
@ -5,11 +5,13 @@ interface CodeEditorState {
|
|||||||
path: string;
|
path: string;
|
||||||
theme: string;
|
theme: string;
|
||||||
value: string;
|
value: string;
|
||||||
|
isMinimap: boolean;
|
||||||
isLigature: boolean;
|
isLigature: boolean;
|
||||||
setLang: (lang: string) => void;
|
setLang: (lang: string) => void;
|
||||||
setPath: (path: string) => void;
|
setPath: (path: string) => void;
|
||||||
setTheme: (theme: string) => void;
|
setTheme: (theme: string) => void;
|
||||||
setValue: (value: string) => void;
|
setValue: (value: string) => void;
|
||||||
|
setIsMinimap: (isMinimap: boolean) => void;
|
||||||
setIsLigature: (isLigature: boolean) => void;
|
setIsLigature: (isLigature: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,10 +20,12 @@ export const useCodeEditorStore = create<CodeEditorState>((set) => ({
|
|||||||
path: "",
|
path: "",
|
||||||
theme: "one-dark-pro",
|
theme: "one-dark-pro",
|
||||||
value: "",
|
value: "",
|
||||||
|
isMinimap: false,
|
||||||
isLigature: false,
|
isLigature: false,
|
||||||
setLang: (lang) => set({ lang }),
|
setLang: (lang) => set({ lang }),
|
||||||
setPath: (path) => set({ path }),
|
setPath: (path) => set({ path }),
|
||||||
setTheme: (theme) => set({ theme }),
|
setTheme: (theme) => set({ theme }),
|
||||||
setValue: (value) => set({ value }),
|
setValue: (value) => set({ value }),
|
||||||
|
setIsMinimap: (isMinimap) => set({ isMinimap }),
|
||||||
setIsLigature: (isLigature) => set({ isLigature }),
|
setIsLigature: (isLigature) => set({ isLigature }),
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user