Skip to content

Commit de1a51b

Browse files
committed
1 parent 7621758 commit de1a51b

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

packages/frontend/core/src/modules/peek-view/view/peek-view-controls.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ export const ControlButton = ({
5959

6060
type DocPeekViewControlsProps = HTMLAttributes<HTMLDivElement> & {
6161
docId: string;
62-
blockId?: string;
6362
mode?: DocMode;
63+
blockIds?: string[];
64+
elementIds?: string[];
6465
};
6566

6667
export const DefaultPeekViewControls = ({
@@ -90,8 +91,9 @@ export const DefaultPeekViewControls = ({
9091

9192
export const DocPeekViewControls = ({
9293
docId,
93-
blockId,
9494
mode,
95+
blockIds,
96+
elementIds,
9597
className,
9698
...rest
9799
}: DocPeekViewControlsProps) => {
@@ -111,8 +113,7 @@ export const DocPeekViewControls = ({
111113
name: t['com.affine.peek-view-controls.open-doc'](),
112114
nameKey: 'open',
113115
onClick: () => {
114-
// TODO(@Peng): for frame blocks, we should mimic "view in edgeless" button behavior
115-
workbench.openDoc({ docId, mode, blockId });
116+
workbench.openDoc({ docId, mode, blockIds, elementIds });
116117
peekView.close('none');
117118
},
118119
},
@@ -121,7 +122,10 @@ export const DocPeekViewControls = ({
121122
nameKey: 'new-tab',
122123
name: t['com.affine.peek-view-controls.open-doc-in-new-tab'](),
123124
onClick: () => {
124-
workbench.openDoc({ docId, mode }, { at: 'new-tab' });
125+
workbench.openDoc(
126+
{ docId, mode, blockIds, elementIds },
127+
{ at: 'new-tab' }
128+
);
125129
peekView.close('none');
126130
},
127131
},
@@ -135,7 +139,7 @@ export const DocPeekViewControls = ({
135139
},
136140
},
137141
].filter((opt): opt is ControlButtonProps => Boolean(opt));
138-
}, [blockId, docId, mode, peekView, t, workbench]);
142+
}, [docId, mode, blockIds, elementIds, peekView, t, workbench]);
139143
return (
140144
<div {...rest} className={clsx(styles.root, className)}>
141145
{controls.map(option => (

packages/frontend/core/src/modules/peek-view/view/peek-view-manager.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ const renderControls = ({ info }: ActivePeekView) => {
5353
<DocPeekViewControls
5454
mode={info.mode}
5555
docId={info.docId}
56-
blockId={info.docId}
56+
blockIds={info.blockIds}
57+
elementIds={info.elementIds}
5758
/>
5859
);
5960
}

packages/frontend/core/src/modules/quicksearch/services/cmdk.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@ export class CMDKQuickSearchService extends Service {
5454
result.source === 'docs' &&
5555
track.$.cmdk.results.searchResultsDocs();
5656

57-
this.workbenchService.workbench.openDoc({
57+
const options: { docId: string; blockIds?: string[] } = {
5858
docId: doc.docId,
59-
blockId: doc.blockId,
60-
});
59+
};
60+
if (doc.blockId) {
61+
options.blockIds = [doc.blockId];
62+
}
63+
64+
this.workbenchService.workbench.openDoc(options);
6165
} else if (result.source === 'collections') {
6266
this.workbenchService.workbench.openCollection(
6367
result.payload.collectionId

packages/frontend/core/src/modules/workbench/entities/workbench.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,27 @@ export class Workbench extends Entity {
122122
}
123123

124124
openDoc(
125-
id: string | { docId: string; blockId?: string; mode?: DocMode },
125+
id:
126+
| string
127+
| {
128+
docId: string;
129+
mode?: DocMode;
130+
blockIds?: string[];
131+
elementIds?: string[];
132+
},
126133
options?: WorkbenchOpenOptions
127134
) {
128-
const docId = typeof id === 'string' ? id : id.docId;
129-
const blockId = typeof id === 'string' ? undefined : id.blockId;
130-
const mode = typeof id === 'string' ? undefined : id.mode;
135+
const isString = typeof id === 'string';
136+
const docId = isString ? id : id.docId;
137+
131138
let query = '';
132-
if (mode || blockId) {
139+
if (!isString) {
140+
const { mode, blockIds, elementIds } = id;
133141
const search = new URLSearchParams();
134142
if (mode) search.set('mode', mode);
135-
if (blockId) search.set('blockIds', blockId);
136-
query = `?${search.toString()}`;
143+
if (blockIds?.length) search.set('blockIds', blockIds.join(','));
144+
if (elementIds?.length) search.set('elementIds', elementIds.join(','));
145+
if (search.size > 0) query = `?${search.toString()}`;
137146
}
138147

139148
this.open(`/${docId}${query}`, options);

0 commit comments

Comments
 (0)