From 726a54a4c972030f8fca664caa7da864f2568a2c Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Thu, 14 Sep 2023 10:47:39 +0300 Subject: [PATCH] Link shortcut and formatting options zindex fix (#4326) --- scripts/core/editor3/components/Editor3.tsx | 1 + .../editor3/components/Editor3Component.tsx | 22 ++++++++++++++----- .../core/editor3/components/toolbar/index.tsx | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/scripts/core/editor3/components/Editor3.tsx b/scripts/core/editor3/components/Editor3.tsx index 94a61a7185..5fdf26c788 100644 --- a/scripts/core/editor3/components/Editor3.tsx +++ b/scripts/core/editor3/components/Editor3.tsx @@ -43,6 +43,7 @@ const mapStateToProps = (state) => ({ const mapDispatchToProps = (dispatch) => ({ onChange: (editorState: EditorState) => dispatch(actions.changeEditorState(editorState)), onTab: (e) => dispatch(actions.handleEditorTab(e)), + showPopup: (type, data) => dispatch(actions.showPopup(type, data)), dragDrop: (transfer, mediaType) => dispatch(actions.dragDrop(transfer, mediaType)), unlock: () => dispatch(actions.setLocked(false)), dispatch: (x) => dispatch(x), diff --git a/scripts/core/editor3/components/Editor3Component.tsx b/scripts/core/editor3/components/Editor3Component.tsx index e1c55e7729..b96e6a8219 100644 --- a/scripts/core/editor3/components/Editor3Component.tsx +++ b/scripts/core/editor3/components/Editor3Component.tsx @@ -26,7 +26,7 @@ import UnstyledBlock from './UnstyledBlock'; import UnstyledWrapper from './UnstyledWrapper'; import * as Suggestions from '../helpers/suggestions'; import {getCurrentAuthor} from '../helpers/author'; -import {setSpellcheckerProgress, applySpellcheck} from '../actions'; +import {setSpellcheckerProgress, applySpellcheck, PopupTypes} from '../actions'; import {noop} from 'lodash'; import {getSpellcheckWarningsByBlock} from './spellchecker/SpellcheckerDecorator'; import {getSpellchecker} from './spellchecker/default-spellcheckers'; @@ -141,6 +141,7 @@ interface IProps { onTab?(event): void; dragDrop?(): void; dispatch?(action: any): void; + showPopup?(type: any, data: any): void; } interface IState { @@ -277,7 +278,19 @@ export class Editor3Component extends React.Component { } keyBindingFn(e) { - const {key, shiftKey} = e; + const {key, shiftKey, ctrlKey} = e; + const selectionState = this.props.editorState.getSelection(); + + if ( + key === 'k' + && ctrlKey + && this.props.editorFormat.includes('link') + && selectionState.isCollapsed() !== true + ) { + this.props.showPopup(PopupTypes.Link, selectionState); + e.preventDefault(); + return ''; + } if (key === 'ArrowDown' || key === 'ArrowUp') { const autocompleteEl = document.querySelector(`.${editor3AutocompleteClassName}`) as HTMLElement | null; @@ -300,10 +313,7 @@ export class Editor3Component extends React.Component { // ctrl + X if (key === 'x' && KeyBindingUtil.hasCommandModifier(e)) { - const {editorState} = this.props; - const selection = editorState.getSelection(); - - if (!selection.isCollapsed()) { + if (!selectionState.isCollapsed()) { document.execCommand('copy'); // add selected text to clipboard return 'delete'; } diff --git a/scripts/core/editor3/components/toolbar/index.tsx b/scripts/core/editor3/components/toolbar/index.tsx index 1146c82c77..fdf46fe955 100644 --- a/scripts/core/editor3/components/toolbar/index.tsx +++ b/scripts/core/editor3/components/toolbar/index.tsx @@ -172,7 +172,7 @@ class ToolbarComponent extends React.Component { )} {has('embed') && (