mirror of
https://github.com/enso-org/enso.git
synced 2024-12-27 05:34:07 +03:00
Fix Esc not closing CB (#7800)
- Fixes #7799 The PR that introduced this bug stopped event propagation in certain cases, in order to fix another issue. This PR introduces a way to run an event handler, but indicate failure so further handlers (if any) are run, otherwise the event will be propagated all the way to the document root. # Important Notes None
This commit is contained in:
parent
af8a2c39d8
commit
f7e079aa43
@ -49,6 +49,7 @@ export default function Dashboard(props: DashboardProps) {
|
||||
const session = authProvider.useNonPartialUserSession()
|
||||
const { backend } = backendProvider.useBackend()
|
||||
const { setBackend } = backendProvider.useSetBackend()
|
||||
const { modal } = modalProvider.useModal()
|
||||
const { unsetModal } = modalProvider.useSetModal()
|
||||
const { localStorage } = localStorageProvider.useLocalStorage()
|
||||
const { shortcuts } = shortcutsProvider.useShortcuts()
|
||||
@ -70,6 +71,7 @@ export default function Dashboard(props: DashboardProps) {
|
||||
const [assetListEvents, dispatchAssetListEvent] =
|
||||
hooks.useEvent<assetListEventModule.AssetListEvent>()
|
||||
const [assetEvents, dispatchAssetEvent] = hooks.useEvent<assetEventModule.AssetEvent>()
|
||||
const modalRef = React.useRef<modalProvider.Modal | null>(null)
|
||||
|
||||
const isListingLocalDirectoryAndWillFail =
|
||||
backend.type === backendModule.BackendType.local && loadingProjectManagerDidFail
|
||||
@ -84,6 +86,10 @@ export default function Dashboard(props: DashboardProps) {
|
||||
setInitialized(true)
|
||||
}, [])
|
||||
|
||||
React.useEffect(() => {
|
||||
modalRef.current = modal
|
||||
}, [modal])
|
||||
|
||||
React.useEffect(() => {
|
||||
unsetModal()
|
||||
if (page === pageSwitcher.Page.editor) {
|
||||
@ -251,9 +257,15 @@ export default function Dashboard(props: DashboardProps) {
|
||||
|
||||
React.useEffect(() => {
|
||||
return shortcuts.registerKeyboardHandlers({
|
||||
[shortcutsModule.KeyboardAction.closeModal]: unsetModal,
|
||||
[shortcutsModule.KeyboardAction.closeModal]: () => {
|
||||
unsetModal()
|
||||
if (modalRef.current == null) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return false
|
||||
}
|
||||
},
|
||||
})
|
||||
}, [shortcuts, unsetModal])
|
||||
}, [shortcuts, /* should never change */ unsetModal])
|
||||
|
||||
const setBackendType = React.useCallback(
|
||||
(newBackendType: backendModule.BackendType) => {
|
||||
|
@ -246,13 +246,15 @@ export class ShortcutRegistry {
|
||||
keyboardShortcutsByKey: Record<string, KeyboardShortcut[]> = {}
|
||||
allKeyboardHandlers: Record<
|
||||
KeyboardAction,
|
||||
((event: KeyboardEvent | React.KeyboardEvent) => void)[]
|
||||
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
||||
((event: KeyboardEvent | React.KeyboardEvent) => boolean | void)[]
|
||||
> = makeKeyboardActionMap(() => [])
|
||||
/** The last handler (if any) for each action in
|
||||
* {@link ShortcutRegistry.allKeyboardHandlers}. */
|
||||
activeKeyboardHandlers: Record<
|
||||
KeyboardAction,
|
||||
((event: KeyboardEvent | React.KeyboardEvent) => void) | null
|
||||
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
||||
((event: KeyboardEvent | React.KeyboardEvent) => boolean | void) | null
|
||||
> = makeKeyboardActionMap(() => null)
|
||||
|
||||
/** Create a {@link ShortcutRegistry}. */
|
||||
@ -322,10 +324,12 @@ export class ShortcutRegistry {
|
||||
if (this.matchesKeyboardShortcut(shortcut, event)) {
|
||||
const handler = this.activeKeyboardHandlers[shortcut.action]
|
||||
if (handler != null) {
|
||||
handler(event)
|
||||
// The matching `false` return is immediately after this loop.
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return true
|
||||
const result = handler(event)
|
||||
if (result !== false) {
|
||||
// The matching `false` return is immediately after this loop.
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -360,7 +364,8 @@ export class ShortcutRegistry {
|
||||
* these handlers. */
|
||||
registerKeyboardHandlers(
|
||||
handlers: Partial<
|
||||
Record<KeyboardAction, (event: KeyboardEvent | React.KeyboardEvent) => void>
|
||||
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
||||
Record<KeyboardAction, (event: KeyboardEvent | React.KeyboardEvent) => boolean | void>
|
||||
>
|
||||
) {
|
||||
for (const action of Object.values(KeyboardAction)) {
|
||||
|
Loading…
Reference in New Issue
Block a user