Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(unified-list): update block when navigating j and k (#96)

Caleb Taylorff1813b041ba
diff --git a/js/app/packages/app/component/EntityNavigationIndicator.tsx b/js/app/packages/app/component/EntityNavigationIndicator.tsx
new file mode 100644
index 0000000000..61650035c9
--- /dev/null
+++ b/js/app/packages/app/component/EntityNavigationIndicator.tsx
@@ -0,0 +1,65 @@
+import { useSplitPanelOrThrow } from '@app/component/split-layout/layoutUtils';
+import { IconButton } from '@core/component/IconButton';
+import { runCommandByToken } from '@core/hotkey/hotkeys';
+import { TOKENS } from '@core/hotkey/tokens';
+import CaretDown from '@icon/regular/caret-down.svg';
+import CaretUp from '@icon/regular/caret-up.svg';
+import { Show } from 'solid-js';
+
+const EntityNavigationIndicator = () => {
+ const {
+ unifiedListContext: {
+ entitiesSignal: [entities],
+ selectedView,
+ viewsDataStore,
+ },
+ handle,
+ } = useSplitPanelOrThrow();
+ const selectedViewData = () => viewsDataStore[selectedView()];
+ const selectedEntity = () => selectedViewData().selectedEntity;
+ const selectedEntityIndex = () =>
+ entities()?.findIndex((item) => item.id === selectedEntity()?.id) ?? -1;
+ return (
+ <Show
+ when={
+ entities()?.length &&
+ selectedEntity() &&
+ handle.content().type !== 'component'
+ }
+ >
+ <div class="flex gap-1 items-center font-mono text-xs text-ink/50 pl-2 pr-4">
+ <div>
+ [<span class="text-ink">{selectedEntityIndex() + 1}</span>/
+ {entities()?.length}]
+ </div>
+ <div>{selectedViewData().view}</div>
+ <div class="flex text-ink">
+ <IconButton
+ size="sm"
+ icon={CaretDown}
+ tooltip={{
+ label: 'Navigate Down',
+ hotkeyToken: TOKENS.entity.step.end,
+ }}
+ disabled={selectedEntityIndex() >= entities()!.length - 1}
+ theme="current"
+ onClick={() => runCommandByToken(TOKENS.entity.step.end)}
+ />
+ <IconButton
+ size="sm"
+ icon={CaretUp}
+ tooltip={{
+ label: 'Navigate Up',
+ hotkeyToken: TOKENS.entity.step.start,
+ }}
+ disabled={selectedEntityIndex() === 0}
+ theme="current"
+ onClick={() => runCommandByToken(TOKENS.entity.step.start)}
+ />
+ </div>
+ </div>
+ </Show>
+ );
+};
+
+export default EntityNavigationIndicator;
diff --git a/js/app/packages/app/component/SoupContext.tsx b/js/app/packages/app/component/SoupContext.tsx
index a6288b306f..ebfa797d0e 100644
--- a/js/app/packages/app/component/SoupContext.tsx
+++ b/js/app/packages/app/component/SoupContext.tsx
@@ -308,6 +308,18 @@ export function createNavigationEntityListShortcut({
const selectedEntity = entities()?.at(index);
if (selectedEntity) {
+ if (splitHandle.content().type !== 'component') {
+ const { type, id } = selectedEntity;
+ if (type === 'document') {
+ const { fileType } = selectedEntity;
+ splitHandle.replace(
+ { type: fileTypeToBlockName(fileType), id },
+ true
+ );
+ } else {
+ splitHandle.replace({ type, id }, true);
+ }
+ }
batch(() => {
setViewDataStore(selectedView(), 'highlightedId', selectedEntity.id);
setViewDataStore(selectedView(), 'selectedEntity', selectedEntity);
@@ -434,7 +446,7 @@ export function createNavigationEntityListShortcut({
);
registerHotkey({
- hotkey: ['arrowdown', 'j'],
+ hotkey: ['j', 'arrowdown'],
scopeId: splitHotkeyScope,
description: 'Down',
hotkeyToken: TOKENS.entity.step.end,
@@ -445,7 +457,7 @@ export function createNavigationEntityListShortcut({
hide: true,
});
registerHotkey({
- hotkey: ['arrowup', 'k'],
+ hotkey: ['k', 'arrowup'],
scopeId: splitHotkeyScope,
hotkeyToken: TOKENS.entity.step.start,
description: 'Up',
diff --git a/js/app/packages/app/component/split-layout/components/SplitHeader.tsx b/js/app/packages/app/component/split-layout/components/SplitHeader.tsx
index b2f8af6a76..bf40a25e3e 100644
--- a/js/app/packages/app/component/split-layout/components/SplitHeader.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitHeader.tsx
@@ -1,3 +1,4 @@
+import EntityNavigationIndicator from '@app/component/EntityNavigationIndicator';
import { IconButton } from '@core/component/IconButton';
import { ResizeZoneContext } from '@core/component/Resize/Resize';
import { TOKENS } from '@core/hotkey/tokens';
@@ -170,6 +171,7 @@ export function SplitHeader(props: { ref: Setter<HTMLDivElement | null> }) {
}}
/>
<div class="z-2 relative flex items-center bg-panel pr-2 border-t border-t-edge-muted border-b border-b-edge-muted h-full">
+ <EntityNavigationIndicator />
<SplitSpotlightButton />
<SplitCreateButton />
</div>
diff --git a/js/app/packages/app/component/split-layout/components/SplitLabel.tsx b/js/app/packages/app/component/split-layout/components/SplitLabel.tsx
index caf91bd00d..00a854669d 100644
--- a/js/app/packages/app/component/split-layout/components/SplitLabel.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitLabel.tsx
@@ -29,9 +29,16 @@ export function StaticSplitLabel(props: {
return (
<div class="z-3 relative flex items-center gap-2 border-y border-edge-muted w-screen max-w-full h-full shrink">
<Show when={props.iconType}>
- <EntityIcon targetType={props.iconType} size="xs" theme="monochrome" />
+ <EntityIcon
+ class="shrink-0"
+ targetType={props.iconType}
+ size="xs"
+ theme="monochrome"
+ />
+ </Show>
+ <Show when={props.icon}>
+ <div class="shrink-0">{props.icon}</div>
</Show>
- <Show when={props.icon}>{props.icon}</Show>
<Show when={props.badges}>{props.badges}</Show>
<span class="inline-block text-sm truncate">{props.label}</span>
</div>
@@ -135,7 +142,7 @@ export function BlockItemSplitLabel(props: {
return (
<div class="z-3 relative flex items-center gap-2 border-y border-edge-muted w-screen max-w-full h-full shrink">
- <EntityIcon targetType={blockName} size="xs" />
+ <EntityIcon class="shrink-0" targetType={blockName} size="xs" />
<Show when={props.badges}>{props.badges}</Show>
<SplitLabel
label={fileName()}
diff --git a/js/app/packages/app/component/useNavigatedFromJK.ts b/js/app/packages/app/component/useNavigatedFromJK.ts
new file mode 100644
index 0000000000..b40bd2f8e0
--- /dev/null
+++ b/js/app/packages/app/component/useNavigatedFromJK.ts
@@ -0,0 +1,19 @@
+import { createMemo } from 'solid-js';
+import { useSplitPanelOrThrow } from './split-layout/layoutUtils';
+
+export function useNavigatedFromJK() {
+ const {
+ unifiedListContext: {
+ entitiesSignal: [_entities],
+ },
+ } = useSplitPanelOrThrow();
+ const navigatedFromJK = createMemo(() => {
+ const entities = _entities();
+ if (!entities) return false;
+ return (
+ entities.length > 0 &&
+ document.documentElement.getAttribute('data-modality') === 'keyboard'
+ );
+ });
+ return { navigatedFromJK };
+}
diff --git a/js/app/packages/block-channel/component/BaseInput.tsx b/js/app/packages/block-channel/component/BaseInput.tsx
index f35ec7dbad..ec19026f84 100644
--- a/js/app/packages/block-channel/component/BaseInput.tsx
+++ b/js/app/packages/block-channel/component/BaseInput.tsx
@@ -34,6 +34,7 @@ import {
type Accessor,
createEffect,
createMemo,
+ createRenderEffect,
createSignal,
For,
onCleanup,
@@ -90,6 +91,7 @@ type BaseInputProps = {
setLocalTyping?: (isTyping: boolean) => void;
/** the list of users in the channel */
channelUsers?: () => IUser[];
+ domRef?: (ref: HTMLDivElement) => void | HTMLDivElement;
};
/** the time after a user stops typing before we consider them idle */
@@ -161,8 +163,14 @@ export function BaseInput(props: BaseInputProps) {
setNodeFormat,
mentions,
MarkdownArea,
+ ref,
} = useChannelMarkdownArea();
+ createRenderEffect(() => {
+ const _ref = ref();
+ if (_ref) props.domRef?.(_ref);
+ });
+
const allMentions: Accessor<SimpleMention[]> = () =>
mentions().map((m) => ({
entity_type: m.itemType,
@@ -414,6 +422,7 @@ export function BaseInput(props: BaseInputProps) {
initialValue={props.initialValue?.()}
useBlockBoundary={true}
onEscape={onEscape}
+ dontFocusOnMount
onFocusLeaveStart={props.onFocusLeaveStart}
onFocusLeaveEnd={onFocusLeaveEnd}
/>
diff --git a/js/app/packages/block-channel/component/Channel.tsx b/js/app/packages/block-channel/component/Channel.tsx
index 4f3fb4a8b4..06e99b33cc 100644
--- a/js/app/packages/block-channel/component/Channel.tsx
+++ b/js/app/packages/block-channel/component/Channel.tsx
@@ -1,4 +1,5 @@
import { useGlobalNotificationSource } from '@app/component/GlobalAppState';
+import { useNavigatedFromJK } from '@app/component/useNavigatedFromJK';
import type { ChannelData } from '@block-channel/definition';
import {
latestActivitySignal,
@@ -40,7 +41,7 @@ import { createDroppable, useDragDropContext } from '@thisbeyond/solid-dnd';
import { toast } from 'core/component/Toast/Toast';
import { registerHotkey } from 'core/hotkey/hotkeys';
import { createMethodRegistration } from 'core/orchestrator';
-import { createSignal, onMount } from 'solid-js';
+import { createRenderEffect, createSignal, onMount } from 'solid-js';
import { createStore } from 'solid-js/store';
import { type FocusableElement, tabbable } from 'tabbable';
import { ChannelInput } from './ChannelInput';
@@ -174,6 +175,9 @@ export function Channel(props: { data: Required<ChannelData> }) {
const focusPrevious = () => {
const tabbableEls = tabbable(blockRef()!);
const activeEl = document.activeElement;
+ if (activeEl === channelWrapperRef() || activeEl === document.body)
+ return false;
+
const activeElIndex = tabbableEls.indexOf(activeEl as FocusableElement);
if (activeElIndex !== -1) {
const prevIndex = activeElIndex - 1;
@@ -194,6 +198,21 @@ export function Channel(props: { data: Required<ChannelData> }) {
return focusPrevious();
};
+ registerHotkey({
+ hotkey: 'enter',
+ scopeId: scopeId(),
+ description: 'Focus Channel Input',
+ keyDownHandler: () => {
+ if (channelInputRef()) {
+ channelInputRef()?.focus();
+ return true;
+ }
+ return false;
+ },
+ hotkeyToken: TOKENS.channel.focusInput,
+ hide: true,
+ });
+
registerHotkey({
hotkey: ['arrowup', 'k', 'shift+tab'],
scopeId: scopeId(),
@@ -226,9 +245,35 @@ export function Channel(props: { data: Required<ChannelData> }) {
hotkeyToken: TOKENS.channel.focusNextMessage,
hide: true,
});
+ const [channelInputRef, setChannelInputRef] = createSignal<
+ HTMLDivElement | undefined
+ >();
+ const [channelWrapperRef, setChannelWrapperRef] = createSignal<
+ HTMLDivElement | undefined
+ >();
+ const [autoFocusOnMount, setAutoFocusOnMount] = createSignal(true);
+
+ const { navigatedFromJK } = useNavigatedFromJK();
+
+ createRenderEffect(() => {
+ if (navigatedFromJK()) {
+ setAutoFocusOnMount(false);
+ }
+ });
+
+ onMount(() => {
+ if (autoFocusOnMount()) return;
+ if (!navigatedFromJK()) return;
+
+ channelWrapperRef()?.focus();
+ });
return (
- <div class={`relative flex flex-col w-full h-full bg-panel`}>
+ <div
+ class={`relative flex flex-col w-full h-full bg-panel bracket-never`}
+ tabIndex={-1}
+ ref={setChannelWrapperRef}
+ >
<ChannelDebouncedNotificationReadMarker
notificationSource={notificationSource}
channelId={channelId}
@@ -278,6 +323,8 @@ export function Channel(props: { data: Required<ChannelData> }) {
setInputAttachmentsStore={setChannelInputAttachmentsStore}
inputAttachmentsKey={channelId}
onFocusLeaveStart={onChannelInputFocusLeaveStart}
+ autoFocusOnMount={autoFocusOnMount()}
+ domRef={setChannelInputRef}
/>
</div>
</div>
diff --git a/js/app/packages/block-channel/component/ChannelInput.tsx b/js/app/packages/block-channel/component/ChannelInput.tsx
index 5790bdd3c0..52e311cc07 100644
--- a/js/app/packages/block-channel/component/ChannelInput.tsx
+++ b/js/app/packages/block-channel/component/ChannelInput.tsx
@@ -23,6 +23,8 @@ export type ChannelInputProps = {
inputAttachmentsKey: string;
channelName: string;
onFocusLeaveStart?: (e: KeyboardEvent) => void;
+ autoFocusOnMount?: boolean;
+ domRef?: (ref: HTMLDivElement) => void | HTMLDivElement;
};
export function ChannelInput(props: ChannelInputProps) {
@@ -82,6 +84,8 @@ export function ChannelInput(props: ChannelInputProps) {
}}
onFocusLeaveStart={props.onFocusLeaveStart}
channelUsers={channelUsers}
+ autoFocusOnMount={props.autoFocusOnMount}
+ domRef={props.domRef}
/>
);
}
diff --git a/js/app/packages/block-chat/component/Block.tsx b/js/app/packages/block-chat/component/Block.tsx
index 6ab8515266..85a08bdd67 100644
--- a/js/app/packages/block-chat/component/Block.tsx
+++ b/js/app/packages/block-chat/component/Block.tsx
@@ -15,7 +15,9 @@ export default function ChatBlock() {
return (
<DocumentBlockContainer title={title()}>
- <Show when={chatBlockData()}>{(data) => <Chat data={data()} />}</Show>
+ <div class="size-full bracket-never" tabIndex={-1}>
+ <Show when={chatBlockData()}>{(data) => <Chat data={data()} />}</Show>
+ </div>
</DocumentBlockContainer>
);
}
diff --git a/js/app/packages/block-chat/component/Chat.tsx b/js/app/packages/block-chat/component/Chat.tsx
index 24385476b2..960c346dc1 100644
--- a/js/app/packages/block-chat/component/Chat.tsx
+++ b/js/app/packages/block-chat/component/Chat.tsx
@@ -1,3 +1,4 @@
+import { useNavigatedFromJK } from '@app/component/useNavigatedFromJK';
import type { SendBuilder } from '@block-chat/blockClient';
import { TopBar } from '@block-chat/component/TopBar';
import type { ChatData } from '@block-chat/definition';
@@ -17,18 +18,28 @@ import {
storeChatState,
} from '@core/component/AI/util/storage';
import { usePaywallState } from '@core/constant/PaywallState';
+import { registerHotkey } from '@core/hotkey/hotkeys';
import { createMethodRegistration } from '@core/orchestrator';
+import {
+ blockElementSignal,
+ blockHotkeyScopeSignal,
+} from '@core/signal/blockElement';
import { blockHandleSignal } from '@core/signal/load';
import { useCanEdit } from '@core/signal/permissions';
import { invalidateUserQuota } from '@service-auth/userQuota';
import { cognitionWebsocketServiceClient } from '@service-cognition/client';
import { createCallback } from '@solid-primitives/rootless';
+import type { LexicalEditor } from 'lexical';
import { createEffect, createSignal, Show } from 'solid-js';
import { pendingLocationParamsSignal } from '../signal/pendingLocationParams';
export function Chat(props: { data: ChatData }) {
const canEdit = useCanEdit();
const disabled = () => !canEdit();
+ const scopeId = blockHotkeyScopeSignal.get;
+ const blockElement = blockElementSignal.get;
+ const { navigatedFromJK } = useNavigatedFromJK();
+ const [chatEditor, setChatEditor] = createSignal<LexicalEditor>();
const [stream, setStream] = createSignal<MessageStream>();
const cancelStream = () => {
@@ -136,6 +147,31 @@ export function Chat(props: { data: ChatData }) {
},
});
+ createEffect(() => {
+ if (scopeId()) {
+ registerHotkey({
+ hotkey: 'enter',
+ scopeId: scopeId(),
+ description: 'Focus Chat Input',
+ keyDownHandler: () => {
+ const editor = chatEditor();
+ if (editor) {
+ editor.focus(undefined, { defaultSelection: 'rootStart' });
+ return true;
+ }
+ return false;
+ },
+ hide: true,
+ });
+ }
+ });
+
+ createEffect(() => {
+ if (!blockElement()) return;
+ if (!navigatedFromJK()) return;
+ blockElement()?.focus();
+ });
+
return (
<DragDropWrapper
class="size-full bg-panel overscroll-none overflow-hidden flex flex-col"
@@ -152,7 +188,12 @@ export function Chat(props: { data: ChatData }) {
<Show when={!disabled()}>
<div class="flex w-full justify-center pb-2 px-4">
<div class="w-3xl">
- <ChatInput onSend={onSend} onStop={cancelStream} />
+ <ChatInput
+ onSend={onSend}
+ onStop={cancelStream}
+ captureEditor={setChatEditor}
+ autoFocusOnMount={!navigatedFromJK()}
+ />
</div>
</div>
</Show>
diff --git a/js/app/packages/block-email/component/BaseInput.tsx b/js/app/packages/block-email/component/BaseInput.tsx
index e94d00e6d4..d7eae7a9b3 100644
--- a/js/app/packages/block-email/component/BaseInput.tsx
+++ b/js/app/packages/block-email/component/BaseInput.tsx
@@ -131,6 +131,7 @@ export function BaseInput(props: {
draftContainsAppendedReply?: boolean;
preloadedAttachments?: AttachmentMacro[];
sideEffectOnSend?: (newMessageId: MessageToSendDbId | null) => void;
+ markdownDomRef?: (ref: HTMLDivElement) => void | HTMLDivElement;
}) {
const ctx = useEmailContext();
const form = createMemo(() =>
@@ -800,6 +801,7 @@ export function BaseInput(props: {
portalScope="local"
formatState={formatState}
setFormatState={setFormatState}
+ domRef={props.markdownDomRef}
/>
</div>
<Show when={!replyAppended()}>
diff --git a/js/app/packages/block-email/component/Block.tsx b/js/app/packages/block-email/component/Block.tsx
index f50929b623..41d113d3c2 100644
--- a/js/app/packages/block-email/component/Block.tsx
+++ b/js/app/packages/block-email/component/Block.tsx
@@ -51,7 +51,7 @@ export default function BlockEmail() {
return (
<DocumentBlockContainer title={title() ?? 'Email'}>
- <div class="contents">
+ <div class="size-full bracket-never" tabIndex={-1}>
<Show when={blockData()}>
<Show when={blockData()?.thread?.db_id}>
{(threadId) => {
diff --git a/js/app/packages/block-email/component/Email.tsx b/js/app/packages/block-email/component/Email.tsx
index 29572bf78d..708810443f 100644
--- a/js/app/packages/block-email/component/Email.tsx
+++ b/js/app/packages/block-email/component/Email.tsx
@@ -1,5 +1,5 @@
import { useGlobalNotificationSource } from '@app/component/GlobalAppState';
-import { TOKENS } from '@core/hotkey/tokens';
+import { registerHotkey } from '@core/hotkey/hotkeys';
import {
blockElementSignal,
blockHotkeyScopeSignal,
@@ -19,7 +19,6 @@ import type { MessageWithBodyReplyless } from '@service-email/generated/schemas'
import type { Thread } from '@service-email/generated/schemas/thread';
import { createCallback } from '@solid-primitives/rootless';
import { useSearchParams } from '@solidjs/router';
-import { registerHotkey } from 'core/hotkey/hotkeys';
import {
type Accessor,
createEffect,
@@ -56,6 +55,8 @@ type EmailProps = {
export function Email(props: EmailProps) {
const scopeId = blockHotkeyScopeSignal.get;
+
+ console.log('scopeId()', scopeId());
const setIsScrollingToMessage = isScrollingToMessage.set;
const { navigateThread } = useThreadNavigation();
const blockElement = blockElementSignal.get;
@@ -487,23 +488,6 @@ export function Email(props: EmailProps) {
navigateToPreviousMessage,
navigateToNextMessage,
});
- registerHotkey({
- hotkey: 'k',
- scopeId: scopeId(),
- description: 'Next email',
- keyDownHandler: () => navigateThread('down'),
- hotkeyToken: TOKENS.email.nextThread,
- displayPriority: 10,
- });
-
- registerHotkey({
- hotkey: 'j',
- scopeId: scopeId(),
- description: 'Previous email',
- keyDownHandler: () => navigateThread('up'),
- hotkeyToken: TOKENS.email.previousThread,
- displayPriority: 9,
- });
});
createEffect(() => {
@@ -539,6 +523,25 @@ export function Email(props: EmailProps) {
}
}
);
+ let markdownDomRef!: HTMLDivElement;
+
+ createEffect(() => {
+ if (scopeId()) {
+ registerHotkey({
+ hotkey: 'enter',
+ scopeId: scopeId(),
+ description: 'Focus Email Input',
+ keyDownHandler: () => {
+ if (markdownDomRef) {
+ markdownDomRef.focus();
+ return true;
+ }
+ return false;
+ },
+ hide: true,
+ });
+ }
+ });
return (
<EmailProvider
@@ -575,6 +578,9 @@ export function Email(props: EmailProps) {
<EmailInput
replyingTo={lastMessage}
draft={messageDbIdToDraftChildren[lastMessage().db_id ?? '']}
+ markdownDomRef={(el) => {
+ markdownDomRef = el;
+ }}
/>
</div>
)}
diff --git a/js/app/packages/block-email/component/EmailInput.tsx b/js/app/packages/block-email/component/EmailInput.tsx
index fa2c7c5194..e83ea310ab 100644
--- a/js/app/packages/block-email/component/EmailInput.tsx
+++ b/js/app/packages/block-email/component/EmailInput.tsx
@@ -12,6 +12,7 @@ import { useEmailContext } from './EmailContext';
interface EmailInputProps {
replyingTo: Accessor<MessageWithBodyReplyless>;
draft?: MessageWithBodyReplyless;
+ markdownDomRef?: (ref: HTMLDivElement) => void | HTMLDivElement;
}
export function EmailInput(props: EmailInputProps) {
@@ -70,6 +71,7 @@ export function EmailInput(props: EmailInputProps) {
preloadedHtml={draftHTML()}
draftContainsAppendedReply={draftContainsAppendedReply()}
sideEffectOnSend={afterSend}
+ markdownDomRef={props.markdownDomRef}
/>
</Show>
);
diff --git a/js/app/packages/block-md/component/Block.tsx b/js/app/packages/block-md/component/Block.tsx
index bf841a68b6..babbcafad4 100644
--- a/js/app/packages/block-md/component/Block.tsx
+++ b/js/app/packages/block-md/component/Block.tsx
@@ -43,7 +43,10 @@ export default function BlockMarkdown() {
return (
<DocumentBlockContainer>
- <div class="w-full h-full select-none overscroll-none overflow-hidden flex flex-col relative">
+ <div
+ class="w-full h-full select-none overscroll-none overflow-hidden flex flex-col relative bracket-never"
+ tabIndex={-1}
+ >
<div class="relative">
<Show when={!isInstructionsMd()} fallback={<InstructionsTopBar />}>
<TopBar />
diff --git a/js/app/packages/block-md/component/MarkdownEditor.tsx b/js/app/packages/block-md/component/MarkdownEditor.tsx
index 38b4c966ee..7374a92953 100644
--- a/js/app/packages/block-md/component/MarkdownEditor.tsx
+++ b/js/app/packages/block-md/component/MarkdownEditor.tsx
@@ -179,7 +179,7 @@ const EDITOR_PADDING_BOTTOM = 200;
const DRAG_EVENT_PADDING = 8;
-export function MarkdownEditor() {
+export function MarkdownEditor(props: { autoFocusOnMount?: boolean } = {}) {
const blockData = blockDataSignal.get;
const blockId = useBlockId();
@@ -838,6 +838,13 @@ export function MarkdownEditor() {
setEditorReady(true);
});
+ // Auto-focus on mount if enabled and editor is ready and empty.
+ createEffect(() => {
+ if (props.autoFocusOnMount && editorReady() && editorHasNoContent()) {
+ editor.focus(undefined, { defaultSelection: 'rootStart' });
+ }
+ });
+
const _generateContentCallback = createCallback((userRequest: string) => {
setIsGenerating(true);
generateContentCallback(userRequest);
diff --git a/js/app/packages/block-md/component/Notebook.tsx b/js/app/packages/block-md/component/Notebook.tsx
index 522f5984af..f535d75dd5 100644
--- a/js/app/packages/block-md/component/Notebook.tsx
+++ b/js/app/packages/block-md/component/Notebook.tsx
@@ -1,3 +1,4 @@
+import { useNavigatedFromJK } from '@app/component/useNavigatedFromJK';
import { CommentMargin } from '@block-md/comments/CommentMargin';
import {
commentsStore,
@@ -11,6 +12,11 @@ import {
ENABLE_MARKDOWN_COMMENTS,
ENABLE_PROPERTIES_METADATA,
} from '@core/constant/featureFlags';
+import { registerHotkey } from '@core/hotkey/hotkeys';
+import {
+ blockElementSignal,
+ blockHotkeyScopeSignal,
+} from '@core/signal/blockElement';
import { tempRedirectLocation } from '@core/signal/location';
import { useCanEdit } from '@core/signal/permissions';
import { useBlockDocumentName } from '@core/util/currentBlockDocumentName';
@@ -57,10 +63,13 @@ const widthToMode = (width: number): CommentLayoutMode => {
};
export function Notebook() {
+ const blockElement = blockElementSignal.get;
const setStore = mdStore.set;
const setWideEnoughForComments = commentWidthSignal.set;
const canEdit = useCanEdit();
const documentName = useBlockDocumentName();
+ const scopeId = blockHotkeyScopeSignal.get;
+ const md = mdStore.get;
let notebookRef!: HTMLDivElement;
let commentMarginRef: HTMLDivElement | undefined;
@@ -69,6 +78,7 @@ export function Notebook() {
const [layoutMode, setLayoutMode] = createSignal(CommentLayoutMode.none);
const [width, setWidth] = createSignal(0);
const [leftFloatX, setLeftFloatX] = createSignal(0);
+ const { navigatedFromJK } = useNavigatedFromJK();
const comments = commentsStore.get;
const hasComment = createMemo(() => {
@@ -143,6 +153,37 @@ export function Notebook() {
}
});
+ createEffect(() => {
+ if (scopeId()) {
+ registerHotkey({
+ hotkey: 'enter',
+ scopeId: scopeId(),
+ description: 'Focus Title or Markdown Editor',
+ keyDownHandler: () => {
+ const titleEditor = md.titleEditor;
+ const markdownEditor = md.editor;
+ const docName = untrack(documentName);
+
+ if (titleEditor && docName === '') {
+ titleEditor.focus();
+ return true;
+ } else if (markdownEditor) {
+ markdownEditor.focus(undefined, { defaultSelection: 'rootStart' });
+ return true;
+ }
+ return false;
+ },
+ hide: true,
+ });
+ }
+ });
+
+ createEffect(() => {
+ if (!blockElement()) return;
+ if (!navigatedFromJK()) return;
+ blockElement()?.focus();
+ });
+
const containerClasses = createMemo(() => {
const mode = layoutMode();
const shared = 'flex relative text-ink min-h-full min-w-0 isolate';
@@ -212,7 +253,7 @@ export function Notebook() {
return (
<div class={containerClasses()} ref={notebookRef}>
<div class={contentDivClasses()} ref={contentRef}>
- <TitleEditor />
+ <TitleEditor autoFocusOnMount={!navigatedFromJK()} />
<Show
when={ENABLE_PROPERTIES_METADATA}
fallback={<div class="h-6 w-full" />}
@@ -223,7 +264,7 @@ export function Notebook() {
fallback={<div class="h-6 w-full" />}
/>
</Show>
- <MarkdownEditor />
+ <MarkdownEditor autoFocusOnMount={!navigatedFromJK()} />
</div>
<div
class={commentPositioning().classes}
diff --git a/js/app/packages/block-md/component/TitleEditor.tsx b/js/app/packages/block-md/component/TitleEditor.tsx
index 707f7333b5..f29347da2f 100644
--- a/js/app/packages/block-md/component/TitleEditor.tsx
+++ b/js/app/packages/block-md/component/TitleEditor.tsx
@@ -127,7 +127,7 @@ function titleNavigationPlugin(
export const TitlePlaceholderSignal = createBlockSignal<string | undefined>();
-export function TitleEditor() {
+export function TitleEditor(props: { autoFocusOnMount?: boolean } = {}) {
const mdData = mdStore.get;
const setMdData = mdStore.set;
const blockData = blockDataSignal.get;
@@ -265,6 +265,15 @@ export function TitleEditor() {
}
});
+ // Auto-focus on mount if enabled and title is empty.
+ createEffect(() => {
+ if (props.autoFocusOnMount && dataReady()) {
+ if (untrack(mdDocumentName) === '') {
+ editor.focus();
+ }
+ }
+ });
+
return (
<div class="relative">
<div
diff --git a/js/app/packages/core/component/AI/component/input/useChatInput.tsx b/js/app/packages/core/component/AI/component/input/useChatInput.tsx
index ac7642720a..54063d833b 100644
--- a/js/app/packages/core/component/AI/component/input/useChatInput.tsx
+++ b/js/app/packages/core/component/AI/component/input/useChatInput.tsx
@@ -42,6 +42,7 @@ export type ChatInputProps = {
isPersistent?: boolean;
showActiveTabs?: boolean;
captureEditor?: (editor: LexicalEditor) => void;
+ autoFocusOnMount?: boolean;
};
type ChatInputInternalProps = {
@@ -203,7 +204,9 @@ function ChatInput(props: ChatInputInternalProps) {
onEnter={handleEnter}
placeholder="Ask AI - @mention anything"
history={availableAttachments}
- dontFocusOnMount={isMobileWidth()}
+ dontFocusOnMount={
+ isMobileWidth() || props.autoFocusOnMount === false
+ }
onPasteFile={props.uploadQueue.upload}
captureEditor={props.captureEditor}
/>
diff --git a/js/app/packages/core/component/BlockContainer.tsx b/js/app/packages/core/component/BlockContainer.tsx
index ee13a0fb67..f7fb6cd0d4 100644
--- a/js/app/packages/core/component/BlockContainer.tsx
+++ b/js/app/packages/core/component/BlockContainer.tsx
@@ -91,7 +91,6 @@ export function BlockContainer(props: BlockContainerProps) {
});
const [attachHotkeys, scopeId] = useHotkeyDOMScope(blockName ?? 'block');
-
setHotkeyScope(scopeId);
onMount(() => {
diff --git a/js/app/packages/core/component/EntityIcon.tsx b/js/app/packages/core/component/EntityIcon.tsx
index aa6c06fcd0..9409f815ff 100644
--- a/js/app/packages/core/component/EntityIcon.tsx
+++ b/js/app/packages/core/component/EntityIcon.tsx
@@ -281,6 +281,7 @@ export type EntityIconProps = {
* Render the icon with a subtle background color?
*/
useBackground?: boolean;
+ class?: string;
};
export type EntityIconSelector = EntityIconProps['targetType'];
@@ -311,6 +312,7 @@ export function EntityIcon(props: EntityIconProps) {
[config().background]: props.useBackground && !isMonochrome(),
[config().background]: props.useBackground && isMonochrome(),
'p-[20%]': props.useBackground,
+ [`${props.class}`]: !!props.class,
}}
>
<Dynamic component={icon()} />
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsx b/js/app/packages/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsx
index 851da2a271..bbe400d48e 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/core/MarkdownTextarea.tsx
@@ -86,6 +86,7 @@ export interface MarkdownTextareaProps {
onFocusLeaveEnd?: (e: KeyboardEvent) => void;
formatState?: SelectionData;
setFormatState?: SetStoreFunction<SelectionData>;
+ domRef?: (ref: HTMLDivElement) => void | HTMLDivElement;
}
export function MarkdownTextarea(props: MarkdownTextareaProps) {
@@ -230,6 +231,7 @@ export function MarkdownTextarea(props: MarkdownTextareaProps) {
onMount(() => {
editor.setRootElement(mountRef);
+ props.domRef?.(mountRef);
});
onCleanup(() => {
diff --git a/js/app/packages/core/hotkey/tokens.ts b/js/app/packages/core/hotkey/tokens.ts
index db43690f3f..9f047ca471 100644
--- a/js/app/packages/core/hotkey/tokens.ts
+++ b/js/app/packages/core/hotkey/tokens.ts
@@ -155,6 +155,7 @@ export const TOKENS = {
collapseThread: 'channel.collapseThread',
focusPreviousMessage: 'channel.focusPreviousMessage',
focusNextMessage: 'channel.focusNextMessage',
+ focusInput: 'channel.focusInput',
sendMessage: 'channel.sendMessage',
},