mirror of
https://github.com/cfngc4594/monaco-editor-lsp-next.git
synced 2025-05-18 23:42:24 +00:00
refactor(ResetButton): replace useCodeEditorStore with useProblemEditor
This commit is contained in:
parent
0ae01d35bc
commit
00f83d69f1
@ -8,19 +8,28 @@ import {
|
|||||||
} from "@/components/ui/tooltip";
|
} from "@/components/ui/tooltip";
|
||||||
import { RotateCcw } from "lucide-react";
|
import { RotateCcw } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { EditorLanguage } from "@prisma/client";
|
import { useProblemEditor } from "@/hooks/use-problem-editor";
|
||||||
import { useCodeEditorStore } from "@/store/useCodeEditorStore";
|
|
||||||
|
|
||||||
interface ResetButtonProps {
|
export function ResetButton() {
|
||||||
templates: { language: EditorLanguage; template: string }[];
|
const { editor, currentTemplate } = useProblemEditor();
|
||||||
}
|
|
||||||
|
|
||||||
export default function ResetButton({
|
const handleReset = () => {
|
||||||
templates,
|
if (editor) {
|
||||||
}: ResetButtonProps) {
|
const model = editor.getModel();
|
||||||
const { editor, language } = useCodeEditorStore();
|
if (model) {
|
||||||
|
const fullRange = model.getFullModelRange();
|
||||||
const currentTemplate = templates.find((t) => t.language === language)?.template ?? "";
|
editor.pushUndoStop();
|
||||||
|
editor.executeEdits("reset-code", [
|
||||||
|
{
|
||||||
|
range: fullRange,
|
||||||
|
text: currentTemplate,
|
||||||
|
forceMoveMarkers: true,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
editor.pushUndoStop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TooltipProvider delayDuration={0}>
|
<TooltipProvider delayDuration={0}>
|
||||||
@ -30,23 +39,8 @@ export default function ResetButton({
|
|||||||
variant="outline"
|
variant="outline"
|
||||||
size="icon"
|
size="icon"
|
||||||
aria-label="Reset Code"
|
aria-label="Reset Code"
|
||||||
onClick={() => {
|
onClick={handleReset}
|
||||||
if (editor) {
|
disabled={!editor}
|
||||||
const model = editor.getModel();
|
|
||||||
if (model) {
|
|
||||||
const fullRange = model.getFullModelRange();
|
|
||||||
editor.pushUndoStop();
|
|
||||||
editor.executeEdits("reset-code", [
|
|
||||||
{
|
|
||||||
range: fullRange,
|
|
||||||
text: currentTemplate,
|
|
||||||
forceMoveMarkers: true,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
editor.pushUndoStop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
className="h-6 w-6 px-1.5 py-0.5 border-none shadow-none hover:bg-muted"
|
className="h-6 w-6 px-1.5 py-0.5 border-none shadow-none hover:bg-muted"
|
||||||
>
|
>
|
||||||
<RotateCcw size={16} strokeWidth={2} aria-hidden="true" />
|
<RotateCcw size={16} strokeWidth={2} aria-hidden="true" />
|
||||||
|
Loading…
Reference in New Issue
Block a user