mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2024-11-15 19:22:26 +08:00
chore: editor resizing debounce
Some checks failed
Alpha Build / alpha (macos-latest, aarch64-apple-darwin) (push) Has been cancelled
Alpha Build / alpha (macos-latest, x86_64-apple-darwin) (push) Has been cancelled
Alpha Build / alpha (windows-latest, aarch64-pc-windows-msvc) (push) Has been cancelled
Alpha Build / alpha (windows-latest, i686-pc-windows-msvc) (push) Has been cancelled
Alpha Build / alpha (windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
Alpha Build / alpha-for-linux (ubuntu-latest, aarch64-unknown-linux-gnu) (push) Has been cancelled
Alpha Build / alpha-for-linux (ubuntu-latest, armv7-unknown-linux-gnueabihf) (push) Has been cancelled
Alpha Build / alpha-for-linux (ubuntu-latest, i686-unknown-linux-gnu) (push) Has been cancelled
Alpha Build / alpha-for-linux (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Has been cancelled
Alpha Build / alpha-for-fixed-webview2 (arm64, windows-latest, aarch64-pc-windows-msvc) (push) Has been cancelled
Alpha Build / alpha-for-fixed-webview2 (x64, windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
Alpha Build / alpha-for-fixed-webview2 (x86, windows-latest, i686-pc-windows-msvc) (push) Has been cancelled
Alpha Build / Update tag (push) Has been cancelled
Some checks failed
Alpha Build / alpha (macos-latest, aarch64-apple-darwin) (push) Has been cancelled
Alpha Build / alpha (macos-latest, x86_64-apple-darwin) (push) Has been cancelled
Alpha Build / alpha (windows-latest, aarch64-pc-windows-msvc) (push) Has been cancelled
Alpha Build / alpha (windows-latest, i686-pc-windows-msvc) (push) Has been cancelled
Alpha Build / alpha (windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
Alpha Build / alpha-for-linux (ubuntu-latest, aarch64-unknown-linux-gnu) (push) Has been cancelled
Alpha Build / alpha-for-linux (ubuntu-latest, armv7-unknown-linux-gnueabihf) (push) Has been cancelled
Alpha Build / alpha-for-linux (ubuntu-latest, i686-unknown-linux-gnu) (push) Has been cancelled
Alpha Build / alpha-for-linux (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Has been cancelled
Alpha Build / alpha-for-fixed-webview2 (arm64, windows-latest, aarch64-pc-windows-msvc) (push) Has been cancelled
Alpha Build / alpha-for-fixed-webview2 (x64, windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
Alpha Build / alpha-for-fixed-webview2 (x86, windows-latest, i686-pc-windows-msvc) (push) Has been cancelled
Alpha Build / Update tag (push) Has been cancelled
This commit is contained in:
parent
df6e245e5c
commit
49e36b6e00
|
@ -18,6 +18,7 @@ import { Notice } from "@/components/base";
|
|||
import { nanoid } from "nanoid";
|
||||
import { appWindow } from "@tauri-apps/api/window";
|
||||
import getSystem from "@/utils/get-system";
|
||||
import debounce from "@/utils/debounce";
|
||||
|
||||
import * as monaco from "monaco-editor";
|
||||
import MonacoEditor from "react-monaco-editor";
|
||||
|
@ -144,12 +145,19 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
|||
}
|
||||
});
|
||||
|
||||
const editorResize = debounce(() => {
|
||||
editorRef.current?.layout();
|
||||
setTimeout(() => editorRef.current?.layout(), 500);
|
||||
}, 100);
|
||||
|
||||
useEffect(() => {
|
||||
const unlistenResized = appWindow.onResized(() => {
|
||||
const onResized = debounce(() => {
|
||||
editorResize();
|
||||
appWindow.isMaximized().then((maximized) => {
|
||||
setIsMaximized(() => maximized);
|
||||
});
|
||||
});
|
||||
}, 100);
|
||||
const unlistenResized = appWindow.onResized(onResized);
|
||||
|
||||
return () => {
|
||||
unlistenResized.then((fn) => fn());
|
||||
|
@ -221,14 +229,7 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
|||
size="medium"
|
||||
color="inherit"
|
||||
title={t(isMaximized ? "Minimize" : "Maximize")}
|
||||
onClick={() =>
|
||||
appWindow.toggleMaximize().then(() => {
|
||||
editorRef.current?.layout();
|
||||
setTimeout(() => {
|
||||
editorRef.current?.layout();
|
||||
}, 500);
|
||||
})
|
||||
}
|
||||
onClick={() => appWindow.toggleMaximize().then(editorResize)}
|
||||
>
|
||||
{isMaximized ? <CloseFullscreenIcon /> : <OpenInFullIcon />}
|
||||
</IconButton>
|
||||
|
|
12
src/utils/debounce.ts
Normal file
12
src/utils/debounce.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
export default function debounce<T extends (...args: any[]) => void>(
|
||||
func: T,
|
||||
wait: number
|
||||
): T {
|
||||
let timeout: ReturnType<typeof setTimeout> | null = null;
|
||||
return function (this: any, ...args: Parameters<T>) {
|
||||
if (timeout !== null) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
timeout = setTimeout(() => func.apply(this, args), wait);
|
||||
} as T;
|
||||
}
|
Loading…
Reference in New Issue
Block a user