From a94328fa956c5164111c27773f557b9761cd775e Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Mon, 30 Oct 2023 21:18:43 +0800 Subject: [PATCH] feat: add copy table cell content option to contextmenu #307 --- src/editor/core/contextmenu/menus/globalMenus.ts | 2 +- src/editor/core/draw/control/Control.ts | 4 ++-- src/editor/core/event/handlers/keydown.ts | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/editor/core/contextmenu/menus/globalMenus.ts b/src/editor/core/contextmenu/menus/globalMenus.ts index c06610a..c408d14 100644 --- a/src/editor/core/contextmenu/menus/globalMenus.ts +++ b/src/editor/core/contextmenu/menus/globalMenus.ts @@ -23,7 +23,7 @@ export const globalMenus: IRegisterContextMenu[] = [ i18nPath: 'contextmenu.global.copy', shortCut: `${isApple ? '⌘' : 'Ctrl'} + C`, when: payload => { - return payload.editorHasSelection + return payload.editorHasSelection || payload.isCrossRowCol }, callback: (command: Command) => { command.executeCopy() diff --git a/src/editor/core/draw/control/Control.ts b/src/editor/core/draw/control/Control.ts index 1f3ee55..d072225 100644 --- a/src/editor/core/draw/control/Control.ts +++ b/src/editor/core/draw/control/Control.ts @@ -84,8 +84,8 @@ export class Control { const startElement = elementList[startIndex] const endElement = elementList[endIndex] if ( - (startElement.type === ElementType.CONTROL || - endElement.type === ElementType.CONTROL) && + (startElement?.type === ElementType.CONTROL || + endElement?.type === ElementType.CONTROL) && startElement.controlId !== endElement.controlId ) { return true diff --git a/src/editor/core/event/handlers/keydown.ts b/src/editor/core/event/handlers/keydown.ts index 37cb033..6c457c9 100644 --- a/src/editor/core/event/handlers/keydown.ts +++ b/src/editor/core/event/handlers/keydown.ts @@ -24,10 +24,9 @@ export function keydown(evt: KeyboardEvent, host: CanvasEvent) { const isCollapsed = startIndex === endIndex // 当前激活控件 const control = draw.getControl() - const isPartRangeInControlOutside = control.isPartRangeInControlOutside() const activeControl = control.getActiveControl() if (evt.key === KeyMap.Backspace) { - if (isReadonly || isPartRangeInControlOutside) return + if (isReadonly || control.isPartRangeInControlOutside()) return let curIndex: number | null if (activeControl) { curIndex = control.keydown(evt) @@ -62,7 +61,7 @@ export function keydown(evt: KeyboardEvent, host: CanvasEvent) { rangeManager.setRange(curIndex, curIndex) draw.render({ curIndex }) } else if (evt.key === KeyMap.Delete) { - if (isReadonly || isPartRangeInControlOutside) return + if (isReadonly || control.isPartRangeInControlOutside()) return let curIndex: number | null if (activeControl) { curIndex = control.keydown(evt) @@ -84,7 +83,7 @@ export function keydown(evt: KeyboardEvent, host: CanvasEvent) { rangeManager.setRange(curIndex, curIndex) draw.render({ curIndex }) } else if (evt.key === KeyMap.Enter) { - if (isReadonly || isPartRangeInControlOutside) return + if (isReadonly || control.isPartRangeInControlOutside()) return const enterText: IElement = { value: ZERO }