diff --git a/src/content/components/DictPanelPortal/index.tsx b/src/content/components/DictPanelPortal/index.tsx index 51f4d81bd..e9dc25edb 100644 --- a/src/content/components/DictPanelPortal/index.tsx +++ b/src/content/components/DictPanelPortal/index.tsx @@ -11,7 +11,9 @@ import { Omit } from '@/typings/helpers' export type DictPanelPortalDispatchers = Omit< DictPanelDispatchers, 'updateItemHeight' | 'updateDragArea' -> +> & { + showPanel: (flag: boolean) => any +} export interface DictPanelPortalProps extends DictPanelPortalDispatchers { readonly isFav: boolean @@ -23,7 +25,10 @@ export interface DictPanelPortalProps extends DictPanelPortalDispatchers { } type DictPanelState= { + /** copy current props to compare with the next props */ readonly propsSelection: SelectionState | null + + readonly isNewSelection: boolean readonly x: number readonly y: number readonly height: number @@ -38,6 +43,8 @@ export default class DictPanelPortal extends React.Component { @@ -101,11 +108,13 @@ export default class DictPanelPortal extends React.Component { this.root.appendChild(this.el) this.isMount = true + this.props.showPanel(true) } unmountEL = () => { this.root.removeChild(this.el) this.isMount = false + this.props.showPanel(false) } frameWillUnmount = () => { @@ -131,25 +140,23 @@ export default class DictPanelPortal extends React.Component { const { direct, ctrl, icon, double } = config.mode const shouldShow = ( - selection.selectionInfo.text && - icon && - !widget.isPinned && - !direct && - !(double && selection.dbClick) && - !(ctrl && selection.ctrlKey) + widget.isMouseOnBowl || ( + selection.selectionInfo.text && + icon && + !widget.isPanelShow && + !direct && + !(double && selection.dbClick) && + !(ctrl && selection.ctrlKey) + ) ) return { diff --git a/src/content/redux/modules/widget.ts b/src/content/redux/modules/widget.ts index 1847325ff..9989ccd3e 100644 --- a/src/content/redux/modules/widget.ts +++ b/src/content/redux/modules/widget.ts @@ -8,7 +8,8 @@ import { StoreState } from './index' export const enum Actions { PIN = 'widget/PIN', FAV_WORD = 'dicts/FAV_WORD', - MOUSE_ON_BOWL = 'disct/MOUSE_ON_BOWL' + MOUSE_ON_BOWL = 'disct/MOUSE_ON_BOWL', + SHOW_PANEL = 'disct/SHOW_PANEL', } /*-----------------------------------------------*\ @@ -19,12 +20,14 @@ export type WidgetState = { readonly isPinned: boolean readonly isFav: boolean readonly isMouseOnBowl: boolean + readonly isPanelShow: boolean } const initState: WidgetState = { isPinned: false, isFav: false, isMouseOnBowl: false, + isPanelShow: false, } export default function reducer (state = initState, action): WidgetState { @@ -39,6 +42,10 @@ export default function reducer (state = initState, action): WidgetState { return state.isMouseOnBowl === action.payload ? state : { ...state, isMouseOnBowl: action.payload } + case Actions.SHOW_PANEL: + return state.isPanelShow === action.payload + ? state + : { ...state, isPanelShow: action.payload } default: return state } @@ -62,6 +69,10 @@ export function mouseOnBowl (payload: boolean): Action { return ({ type: Actions.MOUSE_ON_BOWL, payload }) } +export function showPanel (payload: boolean): Action { + return ({ type: Actions.SHOW_PANEL, payload }) +} + /*-----------------------------------------------*\ Side Effects \*-----------------------------------------------*/