From ef7ba273ab6ee6812db0ed496187ab3bf3d1476b Mon Sep 17 00:00:00 2001 From: pengx17 Date: Tue, 2 Jul 2024 15:28:30 +0000 Subject: [PATCH] fix: copy share link to clipboard command display issue (#7411) fix AF-1027 --- packages/frontend/core/src/commands/registry/command.ts | 2 +- .../src/hooks/affine/use-register-copy-link-commands.tsx | 7 +++++-- .../core/src/modules/quicksearch/impls/commands.ts | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/frontend/core/src/commands/registry/command.ts b/packages/frontend/core/src/commands/registry/command.ts index f113cb9954..738045ef72 100644 --- a/packages/frontend/core/src/commands/registry/command.ts +++ b/packages/frontend/core/src/commands/registry/command.ts @@ -39,6 +39,7 @@ export interface KeybindingOptions { export interface AffineCommandOptions { id: string; // 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); // main text on the left.. // 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; // we use https://github.com/jamiebuilds/tinykeys so that we can use the same keybinding definition // for both mac and windows - // TODO(@Peng): render keybinding in command palette keyBinding?: KeybindingOptions | string; run: () => void | Promise; } diff --git a/packages/frontend/core/src/hooks/affine/use-register-copy-link-commands.tsx b/packages/frontend/core/src/hooks/affine/use-register-copy-link-commands.tsx index 6ae7a7fd07..ca1912344f 100644 --- a/packages/frontend/core/src/hooks/affine/use-register-copy-link-commands.tsx +++ b/packages/frontend/core/src/hooks/affine/use-register-copy-link-commands.tsx @@ -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 { useIsActiveView } from '@affine/core/modules/workbench'; import { WorkspaceFlavour } from '@affine/env/workspace'; @@ -28,7 +31,7 @@ export function useRegisterCopyLinkCommands({ registerAffineCommand({ id: `affine:share-private-link:${docId}`, category: 'affine:general', - preconditionStrategy: () => isActiveView, + preconditionStrategy: PreconditionStrategy.Never, keyBinding: { binding: '$mod+Shift+c', }, diff --git a/packages/frontend/core/src/modules/quicksearch/impls/commands.ts b/packages/frontend/core/src/modules/quicksearch/impls/commands.ts index 91fc114549..dd07759c71 100644 --- a/packages/frontend/core/src/modules/quicksearch/impls/commands.ts +++ b/packages/frontend/core/src/modules/quicksearch/impls/commands.ts @@ -160,17 +160,17 @@ export class CommandsQuickSearchSession return result.map>( ({ item, matches, score = 1 }) => { - const nomalizedRange = ([start, end]: [number, number]) => + const normalizedRange = ([start, end]: [number, number]) => [ start, end + 1 /* in fuse, the `end` is different from the `substring` */, ] as [number, number]; const titleMatches = matches ?.filter(match => match.key === 'label.title') - .flatMap(match => match.indices.map(nomalizedRange)); + .flatMap(match => match.indices.map(normalizedRange)); const subTitleMatches = matches ?.filter(match => match.key === 'label.subTitle') - .flatMap(match => match.indices.map(nomalizedRange)); + .flatMap(match => match.indices.map(normalizedRange)); return { id: 'command:' + item.id,