fix: copy share link to clipboard command display issue (#7411)
fix AF-1027
This commit is contained in:
@@ -39,6 +39,7 @@ export interface KeybindingOptions {
|
|||||||
export interface AffineCommandOptions {
|
export interface AffineCommandOptions {
|
||||||
id: string;
|
id: string;
|
||||||
// a set of predefined precondition strategies, but also allow user to customize their own
|
// a set of predefined precondition strategies, but also allow user to customize their own
|
||||||
|
// note: this only controls the visibility of the command, not the availability (e.g., shortcut keybinding still works)
|
||||||
preconditionStrategy?: PreconditionStrategy | (() => boolean);
|
preconditionStrategy?: PreconditionStrategy | (() => boolean);
|
||||||
// main text on the left..
|
// main text on the left..
|
||||||
// make text a function so that we can do i18n and interpolation when we need to
|
// make text a function so that we can do i18n and interpolation when we need to
|
||||||
@@ -57,7 +58,6 @@ export interface AffineCommandOptions {
|
|||||||
category?: CommandCategory;
|
category?: CommandCategory;
|
||||||
// we use https://github.com/jamiebuilds/tinykeys so that we can use the same keybinding definition
|
// we use https://github.com/jamiebuilds/tinykeys so that we can use the same keybinding definition
|
||||||
// for both mac and windows
|
// for both mac and windows
|
||||||
// TODO(@Peng): render keybinding in command palette
|
|
||||||
keyBinding?: KeybindingOptions | string;
|
keyBinding?: KeybindingOptions | string;
|
||||||
run: () => void | Promise<void>;
|
run: () => void | Promise<void>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { registerAffineCommand } from '@affine/core/commands';
|
import {
|
||||||
|
PreconditionStrategy,
|
||||||
|
registerAffineCommand,
|
||||||
|
} from '@affine/core/commands';
|
||||||
import { useSharingUrl } from '@affine/core/hooks/affine/use-share-url';
|
import { useSharingUrl } from '@affine/core/hooks/affine/use-share-url';
|
||||||
import { useIsActiveView } from '@affine/core/modules/workbench';
|
import { useIsActiveView } from '@affine/core/modules/workbench';
|
||||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||||
@@ -28,7 +31,7 @@ export function useRegisterCopyLinkCommands({
|
|||||||
registerAffineCommand({
|
registerAffineCommand({
|
||||||
id: `affine:share-private-link:${docId}`,
|
id: `affine:share-private-link:${docId}`,
|
||||||
category: 'affine:general',
|
category: 'affine:general',
|
||||||
preconditionStrategy: () => isActiveView,
|
preconditionStrategy: PreconditionStrategy.Never,
|
||||||
keyBinding: {
|
keyBinding: {
|
||||||
binding: '$mod+Shift+c',
|
binding: '$mod+Shift+c',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -160,17 +160,17 @@ export class CommandsQuickSearchSession
|
|||||||
|
|
||||||
return result.map<QuickSearchItem<'commands', AffineCommand>>(
|
return result.map<QuickSearchItem<'commands', AffineCommand>>(
|
||||||
({ item, matches, score = 1 }) => {
|
({ item, matches, score = 1 }) => {
|
||||||
const nomalizedRange = ([start, end]: [number, number]) =>
|
const normalizedRange = ([start, end]: [number, number]) =>
|
||||||
[
|
[
|
||||||
start,
|
start,
|
||||||
end + 1 /* in fuse, the `end` is different from the `substring` */,
|
end + 1 /* in fuse, the `end` is different from the `substring` */,
|
||||||
] as [number, number];
|
] as [number, number];
|
||||||
const titleMatches = matches
|
const titleMatches = matches
|
||||||
?.filter(match => match.key === 'label.title')
|
?.filter(match => match.key === 'label.title')
|
||||||
.flatMap(match => match.indices.map(nomalizedRange));
|
.flatMap(match => match.indices.map(normalizedRange));
|
||||||
const subTitleMatches = matches
|
const subTitleMatches = matches
|
||||||
?.filter(match => match.key === 'label.subTitle')
|
?.filter(match => match.key === 'label.subTitle')
|
||||||
.flatMap(match => match.indices.map(nomalizedRange));
|
.flatMap(match => match.indices.map(normalizedRange));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: 'command:' + item.id,
|
id: 'command:' + item.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user