From 1766e08f5c538d2f569dd2439e2fad2015741b0b Mon Sep 17 00:00:00 2001 From: Daniil Sloboda Date: Tue, 10 Sep 2024 18:08:09 +0400 Subject: [PATCH] #4965 - fixed tool reset on view only enabling --- .../ketcher-react/src/script/editor/Editor.ts | 2 +- .../src/script/ui/state/editor/index.js | 32 +++++++++++-------- .../modal/components/document/Open/Open.tsx | 14 ++++++-- .../process/Recognize/Recognize.jsx | 13 ++++++-- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/packages/ketcher-react/src/script/editor/Editor.ts b/packages/ketcher-react/src/script/editor/Editor.ts index 53258c516b..1077f6c42e 100644 --- a/packages/ketcher-react/src/script/editor/Editor.ts +++ b/packages/ketcher-react/src/script/editor/Editor.ts @@ -342,7 +342,7 @@ class Editor implements KetcherEditor { private updateToolAfterOptionsChange(wasViewOnlyEnabled: boolean) { const isViewOnlyEnabled = this.render.options.viewOnlyMode; if (!wasViewOnlyEnabled && isViewOnlyEnabled === true) { - this.tool('select'); + this.event.change.dispatch('force'); } } diff --git a/packages/ketcher-react/src/script/ui/state/editor/index.js b/packages/ketcher-react/src/script/ui/state/editor/index.js index c49dc47662..ca47b2090b 100644 --- a/packages/ketcher-react/src/script/ui/state/editor/index.js +++ b/packages/ketcher-react/src/script/ui/state/editor/index.js @@ -43,27 +43,31 @@ export default function initEditor(dispatch, getState) { const updateAction = debounce(100, () => dispatch({ type: 'UPDATE' })); const sleep = (time) => new Promise((resolve) => setTimeout(resolve, time)); - function resetToSelect(dispatch) { - // eslint-disable-line no-shadow - const state = global.currentState; - const activeTool = state.actionState.activeTool.tool; - if (activeTool === 'select') return; - const selectMode = state.toolbar.visibleTools.select; - const resetOption = state.options.settings.resetToSelect; - if (resetOption === true || resetOption === activeTool) - // example: 'paste' - dispatch({ type: 'ACTION', action: acts[selectMode].action }); - else updateAction(); - } + const resetToSelect = + (force = false) => + (dispatch) => { + // eslint-disable-line no-shadow + const state = global.currentState; + const activeTool = state.actionState.activeTool.tool; + if (activeTool === 'select') return; + const selectMode = state.toolbar.visibleTools.select; + const resetOption = state.options.settings.resetToSelect; + if (resetOption === true || resetOption === activeTool || force === true) + // example: 'paste' + dispatch({ type: 'ACTION', action: acts[selectMode].action }); + else updateAction(); + }; return { onInit: (editor) => { dispatch({ type: 'INIT', editor }); }, onChange: (action) => { - if (action === undefined) sleep(0).then(() => dispatch(resetToSelect)); + if (action === undefined) sleep(0).then(() => dispatch(resetToSelect())); + // Editor switched to view only mode + if (action === 'force') dispatch(resetToSelect(true)); // new tool in reducer - else dispatch(resetToSelect); + else dispatch(resetToSelect()); }, onSelectionChange: () => { updateAction(); diff --git a/packages/ketcher-react/src/script/ui/views/modal/components/document/Open/Open.tsx b/packages/ketcher-react/src/script/ui/views/modal/components/document/Open/Open.tsx index 76ec7be4fb..3795d95bab 100644 --- a/packages/ketcher-react/src/script/ui/views/modal/components/document/Open/Open.tsx +++ b/packages/ketcher-react/src/script/ui/views/modal/components/document/Open/Open.tsx @@ -22,7 +22,7 @@ import Recognize from '../../process/Recognize/Recognize'; import { fileOpener } from '../../../../../utils/'; import { DialogActionButton } from './components/DialogActionButton'; import { ViewSwitcher } from './components/ViewSwitcher'; -import { getFormatMimeTypeByFileName } from 'ketcher-core'; +import { getFormatMimeTypeByFileName, ketcherProvider } from 'ketcher-core'; interface OpenProps { server: any; errorHandler: (err: string) => void; @@ -42,7 +42,13 @@ const MODAL_STATES = { presentationViewer: 'presentationViewer', }; -const FooterContent = ({ structStr, openHandler, copyHandler, onCancel }) => { +const FooterContent = ({ + structStr, + openHandler, + copyHandler, + onCancel, + isAddToCanvasDisabled, +}) => { return (