Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions client/packages/lowcoder/src/comps/utils/gridCompOperator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,7 @@ export class GridCompOperator {
const payload = buildEmptyPayload();
payload.sourcePositionParams = sourcePositionParams;
payload.gridItems = gridItems;
const written = await writeToClipboard(payload);
if (written) {
messageInstance.success(trans("gridCompOperator.copyCompsSuccess", { compNum: gridItems.length }));
} else {
messageInstance.error(trans("gridCompOperator.clipboardWriteError"));
}
return written;
return writeToClipboard(payload);
}

static pasteFromPayload(editorState: EditorState, payload: LowcoderClipboardPayload): boolean {
Expand Down Expand Up @@ -244,7 +238,6 @@ export class GridCompOperator {
})
);
editorState.setSelectedCompNames(copyCompNames);
messageInstance.success(trans("gridCompOperator.pasteCompsSuccess", { compNum: copyCompNames.size }));
return true;
}

Expand Down
11 changes: 1 addition & 10 deletions client/packages/lowcoder/src/comps/utils/hookCompOperator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { HookComp } from "comps/hooks/hookComp";
import { EditorState } from "comps/editorState";
import { singletonHookComp } from "comps/hooks/hookCompTypes";
import { wrapActionExtraInfo } from "lowcoder-core";
import { messageInstance } from "lowcoder-design";
import { trans } from "i18n";
import {
writeHookOnlyToClipboard,
type ClipboardHookItem,
Expand Down Expand Up @@ -40,13 +38,7 @@ export class HookCompOperator {
return { compType, comp, name, fullValue };
});

const written = await writeHookOnlyToClipboard(hookItems);
if (written) {
messageInstance.success(trans("gridCompOperator.copyCompsSuccess", { compNum: hookItems.length }));
} else {
messageInstance.error(trans("gridCompOperator.clipboardWriteError"));
}
return written;
return writeHookOnlyToClipboard(hookItems);
}

static pasteFromPayload(editorState: EditorState, payload: LowcoderClipboardPayload): boolean {
Expand Down Expand Up @@ -86,7 +78,6 @@ export class HookCompOperator {
});

editorState.setSelectedCompNames(newNames, "leftPanel");
messageInstance.success(trans("gridCompOperator.pasteCompsSuccess", { compNum: newNames.size }));
return true;
}
}
19 changes: 13 additions & 6 deletions client/packages/lowcoder/src/pages/editor/editorHotKeys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import React, { useCallback, useContext, useRef, useEffect } from "react";
import { EditorContext, EditorState } from "comps/editorState";
import { GridCompOperator, readFromClipboard } from "comps/utils/gridCompOperator";
import { HookCompOperator } from "comps/utils/hookCompOperator";
import { messageInstance } from "lowcoder-design";
import { trans } from "i18n";
import { ExternalEditorContext } from "util/context/ExternalEditorContext";
import { EditorHistory } from "util/editoryHistory";
import { executeQueryAction } from "lowcoder-core";
import {
GlobalShortcutsWrapper,
isFilterInputTarget,
modKeyPressed,
selectCompModifierKeyPressed,
ShortcutsWrapper,
Expand All @@ -20,6 +19,11 @@ import { preview } from "constants/routesURL";
import { useApplicationId } from "util/hooks";
import { useUnmount } from "react-use";


function isNativeClipboardContext(e: KeyboardEvent | React.KeyboardEvent): boolean {
return isFilterInputTarget(e) || !!window.getSelection?.()?.toString();
}

async function handleCopyComps(editorState: EditorState) {
const isHook = await HookCompOperator.copyComp(editorState);
if (!isHook) {
Expand All @@ -30,7 +34,6 @@ async function handleCopyComps(editorState: EditorState) {
async function handlePasteComps(editorState: EditorState) {
const payload = await readFromClipboard();
if (!payload) {
messageInstance.info(trans("gridCompOperator.selectCompFirst"));
return;
}

Expand Down Expand Up @@ -98,17 +101,18 @@ function handleGlobalKeyDown(
break;
}
default:
if (modKeyPressed(e)) {
if (modKeyPressed(e) && !isNativeClipboardContext(e)) {
const key = e.key?.toLowerCase();
if (key === "c") {
const hasSelectedComps = editorState.selectedCompNames.size > 0;
if (key === "c" && hasSelectedComps) {
handleCopyComps(editorState);
break;
}
if (key === "v") {
handlePasteComps(editorState);
break;
}
if (key === "x") {
if (key === "x" && hasSelectedComps) {
GridCompOperator.cutComp(editorState, editorState.selectedComps());
break;
}
Expand Down Expand Up @@ -236,12 +240,15 @@ function handleEditorKeyDown(e: React.KeyboardEvent, editorState: EditorState) {
e.stopPropagation();
return;
case "copyComps":
if (isNativeClipboardContext(e) || editorState.selectedCompNames.size === 0) return;
handleCopyComps(editorState);
return;
case "pasteComps":
if (isNativeClipboardContext(e)) return;
handlePasteComps(editorState);
return;
case "cutComps":
if (isNativeClipboardContext(e) || editorState.selectedCompNames.size === 0) return;
GridCompOperator.cutComp(editorState, editorState.selectedComps());
return;
case "deselectComps":
Expand Down
Loading