diff --git a/apps/desktop/layer/renderer/src/modules/command/commands/layout.tsx b/apps/desktop/layer/renderer/src/modules/command/commands/layout.tsx index 08c5c7f02..ed8b1bdc7 100644 --- a/apps/desktop/layer/renderer/src/modules/command/commands/layout.tsx +++ b/apps/desktop/layer/renderer/src/modules/command/commands/layout.tsx @@ -7,11 +7,14 @@ import { useRegisterCommandEffect } from "../hooks/use-register-command" import type { Command } from "../types" import { COMMAND_ID } from "./id" +interface FocusEvent { + highlightBoundary: boolean +} declare module "@follow/utils/event-bus" { interface EventBusMap { - "layout:focus-to-timeline": never - "layout:focus-to-subscription": never - "layout:focus-to-entry-render": never + "layout:focus-to-timeline": FocusEvent + "layout:focus-to-subscription": FocusEvent + "layout:focus-to-entry-render": FocusEvent } } @@ -28,21 +31,21 @@ export const useRegisterLayoutCommands = () => { id: COMMAND_ID.layout.focusToTimeline, label: "Focus to timeline", run: () => { - EventBus.dispatch(COMMAND_ID.layout.focusToTimeline) + EventBus.dispatch(COMMAND_ID.layout.focusToTimeline, { highlightBoundary: true }) }, }, { id: COMMAND_ID.layout.focusToSubscription, label: "Focus to subscription", run: () => { - EventBus.dispatch(COMMAND_ID.layout.focusToSubscription) + EventBus.dispatch(COMMAND_ID.layout.focusToSubscription, { highlightBoundary: true }) }, }, { id: COMMAND_ID.layout.focusToEntryRender, label: "Enter Selected Entry", run: () => { - EventBus.dispatch(COMMAND_ID.layout.focusToEntryRender) + EventBus.dispatch(COMMAND_ID.layout.focusToEntryRender, { highlightBoundary: true }) }, }, { diff --git a/apps/desktop/layer/renderer/src/modules/entry-column/layouts/EntryItemWrapper.tsx b/apps/desktop/layer/renderer/src/modules/entry-column/layouts/EntryItemWrapper.tsx index 3b9ea8854..96cd32664 100644 --- a/apps/desktop/layer/renderer/src/modules/entry-column/layouts/EntryItemWrapper.tsx +++ b/apps/desktop/layer/renderer/src/modules/entry-column/layouts/EntryItemWrapper.tsx @@ -77,7 +77,10 @@ export const EntryItemWrapper: FC< entryId: entry.entries.id, }) - setTimeout(() => EventBus.dispatch(COMMAND_ID.layout.focusToEntryRender), 60) + setTimeout( + () => EventBus.dispatch(COMMAND_ID.layout.focusToEntryRender, { highlightBoundary: false }), + 60, + ) }, [asRead, entry.entries.id, entry.feedId, navigate], ) diff --git a/apps/desktop/layer/renderer/src/providers/global-hotkeys-provider.tsx b/apps/desktop/layer/renderer/src/providers/global-hotkeys-provider.tsx index 7390fe3bd..01cc1a7c7 100644 --- a/apps/desktop/layer/renderer/src/providers/global-hotkeys-provider.tsx +++ b/apps/desktop/layer/renderer/src/providers/global-hotkeys-provider.tsx @@ -42,7 +42,7 @@ export const GlobalHotkeysProvider = () => { activeScopes[0] === HotkeyScope.Home && e.target === document.body ) { - EventBus.dispatch(COMMAND_ID.layout.focusToTimeline) + EventBus.dispatch(COMMAND_ID.layout.focusToTimeline, { highlightBoundary: true }) } }) // Re force to sidebar focusable @@ -53,7 +53,7 @@ export const GlobalHotkeysProvider = () => { activeScopes.length === 1 && activeScopes[0] === HotkeyScope.Home ) { - EventBus.dispatch(COMMAND_ID.layout.focusToTimeline) + EventBus.dispatch(COMMAND_ID.layout.focusToTimeline, { highlightBoundary: true }) } }) diff --git a/packages/internal/utils/src/event-bus.ts b/packages/internal/utils/src/event-bus.ts index 1cc338814..ac3651743 100644 --- a/packages/internal/utils/src/event-bus.ts +++ b/packages/internal/utils/src/event-bus.ts @@ -11,11 +11,18 @@ class EventBusEvent extends Event { super(EventBusEvent.type) } } + +type IDispatcher = ( + ...args: E[T] extends never ? [event: T] : [event: T, data: E[T]] +) => void type AnyObject = Record class EventBusStatic { - dispatch(event: T, data: E[T]): void - dispatch(event: T): void - dispatch(event: T, data?: E[T]) { + constructor() { + this.dispatch = this.dispatch.bind(this) + this.subscribe = this.subscribe.bind(this) + this.unsubscribe = this.unsubscribe.bind(this) + } + dispatch: IDispatcher = (event: T, data?: E[T]) => { window.dispatchEvent(new EventBusEvent(event as string, data)) }