Skip to content

Commit

Permalink
feat(web): format code on save (#1002)
Browse files Browse the repository at this point in the history
* feat(web): format code on save

* fix(web): json data max height
  • Loading branch information
LeezQ committed Apr 4, 2023
1 parent 378b0e6 commit e970a66
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion web/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/* 滚动条滑块 */
::-webkit-scrollbar-thumb {
border-radius: 4px;
background: rgba(0, 0, 0, 0.5);
background: rgba(0, 0, 0, 0.2);
}

html,
Expand Down
19 changes: 19 additions & 0 deletions web/src/components/Editor/FunctionEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import { useEffect, useRef } from "react";
import { debounce } from "lodash";
import * as monaco from "monaco-editor/esm/vs/editor/editor.api";

import { Pages } from "@/constants";

import "./userWorker";

import { AutoImportTypings } from "./typesResolve";

import useHotKey, { DEFAULT_SHORTCUTS } from "@/hooks/useHotKey";
import useGlobalStore from "@/pages/globalStore";

const autoImportTypings = new AutoImportTypings();
const parseImports = debounce(autoImportTypings.parse, 1500).bind(autoImportTypings);

Expand Down Expand Up @@ -108,6 +113,19 @@ function FunctionEditor(props: {
const subscriptionRef = useRef<monaco.IDisposable | undefined>(undefined);
const monacoEl = useRef(null);

const globalStore = useGlobalStore((state) => state);

useHotKey(
DEFAULT_SHORTCUTS.send_request,
() => {
// format
editorRef.current?.trigger("keyboard", "editor.action.formatDocument", {});
},
{
enabled: globalStore.currentPageId === Pages.function,
},
);

useEffect(() => {
if (monacoEl && !editorRef.current) {
editorRef.current = monaco.editor.create(monacoEl.current!, {
Expand All @@ -120,6 +138,7 @@ function FunctionEditor(props: {
scrollbar: {
verticalScrollbarSize: 6,
},
formatOnPaste: true,
overviewRulerLanes: 0,
lineNumbersMinChars: 4,
fontSize: 14,
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/Editor/JSONViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ export default function JSONViewer(props: JSONViewerProps) {
return (
<div
style={{
maxHeight: 100,
overflow: "hidden",
maxHeight: 390,
overflow: "auto",
}}
>
<SyntaxHighlighter
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Editor/JsonEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function JsonEditor(props: {
alwaysConsumeMouseWheel: false,
},
lineNumbersMinChars: 0,
fontSize: 14,
fontSize: 13,
scrollBeyondLastLine: false,
folding: false,
overviewRulerBorder: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from "react";
import { useColorMode } from "@chakra-ui/react";
import clsx from "clsx";
import { t } from "i18next";
Expand Down

0 comments on commit e970a66

Please sign in to comment.