@@ -2,13 +2,12 @@ import React, { useCallback, useContext, useRef, useEffect } from "react";
22import { EditorContext , EditorState } from "comps/editorState" ;
33import { GridCompOperator , readFromClipboard } from "comps/utils/gridCompOperator" ;
44import { HookCompOperator } from "comps/utils/hookCompOperator" ;
5- import { messageInstance } from "lowcoder-design" ;
6- import { trans } from "i18n" ;
75import { ExternalEditorContext } from "util/context/ExternalEditorContext" ;
86import { EditorHistory } from "util/editoryHistory" ;
97import { executeQueryAction } from "lowcoder-core" ;
108import {
119 GlobalShortcutsWrapper ,
10+ isFilterInputTarget ,
1211 modKeyPressed ,
1312 selectCompModifierKeyPressed ,
1413 ShortcutsWrapper ,
@@ -20,6 +19,11 @@ import { preview } from "constants/routesURL";
2019import { useApplicationId } from "util/hooks" ;
2120import { useUnmount } from "react-use" ;
2221
22+
23+ function isNativeClipboardContext ( e : KeyboardEvent | React . KeyboardEvent ) : boolean {
24+ return isFilterInputTarget ( e ) || ! ! window . getSelection ?.( ) ?. toString ( ) ;
25+ }
26+
2327async function handleCopyComps ( editorState : EditorState ) {
2428 const isHook = await HookCompOperator . copyComp ( editorState ) ;
2529 if ( ! isHook ) {
@@ -30,7 +34,6 @@ async function handleCopyComps(editorState: EditorState) {
3034async function handlePasteComps ( editorState : EditorState ) {
3135 const payload = await readFromClipboard ( ) ;
3236 if ( ! payload ) {
33- messageInstance . info ( trans ( "gridCompOperator.selectCompFirst" ) ) ;
3437 return ;
3538 }
3639
@@ -98,17 +101,18 @@ function handleGlobalKeyDown(
98101 break ;
99102 }
100103 default :
101- if ( modKeyPressed ( e ) ) {
104+ if ( modKeyPressed ( e ) && ! isNativeClipboardContext ( e ) ) {
102105 const key = e . key ?. toLowerCase ( ) ;
103- if ( key === "c" ) {
106+ const hasSelectedComps = editorState . selectedCompNames . size > 0 ;
107+ if ( key === "c" && hasSelectedComps ) {
104108 handleCopyComps ( editorState ) ;
105109 break ;
106110 }
107111 if ( key === "v" ) {
108112 handlePasteComps ( editorState ) ;
109113 break ;
110114 }
111- if ( key === "x" ) {
115+ if ( key === "x" && hasSelectedComps ) {
112116 GridCompOperator . cutComp ( editorState , editorState . selectedComps ( ) ) ;
113117 break ;
114118 }
@@ -236,12 +240,15 @@ function handleEditorKeyDown(e: React.KeyboardEvent, editorState: EditorState) {
236240 e . stopPropagation ( ) ;
237241 return ;
238242 case "copyComps" :
243+ if ( isNativeClipboardContext ( e ) || editorState . selectedCompNames . size === 0 ) return ;
239244 handleCopyComps ( editorState ) ;
240245 return ;
241246 case "pasteComps" :
247+ if ( isNativeClipboardContext ( e ) ) return ;
242248 handlePasteComps ( editorState ) ;
243249 return ;
244250 case "cutComps" :
251+ if ( isNativeClipboardContext ( e ) || editorState . selectedCompNames . size === 0 ) return ;
245252 GridCompOperator . cutComp ( editorState , editorState . selectedComps ( ) ) ;
246253 return ;
247254 case "deselectComps" :
0 commit comments