diff --git a/src/components/ProShortcut/index.tsx b/src/components/ProShortcut/index.tsx index 74a1074947..878298abd2 100644 --- a/src/components/ProShortcut/index.tsx +++ b/src/components/ProShortcut/index.tsx @@ -17,7 +17,7 @@ import { type Key, keys, modifierKeys, normalKeys } from "./keys"; interface ProShortcutProps { title: string; description?: string; - defaultValue?: string; + value?: string; onChange?: (value: string) => void; } @@ -26,14 +26,14 @@ interface State { } const ProShortcut: FC = (props) => { - const { title, description, defaultValue = "", onChange } = props; + const { title, description, value = "", onChange } = props; const { t } = useTranslation(); const handleDefaultValue = () => { - if (!defaultValue) return []; + if (!value) return []; - return defaultValue.split("+").map((shortcut) => find(keys, { shortcut })!); + return value.split("+").map((shortcut) => find(keys, { shortcut })!); }; const containerRef = useRef(null); diff --git a/src/database/index.tsx b/src/database/index.tsx index 9b58dd826c..5a14fb9c3f 100644 --- a/src/database/index.tsx +++ b/src/database/index.tsx @@ -28,7 +28,7 @@ export const initDatabase = async () => { type TEXT, [group] TEXT, value TEXT, - search TEXT, + search TEXT, count INTEGER, width INTEGER, height INTEGER, diff --git a/src/pages/Clipboard/Panel/components/List/components/Item/index.tsx b/src/pages/Clipboard/Panel/components/List/components/Item/index.tsx index 828c306303..4c76fc480c 100644 --- a/src/pages/Clipboard/Panel/components/List/components/Item/index.tsx +++ b/src/pages/Clipboard/Panel/components/List/components/Item/index.tsx @@ -49,7 +49,7 @@ const Item: FC = (props) => { }; // 粘贴纯文本 - const pastePlainText = () => { + const pastePlain = () => { pasteClipboard(data, true); }; @@ -129,12 +129,12 @@ const Item: FC = (props) => { { label: t("clipboard.button.context_menu.paste_ocr_text"), hide: type !== "image" || /^[\s]*$/.test(search), - event: pastePlainText, + event: pastePlain, }, { label: t("clipboard.button.context_menu.paste_as_plain_text"), hide: type !== "html" && type !== "rtf", - event: pastePlainText, + event: pastePlain, }, { label: favorite diff --git a/src/pages/Clipboard/Panel/index.tsx b/src/pages/Clipboard/Panel/index.tsx index 45aeabf803..72e252085f 100644 --- a/src/pages/Clipboard/Panel/index.tsx +++ b/src/pages/Clipboard/Panel/index.tsx @@ -3,6 +3,7 @@ import Audio from "@/components/Audio"; import type { ClipboardItem, TablePayload } from "@/types/database"; import { listen } from "@tauri-apps/api/event"; import { registerAll, unregister } from "@tauri-apps/api/globalShortcut"; +import { appWindow } from "@tauri-apps/api/window"; import type { EventEmitter } from "ahooks/lib/useEventEmitter"; import { find, findIndex, isEqual, last, merge, range } from "lodash-es"; import { nanoid } from "nanoid"; @@ -128,9 +129,20 @@ const ClipboardPanel = () => { }, }); - // 监听快捷键 + // 监听窗口显隐的快捷键 useRegister(toggleWindowVisible, [shortcut.clipboard]); + // 监听粘贴为纯文本的快捷键 + useRegister(async () => { + const focused = await appWindow.isFocused(); + + if (!focused) return; + + const data = find(state.list, { id: state.activeId }); + + pasteClipboard(data, true); + }, [shortcut.pastePlain]); + // 获取剪切板内容 const getList = async () => { const { search, group, favorite } = state; diff --git a/src/pages/Clipboard/Settings/index.tsx b/src/pages/Clipboard/Settings/index.tsx index 5b7ff61e41..becaa545fb 100644 --- a/src/pages/Clipboard/Settings/index.tsx +++ b/src/pages/Clipboard/Settings/index.tsx @@ -92,9 +92,9 @@ const ClipboardSettings = () => { description={t( "preference.clipboard.content_settings.hints.paste_as_plain", )} - value={content.pastePlainText} + value={content.pastePlain} onChange={(value) => { - clipboardStore.content.pastePlainText = value; + clipboardStore.content.pastePlain = value; }} /> diff --git a/src/pages/Shortcut/index.tsx b/src/pages/Shortcut/index.tsx index 3b2420ca20..b5ba473772 100644 --- a/src/pages/Shortcut/index.tsx +++ b/src/pages/Shortcut/index.tsx @@ -11,7 +11,7 @@ const Shortcut = () => { { globalStore.shortcut.clipboard = value; }} @@ -19,13 +19,22 @@ const Shortcut = () => { { globalStore.shortcut.preference = value; }} /> + + { + globalStore.shortcut.pastePlain = value; + }} + /> ); }; diff --git a/src/plugins/clipboard.ts b/src/plugins/clipboard.ts index 1a7d38b904..14e536bdb0 100644 --- a/src/plugins/clipboard.ts +++ b/src/plugins/clipboard.ts @@ -228,9 +228,9 @@ export const writeImage = (value: string) => { * HTML 内容写入剪贴板 */ export const writeHTML = (text: string, html: string) => { - const { pastePlainText } = clipboardStore.content; + const { pastePlain } = clipboardStore.content; - if (pastePlainText) { + if (pastePlain) { return writeText(text); } @@ -244,9 +244,9 @@ export const writeHTML = (text: string, html: string) => { * 富文写入剪贴板 */ export const writeRTF = (text: string, rtf: string) => { - const { pastePlainText } = clipboardStore.content; + const { pastePlain } = clipboardStore.content; - if (pastePlainText) { + if (pastePlain) { return writeText(text); } @@ -295,7 +295,7 @@ export const onClipboardUpdate = ( * 将数据写入剪切板 * @param data 数据 */ -export const writeClipboard = async (data: ClipboardItem) => { +export const writeClipboard = async (data?: ClipboardItem) => { if (!data) return; const { type, value, search } = data; @@ -319,7 +319,7 @@ export const writeClipboard = async (data: ClipboardItem) => { * @param data 数据 * @param plain 是否纯文本粘贴 */ -export const pasteClipboard = async (data: ClipboardItem, plain = false) => { +export const pasteClipboard = async (data?: ClipboardItem, plain = false) => { if (!data) return; const { type, value } = data; diff --git a/src/stores/clipboard.ts b/src/stores/clipboard.ts index b5719e678e..a8bb42b245 100644 --- a/src/stores/clipboard.ts +++ b/src/stores/clipboard.ts @@ -20,7 +20,7 @@ export const CLIPBOARD_STORE_INITIAL_STATE: ClipboardStore = { content: { autoPaste: "double", ocr: true, - pastePlainText: false, + pastePlain: false, }, history: { diff --git a/src/types/store.d.ts b/src/types/store.d.ts index fb1ae15634..5e5360950f 100644 --- a/src/types/store.d.ts +++ b/src/types/store.d.ts @@ -36,6 +36,7 @@ export interface GlobalStore { enable: boolean; value: ModifierKey; }; + pastePlain?: string; }; // 只在当前系统环境使用 @@ -72,7 +73,7 @@ export interface ClipboardStore { content: { autoPaste: "single" | "double"; ocr: boolean; - pastePlainText: boolean; + pastePlain: boolean; }; // 历史记录