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.

fix: open in same or new split behavior (#1416)

dev-rb4d6c1460306c
diff --git a/js/app/packages/app/component/Launcher.tsx b/js/app/packages/app/component/Launcher.tsx
index 327d7733bb..ef7cd74af6 100644
--- a/js/app/packages/app/component/Launcher.tsx
+++ b/js/app/packages/app/component/Launcher.tsx
@@ -39,7 +39,7 @@ const createBlock = async (spec: {
loading?: boolean;
shouldInsert?: boolean;
}) => {
- const { replaceSplit, insertSplit } = useSplitLayout();
+ const { openWithSplit } = useSplitLayout();
const { blockName, createFn, loading } = spec;
setCreateMenuOpen(false, false);
@@ -50,16 +50,20 @@ const createBlock = async (spec: {
const block = { type: blockName, id };
- spec.shouldInsert
- ? insertSplit(block, 'launcher')
- : replaceSplit({ content: block, referredFrom: 'launcher' });
+ openWithSplit(block, {
+ referredFrom: 'launcher',
+ preferNewSplit: spec.shouldInsert,
+ });
+
+ return;
} else {
- const split = spec.shouldInsert
- ? insertSplit({ type: 'component', id: 'loading' }, 'launcher')
- : replaceSplit({
- content: { type: 'component', id: 'loading' },
- referredFrom: 'launcher',
- });
+ const split = openWithSplit(
+ { type: 'component', id: 'loading' },
+ {
+ referredFrom: 'launcher',
+ preferNewSplit: spec.shouldInsert,
+ }
+ );
const id = await createFn();
if (!id) {
@@ -82,19 +86,19 @@ const createComponent = async (spec: {
asPopover?: boolean;
}) => {
setCreateMenuOpen(false, false);
- const { replaceSplit, insertSplit, popoverSplit } = useSplitLayout();
+ const { openWithSplit, popoverSplit } = useSplitLayout();
if (spec.asPopover) {
popoverSplit({ type: 'component', id: spec.componentId });
return;
}
- if (spec.shouldInsert) {
- insertSplit({ type: 'component', id: spec.componentId }, 'launcher');
- } else {
- replaceSplit({
- content: { type: 'component', id: spec.componentId },
+
+ openWithSplit(
+ { type: 'component', id: spec.componentId },
+ {
referredFrom: 'launcher',
- });
- }
+ preferNewSplit: spec.shouldInsert,
+ }
+ );
};
type CreatableBlock = Omit<HotkeyRegistrationOptions, 'scopeId'> & {
@@ -122,7 +126,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [
content: '',
projectId: undefined,
}),
- shouldInsert: !pressedKeys().has('opt'),
+ shouldInsert: pressedKeys().has('shift'),
});
return true;
},
@@ -158,7 +162,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [
keyDownHandler: () => {
createComponent({
componentId: 'email-compose',
- shouldInsert: !pressedKeys().has('opt'),
+ shouldInsert: pressedKeys().has('shift'),
});
return true;
},
@@ -174,7 +178,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [
keyDownHandler: () => {
createComponent({
componentId: 'channel-compose',
- shouldInsert: !pressedKeys().has('opt'),
+ shouldInsert: pressedKeys().has('shift'),
});
return true;
},
@@ -197,7 +201,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [
}
return result.chatId;
},
- shouldInsert: !pressedKeys().has('opt'),
+ shouldInsert: pressedKeys().has('shift'),
});
return true;
},
@@ -223,7 +227,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [
const [_, id] = ok(result.documentId);
return id;
},
- shouldInsert: !pressedKeys().has('opt'),
+ shouldInsert: pressedKeys().has('shift'),
});
return true;
},
@@ -240,7 +244,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [
createBlock({
blockName: 'project',
createFn: () => createProject({ name: 'New Folder' }),
- shouldInsert: !pressedKeys().has('opt'),
+ shouldInsert: pressedKeys().has('shift'),
});
return true;
},
@@ -267,7 +271,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [
const [, id] = ok(result[1]?.documentId);
return id;
},
- shouldInsert: !pressedKeys().has('opt'),
+ shouldInsert: pressedKeys().has('shift'),
});
return true;
},
@@ -445,7 +449,7 @@ const LauncherInner = (props: LauncherInnerProps) => {
if (item.altHotkeyToken) {
registerHotkey({
hotkeyToken: item.altHotkeyToken,
- hotkey: `opt+${item.hotkey}` as ValidHotkey,
+ hotkey: `shift+${item.hotkey}` as ValidHotkey,
scopeId: launcherScope,
description: `${item.description} in current split`,
keyDownHandler: () => {
@@ -505,7 +509,7 @@ const LauncherInner = (props: LauncherInnerProps) => {
});
registerHotkey({
- hotkey: 'opt+enter' as ValidHotkey,
+ hotkey: 'enter' as ValidHotkey,
scopeId: launcherScope,
description: 'Open in current split',
keyDownHandler: () => {
@@ -564,7 +568,7 @@ const LauncherInner = (props: LauncherInnerProps) => {
</For>
</div>
<div class="col-span-full text-sm text-ink-muted text-center pt-4">
- Hold option to open in current split
+ Hold shift to open in current split
</div>
</div>
);
diff --git a/js/app/packages/app/component/command/Konsole.tsx b/js/app/packages/app/component/command/Konsole.tsx
index 52edfd6bf8..842533a088 100644
--- a/js/app/packages/app/component/command/Konsole.tsx
+++ b/js/app/packages/app/component/command/Konsole.tsx
@@ -238,7 +238,7 @@ export function KommandMenuInner(props: {
});
registerHotkey({
- hotkey: 'opt+enter',
+ hotkey: 'shift+enter',
scopeId: konsoleHotkeyScopeId,
description: 'Open in new split',
keyDownHandler: () => {
diff --git a/js/app/packages/app/component/command/KonsoleItem.tsx b/js/app/packages/app/component/command/KonsoleItem.tsx
index 9a1ce2d813..f9e142422b 100644
--- a/js/app/packages/app/component/command/KonsoleItem.tsx
+++ b/js/app/packages/app/component/command/KonsoleItem.tsx
@@ -351,27 +351,26 @@ export function useCommandItemAction(args: {
setCommandScopeCommands: Setter<CommandWithInfo[]>;
}) {
const { setCommandScopeCommands } = args;
- const { replaceSplit, insertSplit } = useSplitLayout();
+ const { openWithSplit } = useSplitLayout();
const blockOrchestrator = useGlobalBlockOrchestrator();
return function itemAction(
item: CommandItemCard | undefined,
action: ItemAction
) {
- console.log('ITEM ACTION', item, action);
if (!item) return;
const blockName = getCommandItemBlockName(item);
const id = item.data.id;
if (blockName) {
- if (action === 'new-split') {
- insertSplit({ type: blockName, id }, 'kommand-menu');
- } else {
- replaceSplit({
- content: { type: blockName, id },
+ openWithSplit(
+ { type: blockName, id },
+ {
referredFrom: 'kommand-menu',
- });
- }
+ preferNewSplit: action === 'new-split',
+ }
+ );
+
if (item.snippet) {
gotoSnippetLocation(blockOrchestrator, id, item.snippet, cleanQuery());
}
@@ -544,7 +543,7 @@ export function CommandItemCard(props: CommandItemProps) {
const CommandItemContainer = ({ children }: { children?: JSXElement }) => {
const optionKeyPressed = createMemo(() => {
- return pressedKeys().has('opt');
+ return pressedKeys().has('shift');
});
return (
<div
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
index 9037bae136..36f1d0f2bd 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
@@ -257,7 +257,6 @@ export const SoupViewList = (props: SoupViewListProps) => {
useSoupViewHotkeys({
splitId: panel.handle.id,
scopeId: scopeId(),
- domRef: soupViewRef,
soup,
splitHandle: panel.handle,
virtualizerHandle,
@@ -321,7 +320,7 @@ export const SoupViewList = (props: SoupViewListProps) => {
}
await openEntityInSplitFromUnifiedList(entity, {
- openInNewSplit: event.altKey,
+ openInNewSplit: event.shiftKey,
location,
splitHandle: panel.handle,
});
@@ -335,7 +334,7 @@ export const SoupViewList = (props: SoupViewListProps) => {
}
await openEntityInSplitFromUnifiedList(entity, {
- openInNewSplit: event.altKey,
+ openInNewSplit: event.shiftKey,
location,
splitHandle: panel.handle,
});
diff --git a/js/app/packages/app/component/next-soup/soup-view/use-soup-view-hotkeys.ts b/js/app/packages/app/component/next-soup/soup-view/use-soup-view-hotkeys.ts
index 8af74f290f..ace676a111 100644
--- a/js/app/packages/app/component/next-soup/soup-view/use-soup-view-hotkeys.ts
+++ b/js/app/packages/app/component/next-soup/soup-view/use-soup-view-hotkeys.ts
@@ -28,7 +28,6 @@ import { openEntityInSplitFromUnifiedList } from '@app/component/next-soup/utils
type UseSoupViewHotkeysOptions = {
splitId: string;
scopeId: string;
- domRef: Accessor<HTMLElement | undefined>;
soup: SoupState;
splitHandle: SplitHandle;
virtualizerHandle: Accessor<VirtualizerHandle | undefined>;
@@ -293,4 +292,21 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
return false;
},
});
+
+ registerHotkey({
+ hotkey: ['shift+enter'],
+ scopeId,
+ description: 'Open in new split',
+ condition: () => soup.focus.id() !== undefined,
+ keyDownHandler: () => {
+ const entity = soup.focus.item();
+ if (!entity) return false;
+ openEntityInSplitFromUnifiedList(entity, {
+ splitHandle,
+ openInNewSplit: true,
+ });
+ return true;
+ },
+ hide: true,
+ });
};
diff --git a/js/app/packages/app/component/next-soup/utils.ts b/js/app/packages/app/component/next-soup/utils.ts
index f4bfbe5a8b..065dad272e 100644
--- a/js/app/packages/app/component/next-soup/utils.ts
+++ b/js/app/packages/app/component/next-soup/utils.ts
@@ -3,15 +3,11 @@ import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';
import { URL_PARAMS as EMAIL_PARAMS } from '@block-email/constants';
import { URL_PARAMS as MD_PARAMS } from '@block-md/constants';
import { URL_PARAMS as PDF_PARAMS } from '@block-pdf/signal/location';
-import type {
- SplitContent,
- SplitHandle,
-} from '@app/component/split-layout/layoutManager';
+import type { SplitHandle } from '@app/component/split-layout/layoutManager';
import { globalSplitManager } from '@app/signal/splitLayout';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
import { waitForFrames } from '@core/util/sleep';
import {
- type DocumentEntity,
type EntityData,
isSearchEntity,
queryKeys,
@@ -26,6 +22,7 @@ import {
SYSTEM_PROPERTY_IDS,
} from '@core/component/Properties/constants';
import { soupKeys } from '@queries/soup/keys';
+import { match } from 'ts-pattern';
const mergeSearchEntities = <T extends EntityData>(
first: WithSearch<T>,
@@ -282,38 +279,7 @@ export const openEntityInSplitFromUnifiedList = async (
const blockOrchestrator = splitManager.getOrchestrator();
- // Create split functions
- const insertSplit = (content: SplitContent) => {
- return splitManager.createNewSplit({
- content,
- activate: true,
- referredFrom: 'unified-list',
- });
- };
-
- const replaceOrInsertSplit = (content: SplitContent) => {
- const existingSplit = splitManager.getSplitByContent(
- content.type,
- content.id
- );
- if (existingSplit) {
- return existingSplit;
- }
-
- splitHandle.replace({ next: content, referredFrom: 'unified-list' });
- return splitHandle;
- };
-
- // Handle document entities separately
- if (entity.type === 'document') {
- return openDocument(entity as DocumentEntity, {
- openInNewSplit,
- blockOrchestrator,
- location,
- insertSplit,
- replaceOrInsertSplit,
- });
- }
+ const content = getEntitySplitContent(entity);
// Build params for channel entities with location
const params =
@@ -324,12 +290,15 @@ export const openEntityInSplitFromUnifiedList = async (
}
: undefined;
- // Create or replace split based on openInNewSplit option
- const handle = openInNewSplit
- ? insertSplit({ type: entity.type, id: entity.id, params })
- : replaceOrInsertSplit({ type: entity.type, id: entity.id, params });
-
- handle?.activate();
+ splitManager.openWithSplit(
+ { ...content, params },
+ {
+ referredFrom: 'unified-list',
+ activate: true,
+ preferNewSplit: openInNewSplit,
+ handle: splitHandle,
+ }
+ );
// Navigate to specific location if provided
if (!location) return;
@@ -337,41 +306,17 @@ export const openEntityInSplitFromUnifiedList = async (
await navigateToLocation(entity.id, location, blockOrchestrator);
};
-/**
- * Opens a document entity in a split.
- */
-async function openDocument(
- entity: DocumentEntity,
- options: {
- openInNewSplit?: boolean;
- blockOrchestrator: BlockOrchestrator;
- location?: SearchLocation;
- insertSplit: (content: SplitContent) => SplitHandle | undefined;
- replaceOrInsertSplit: (content: SplitContent) => SplitHandle | undefined;
- }
-): Promise<void> {
- const {
- openInNewSplit,
- blockOrchestrator,
- location,
- insertSplit,
- replaceOrInsertSplit,
- } = options;
-
- const { id, fileType, subType } = entity;
- const blockName = fileTypeToBlockName(subType?.type ?? fileType);
-
- // Create or replace split based on openInNewSplit option
- const handle = openInNewSplit
- ? insertSplit({ type: blockName, id })
- : replaceOrInsertSplit({ type: blockName, id });
+function getEntitySplitContent(entity: EntityData) {
+ return match(entity)
+ .with({ type: 'document' }, (entity) => {
+ const { id, fileType, subType } = entity;
+ const blockName = fileTypeToBlockName(subType?.type ?? fileType);
- handle?.activate();
-
- // Navigate to specific location if provided
- if (!location) return;
-
- await navigateToLocation(id, location, blockOrchestrator);
+ return { type: blockName, id };
+ })
+ .otherwise((entity) => {
+ return { type: entity.type, id: entity.id };
+ });
}
/**
diff --git a/js/app/packages/app/component/split-layout/layout.ts b/js/app/packages/app/component/split-layout/layout.ts
index 62444b70a1..5c6563a863 100644
--- a/js/app/packages/app/component/split-layout/layout.ts
+++ b/js/app/packages/app/component/split-layout/layout.ts
@@ -1,15 +1,19 @@
import { useContext } from 'solid-js';
import { globalSplitManager } from '../../signal/splitLayout';
import { SplitPanelContext } from './context';
-import type { ReferredFrom, SplitContent } from './layoutManager';
+import type {
+ OpenWithSplitOptions,
+ ReferredFrom,
+ SplitContent,
+} from './layoutManager';
import { isMobile } from '@core/mobile/isMobile';
export function useSplitLayout() {
const splitPanelContext = useContext(SplitPanelContext);
- function replaceOrInsertSplit(
+ function openWithSplit(
content: SplitContent,
- referredFrom: ReferredFrom = null
+ options?: OpenWithSplitOptions
) {
const splitManager = globalSplitManager();
if (!splitManager) {
@@ -17,28 +21,30 @@ export function useSplitLayout() {
return;
}
- const existingSplit = splitManager.getSplitByContent(
- content.type,
- content.id
- );
+ // On mobile, never open in new split
+ const preferNewSplit = isMobile() ? false : options?.preferNewSplit;
- if (existingSplit) {
- return existingSplit;
- }
+ return splitManager.openWithSplit(content, {
+ ...options,
+ preferNewSplit,
+ });
+ }
- if (splitPanelContext) {
- splitPanelContext.handle.replace({
- next: content,
- referredFrom: referredFrom ?? null,
- });
- return splitPanelContext.handle;
- } else {
- return splitManager.createNewSplit({
- content,
- activate: true,
- referredFrom,
- });
+ function replaceOrInsertSplit(
+ content: SplitContent,
+ referredFrom: ReferredFrom = null
+ ) {
+ const splitManager = globalSplitManager();
+ if (!splitManager) {
+ console.error('No split manager found');
+ return;
}
+
+ return openWithSplit(content, {
+ referredFrom,
+ handle: splitPanelContext?.handle,
+ activate: true,
+ });
}
function replaceSplit(options: {
@@ -47,50 +53,23 @@ export function useSplitLayout() {
referredFrom?: ReferredFrom;
}) {
const { content, mergeHistory, referredFrom } = options;
- if (splitPanelContext) {
- splitPanelContext.handle.replace({
- next: content,
- mergeHistory,
- referredFrom: referredFrom ?? null,
- });
- return splitPanelContext.handle;
- }
- const splitManager = globalSplitManager();
- if (!splitManager) {
- console.error('No split manager found');
- return;
- }
- const activeSplitId = splitManager.activeSplitId();
- const activeSplit = activeSplitId && splitManager.getSplit(activeSplitId);
- if (activeSplit) {
- activeSplit.replace({
- next: content,
- mergeHistory,
- referredFrom: referredFrom ?? null,
- });
- return activeSplit;
- }
+ return openWithSplit(content, {
+ mergeHistory,
+ referredFrom,
+ handle: splitPanelContext?.handle,
+ preferNewSplit: false,
+ });
}
function insertSplit(
content: SplitContent,
referredFrom: ReferredFrom = null
) {
- // On mobile, replace instead of inserting a new split
- if (isMobile()) {
- return replaceSplit({ content, referredFrom });
- }
-
- const splitManager = globalSplitManager();
- if (!splitManager) {
- console.error('No split manager found');
- return;
- }
- return splitManager.createNewSplit({
- content,
+ return openWithSplit(content, {
activate: true,
referredFrom,
+ preferNewSplit: true,
});
}
@@ -121,6 +100,7 @@ export function useSplitLayout() {
}
return {
+ openWithSplit,
getSplitCount,
replaceOrInsertSplit,
replaceSplit,
diff --git a/js/app/packages/app/component/split-layout/layoutManager.ts b/js/app/packages/app/component/split-layout/layoutManager.ts
index 729d0e5eee..7efae1b18a 100644
--- a/js/app/packages/app/component/split-layout/layoutManager.ts
+++ b/js/app/packages/app/component/split-layout/layoutManager.ts
@@ -122,6 +122,17 @@ export type CreateNewSplitOptions = {
referredFrom: ReferredFrom;
};
+export type OpenWithSplitOptions = {
+ mergeHistory?: boolean;
+ activate?: boolean;
+ referredFrom?: ReferredFrom;
+ allowDuplicate?: boolean;
+ replaceWhenFull?: boolean;
+ /** If true, prefers opening in a new split. May still replace if layout is at capacity. */
+ preferNewSplit?: boolean;
+ handle?: SplitHandle;
+};
+
function keyOfSplitState(s: SplitState): SplitKey {
return `${s.content.type}:${s.content.id}`;
}
@@ -203,6 +214,11 @@ export type SplitManager = {
/** Create a new split with the provided initial content and activate it */
createNewSplit: (options: CreateNewSplitOptions) => SplitHandle;
+ openWithSplit: (
+ content: SplitContent,
+ options?: OpenWithSplitOptions
+ ) => SplitHandle;
+
/** Set a split as active by its split id */
activateSplit: (id: SplitId) => void;
@@ -214,6 +230,8 @@ export type SplitManager = {
getOrchestrator: () => BlockOrchestrator;
+ canAppendSplit: () => boolean;
+
/**
* Reconcile the splits with the provided list of splits.
* Useful for when the url changes.
@@ -401,6 +419,10 @@ export function createSplitLayout(
const [resizeContext, setResizeContext] = createSignal<ResizeZoneCtx>();
+ const canAppendSplit = createMemo(
+ () => resizeContext()?.canFit({ minSize: 400 }) ?? true
+ );
+
const [splitNamesById, setSplitNamesById] = createStore<{
[id: SplitId]: string;
}>({});
@@ -972,6 +994,54 @@ export function createSplitLayout(
});
}
+ function openWithSplit(
+ content: SplitContent,
+ options: OpenWithSplitOptions = {}
+ ): SplitHandle {
+ const existingSplit = getSplitByContent(content.type, content.id);
+
+ if (!options.allowDuplicate && existingSplit) {
+ if (options.activate !== false) {
+ existingSplit.activate();
+ }
+
+ return existingSplit;
+ }
+
+ let splitHandle = options.handle;
+
+ if (!splitHandle) {
+ splitHandle = state.activeSplitId
+ ? getSplit(state.activeSplitId)
+ : undefined;
+ }
+
+ const shouldReplaceWhenFull =
+ options.replaceWhenFull !== false && !canAppendSplit();
+
+ const shouldReplace = !options.preferNewSplit || shouldReplaceWhenFull;
+
+ if (splitHandle && shouldReplace) {
+ splitHandle.replace({
+ next: content,
+ referredFrom: options.referredFrom ?? null,
+ mergeHistory: options.mergeHistory,
+ });
+
+ if (options.activate !== false) {
+ splitHandle.activate();
+ }
+
+ return splitHandle;
+ } else {
+ return createNewSplit({
+ content,
+ activate: options.activate ?? true,
+ referredFrom: options.referredFrom ?? null,
+ });
+ }
+ }
+
return {
splits: () => state.splits,
activeSplitId: () => state.activeSplitId,
@@ -979,6 +1049,7 @@ export function createSplitLayout(
events: lastEvent,
reconcile: reconcileSplits,
getSplit,
+ openWithSplit,
removeSplit,
createNewSplit,
getUrlSegments,
@@ -998,5 +1069,6 @@ export function createSplitLayout(
getActivePopovers,
closeAllPopovers,
popovers: () => state.popovers,
+ canAppendSplit,
};
}
diff --git a/js/app/packages/block-channel/component/Attachment.tsx b/js/app/packages/block-channel/component/Attachment.tsx
index be8ec7ce28..9a7466870b 100644
--- a/js/app/packages/block-channel/component/Attachment.tsx
+++ b/js/app/packages/block-channel/component/Attachment.tsx
@@ -27,7 +27,7 @@ type AttachmentProps = {
};
export function Attachment(props: AttachmentProps) {
- const { insertSplit, replaceOrInsertSplit } = useSplitLayout();
+ const { openWithSplit } = useSplitLayout();
const [hover, setHover] = createSignal(false);
const attachmentName = () => {
@@ -102,12 +102,14 @@ export function Attachment(props: AttachmentProps) {
text={truncateString(attachmentName(), 30)}
onClick={(e) => {
if (props.attachment.pending) return;
- const inNewSplit = openInNewSplitForMention(e.altKey, true);
- const open = inNewSplit ? insertSplit : replaceOrInsertSplit;
- open({
- type: fileTypeToBlockName(blockName()),
- id: props.attachment.id,
- })?.activate?.();
+ const inNewSplit = openInNewSplitForMention(e.shiftKey, true);
+ openWithSplit(
+ {
+ type: fileTypeToBlockName(blockName()),
+ id: props.attachment.id,
+ },
+ { preferNewSplit: inNewSplit }
+ );
}}
/>
)}
diff --git a/js/app/packages/block-channel/component/AttachmentsModal.tsx b/js/app/packages/block-channel/component/AttachmentsModal.tsx
index 660809718d..df2dcefc0d 100644
--- a/js/app/packages/block-channel/component/AttachmentsModal.tsx
+++ b/js/app/packages/block-channel/component/AttachmentsModal.tsx
@@ -25,7 +25,7 @@ const DRAWER_ID = 'attachments';
export function AttachmentsModal() {
const drawerControl = useDrawerControl(DRAWER_ID);
const currentBlockId = useBlockId();
- const { replaceOrInsertSplit } = useSplitLayout();
+ const { openWithSplit } = useSplitLayout();
const channelContext = useChannelContext();
const mentionsQuery = useMentionsQuery(() => currentBlockId);
@@ -51,8 +51,14 @@ export function AttachmentsModal() {
);
});
- const navigateToItem = (blockName: BlockName, blockId: string) => {
- replaceOrInsertSplit({ type: blockName, id: blockId });
+ const onClickAttachment = (
+ event: MouseEvent,
+ details: { blockName: BlockName; blockId: string }
+ ) => {
+ openWithSplit(
+ { type: details.blockName, id: details.blockId },
+ { preferNewSplit: !event.shiftKey }
+ );
};
return (
@@ -93,7 +99,7 @@ export function AttachmentsModal() {
<Suspense>
<AttachmentItem
attachment={attachment}
- onNavigate={navigateToItem}
+ onNavigate={onClickAttachment}
senderId={channelContext
.messageSenderMap()
.get(attachment.message_id)}
@@ -126,7 +132,10 @@ function makeAttachmentFromMention(
type AttachmentItemProps = {
attachment: Attachment;
- onNavigate: (blockName: BlockName | BlockAlias, blockId: string) => void;
+ onNavigate: (
+ event: MouseEvent,
+ details: { blockName: BlockName | BlockAlias; blockId: string }
+ ) => void;
senderId: string | undefined;
};
@@ -139,10 +148,13 @@ function AttachmentItem(props: AttachmentItemProps) {
type: props.attachment.entity_type as ItemType,
}));
- const handleClick = () => {
+ const handleClick = (event: MouseEvent) => {
const item = preview();
if (isAccessiblePreviewItem(item) && item.type === 'document') {
- props.onNavigate(fileTypeToBlockName(item.fileType), item.id);
+ props.onNavigate(event, {
+ blockName: fileTypeToBlockName(item.fileType),
+ blockId: item.id,
+ });
} else {
toast.failure('Failed to open attachment');
}
diff --git a/js/app/packages/block-email/component/AttachmentPill.tsx b/js/app/packages/block-email/component/AttachmentPill.tsx
index e46bf8fe6e..8d6b3faedf 100644
--- a/js/app/packages/block-email/component/AttachmentPill.tsx
+++ b/js/app/packages/block-email/component/AttachmentPill.tsx
@@ -12,7 +12,7 @@ type EmailAttachmentPillProps = {
attachment: { fileName: string; mimeType?: string };
removable?: boolean;
onRemove?: () => void;
- onClick?: (fileType?: FileType) => void;
+ onClick?: (event: MouseEvent, fileType?: FileType) => void;
};
export function EmailAttachmentPill(props: EmailAttachmentPillProps) {
@@ -30,7 +30,7 @@ export function EmailAttachmentPill(props: EmailAttachmentPillProps) {
classList={{
'pl-2': props.removable,
}}
- onClick={() => props.onClick?.(fileType())}
+ onClick={(e) => props.onClick?.(e, fileType())}
>
<Show when={fileType() !== undefined || props.attachment.mimeType}>
<EntityIcon
diff --git a/js/app/packages/block-email/component/MessageContainer.tsx b/js/app/packages/block-email/component/MessageContainer.tsx
index e8b9eb3b98..6f0f1392f6 100644
--- a/js/app/packages/block-email/component/MessageContainer.tsx
+++ b/js/app/packages/block-email/component/MessageContainer.tsx
@@ -135,14 +135,14 @@ export function MessageContainer(props: MessageContainerProps) {
);
});
+ const { openWithSplit } = useSplitLayout();
+ const queryClient = useQueryClient();
const draftAttachments = createMemo(() => {
return props.message.attachments_draft ?? [];
});
- const { replaceOrInsertSplit } = useSplitLayout();
- const queryClient = useQueryClient();
-
const onClickAttachment = async (
+ event: MouseEvent,
attachment: Attachment,
fileType: FileType | undefined
) => {
@@ -183,10 +183,10 @@ export function MessageContainer(props: MessageContainerProps) {
});
const blockName = fileType ? fileTypeToBlockName(fileType) : 'unknown';
- replaceOrInsertSplit({
- type: blockName,
- id: document_id,
- })?.activate?.();
+ openWithSplit(
+ { type: blockName, id: document_id },
+ { preferNewSplit: event.shiftKey }
+ );
};
const handleExpand = () => {
@@ -284,8 +284,8 @@ export function MessageContainer(props: MessageContainerProps) {
fileName: attachment.filename ?? '',
mimeType: attachment.mime_type ?? undefined,
}}
- onClick={(fileType) =>
- onClickAttachment(attachment, fileType)
+ onClick={(event, fileType) =>
+ onClickAttachment(event, attachment, fileType)
}
/>
)}
diff --git a/js/app/packages/block-project/component/ProjectCreateMenu.tsx b/js/app/packages/block-project/component/ProjectCreateMenu.tsx
index 9dcaf6d98f..8c8340e2ae 100644
--- a/js/app/packages/block-project/component/ProjectCreateMenu.tsx
+++ b/js/app/packages/block-project/component/ProjectCreateMenu.tsx
@@ -53,7 +53,7 @@ function MenuContent(props: { projectId: string }) {
}) => {
const { blockName, createFn, loading } = spec;
- const shouldInsert = pressedKeys().has('opt');
+ const shouldInsert = pressedKeys().has('shift');
const tryCreate = async () => {
try {
diff --git a/js/app/packages/core/component/AI/component/input/Attachment.tsx b/js/app/packages/core/component/AI/component/input/Attachment.tsx
index 26ca730d20..2914b0834e 100644
--- a/js/app/packages/core/component/AI/component/input/Attachment.tsx
+++ b/js/app/packages/core/component/AI/component/input/Attachment.tsx
@@ -162,7 +162,7 @@ function ChatAttachment(props: {
if (isImageAttachment(attachment)) return;
const block_ = block();
if (!block_) return;
- const inNewSplit = openInNewSplitForMention(e.altKey, true);
+ const inNewSplit = openInNewSplitForMention(e.shiftKey, true);
const open = inNewSplit ? insertSplit : replaceOrInsertSplit;
open({
id: attachment.attachmentId,
diff --git a/js/app/packages/core/component/ItemPreview.tsx b/js/app/packages/core/component/ItemPreview.tsx
index d14d3e5473..14bc3d2be9 100644
--- a/js/app/packages/core/component/ItemPreview.tsx
+++ b/js/app/packages/core/component/ItemPreview.tsx
@@ -62,11 +62,11 @@ export function useItemPreviewData(entity: Accessor<ItemEntity>) {
id: string,
fileType?: FileType,
subType?: NamedSubType,
- altKey?: boolean
+ shiftKey?: boolean
) {
const _type = subType ?? fileType ?? type;
if (!_type) return;
- openItem(_type, id, openInNewSplitForMention(altKey, true));
+ openItem(_type, id, openInNewSplitForMention(shiftKey, true));
}
const name = () => {
@@ -205,7 +205,7 @@ function ItemPreviewInner(props: ItemEntity) {
item.id,
item.fileType,
item.subType?.type as NamedSubType | undefined,
- e.altKey
+ e.shiftKey
);
});
return (
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/core/BlockLink.tsx b/js/app/packages/core/component/LexicalMarkdown/component/core/BlockLink.tsx
index 15b8976ee7..be18680cd4 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/core/BlockLink.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/core/BlockLink.tsx
@@ -37,7 +37,7 @@ export function openDocument(
inNewSplit?: boolean
) {
const currentBlockId = useMaybeBlockId();
- const { replaceOrInsertSplit, insertSplit } = useSplitLayout();
+ const { openWithSplit } = useSplitLayout();
const targetBlock = fileTypeToBlockName(blockOrFileType);
if (!targetBlock) return;
@@ -53,19 +53,7 @@ export function openDocument(
return;
}
- if (inNewSplit) {
- const handle = insertSplit({
- type: targetBlock,
- id,
- });
- handle?.activate();
- } else {
- const handle = replaceOrInsertSplit({
- type: targetBlock,
- id,
- });
- handle?.activate();
- }
+ openWithSplit({ type: targetBlock, id }, { preferNewSplit: inNewSplit });
if (isBlockNameWithLocation(targetBlock)) {
openLocation(targetBlock, id, params);
@@ -80,7 +68,7 @@ export function BlockLink(
}>
) {
const open = createCallback((e: MouseEvent) => {
- let newSplit = e.altKey;
+ let newSplit = e.shiftKey;
openDocument(props.blockOrFileName, props.id, props.params, newSplit);
});
const navHandlers = useSplitNavigationHandler<HTMLSpanElement>(open);
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/decorator/ContactMention.tsx b/js/app/packages/core/component/LexicalMarkdown/component/decorator/ContactMention.tsx
index a5f6cb041e..9b27fb165e 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/decorator/ContactMention.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/decorator/ContactMention.tsx
@@ -19,7 +19,7 @@ export function ContactMention(props: ContactMentionDecoratorProps) {
const editor = lexicalWrapper?.editor;
const selection = () => lexicalWrapper?.selection;
- const { replaceOrInsertSplit, insertSplit } = useSplitLayout()!;
+ const { openWithSplit } = useSplitLayout()!;
const [popupOpen, setPopupOpen] = createSignal(false);
let mentionRef!: HTMLSpanElement;
@@ -33,18 +33,11 @@ export function ContactMention(props: ContactMentionDecoratorProps) {
const openContact = (e: MouseEvent | KeyboardEvent | null) => {
// The contactId is the email or @domain
const contactId = encodeURIComponent(props.emailOrDomain);
- const inNewSplit = openInNewSplitForMention(e?.altKey, e != null);
- if (inNewSplit) {
- insertSplit({
- type: 'contact',
- id: contactId,
- });
- } else {
- replaceOrInsertSplit({
- type: 'contact',
- id: contactId,
- });
- }
+ const inNewSplit = openInNewSplitForMention(e?.shiftKey, e != null);
+ openWithSplit(
+ { type: 'contact', id: contactId },
+ { preferNewSplit: inNewSplit }
+ );
};
const displayName = () => {
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx b/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx
index 38b739723a..e669ca8085 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx
@@ -228,7 +228,7 @@ export function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
props.blockName,
props.documentId,
props.blockParams,
- openInNewSplitForMention(e?.altKey, e != null)
+ openInNewSplitForMention(e?.shiftKey, e != null)
);
});
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx b/js/app/packages/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx
index 164804fb8d..cac88af941 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx
@@ -87,7 +87,7 @@ function SnapshotInner(props: SnapshotDecoratorProps) {
props.blockName,
props.documentId,
{},
- openInNewSplitForMention(e?.altKey, e != null)
+ openInNewSplitForMention(e?.shiftKey, e != null)
);
});
diff --git a/js/app/packages/core/component/References.tsx b/js/app/packages/core/component/References.tsx
index 2250bdc186..4f14d8015f 100644
--- a/js/app/packages/core/component/References.tsx
+++ b/js/app/packages/core/component/References.tsx
@@ -68,7 +68,7 @@ export function References(props: ReferenceProps) {
return response[1].references;
});
- const { replaceOrInsertSplit } = useSplitLayout();
+ const { openWithSplit } = useSplitLayout();
const blockOrchestrator = useGlobalBlockOrchestrator();
const messageLocation = async (
@@ -83,33 +83,52 @@ export function References(props: ReferenceProps) {
});
};
- const navigateToMessage = (
- channelId: string,
- messageId: string,
- threadId?: string
- ) => {
- replaceOrInsertSplit({
- type: 'channel',
- id: channelId,
- });
- messageLocation(channelId, messageId, threadId);
+ const navigateToItem = ({
+ event,
+ blockId,
+ blockName,
+ }: {
+ event?: KeyboardEvent | MouseEvent;
+ blockName: BlockName | BlockAlias;
+ blockId: string;
+ }) => {
+ openWithSplit(
+ { type: blockName, id: blockId },
+ { preferNewSplit: event?.shiftKey !== true }
+ );
};
- const navigateToItem = (
- blockName: BlockName | BlockAlias,
- blockId: string
- ) => {
- replaceOrInsertSplit({
- type: blockName,
- id: blockId,
+ const navigateToMessage = ({
+ channelId,
+ messageId,
+ threadId,
+ event,
+ }: {
+ event?: KeyboardEvent | MouseEvent;
+ channelId: string;
+ messageId: string;
+ threadId?: string;
+ }) => {
+ navigateToItem({
+ event,
+ blockName: 'channel',
+ blockId: channelId,
});
+ messageLocation(channelId, messageId, threadId);
};
- const navigateToGenericReference = (item: PreviewItem) => {
+ const navigateToGenericReference = (
+ item: PreviewItem,
+ event?: KeyboardEvent | MouseEvent
+ ) => {
if (isAccessiblePreviewItem(item) && item.type === 'document') {
const blockId = item.id;
const blockType = fileTypeToBlockName(item.fileType);
- navigateToItem(blockType, blockId);
+ navigateToItem({
+ event,
+ blockName: blockType,
+ blockId,
+ });
} else {
toast.failure('Failed to open reference');
}
@@ -172,8 +191,12 @@ export function References(props: ReferenceProps) {
const hasMessageContent =
ref.message_content && ref.message_content.trim().length > 0;
- const navHandlers = useSplitNavigationHandler(() =>
- navigateToMessage(ref.channel_id, ref.message_id)
+ const navHandlers = useSplitNavigationHandler((e) =>
+ navigateToMessage({
+ event: e,
+ channelId: ref.channel_id,
+ messageId: ref.message_id,
+ })
);
return (
@@ -213,8 +236,8 @@ export function References(props: ReferenceProps) {
type: ref.source_entity_type as ItemType,
}));
- const navHandlers = useSplitNavigationHandler(() =>
- navigateToGenericReference(item())
+ const navHandlers = useSplitNavigationHandler((e) =>
+ navigateToGenericReference(item(), e)
);
return (
diff --git a/js/app/packages/core/component/UserTooltip.tsx b/js/app/packages/core/component/UserTooltip.tsx
index e5e8c5adcb..b685d87aba 100644
--- a/js/app/packages/core/component/UserTooltip.tsx
+++ b/js/app/packages/core/component/UserTooltip.tsx
@@ -24,7 +24,7 @@ export type UserTooltipProps = {
export function UserTooltip(props: UserTooltipProps) {
const currentUserId = useUserId();
- const { replaceOrInsertSplit } = useSplitLayout();
+ const { openWithSplit } = useSplitLayout();
const openDM = async (e: PointerEvent | MouseEvent) => {
e.preventDefault();
@@ -36,10 +36,10 @@ export function UserTooltip(props: UserTooltipProps) {
});
const channelId = isOk(result) && result[1]?.channel_id;
if (channelId) {
- replaceOrInsertSplit({
- type: 'channel',
- id: channelId,
- });
+ openWithSplit(
+ { type: 'channel', id: channelId },
+ { preferNewSplit: e.shiftKey }
+ );
} else {
toast.failure('Failed to open direct message');
}