mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-06 08:50:50 +08:00
fix(core): cmdk crash when entering double quotes (#5008)
Due to a bug in the upstream repository, a temporary fix was implemented until the issue in the upstream repository is resolved. https://github.com/pacocoursey/cmdk/issues/189
This commit is contained in:
@@ -24,7 +24,7 @@ import {
|
||||
PreconditionStrategy,
|
||||
} from '@toeverything/infra/command';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import { escape, groupBy } from 'lodash-es';
|
||||
import { groupBy } from 'lodash-es';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
|
||||
import {
|
||||
@@ -44,6 +44,10 @@ interface SearchResultsValue {
|
||||
content: string;
|
||||
}
|
||||
|
||||
export function removeDoubleQuotes(str?: string): string | undefined {
|
||||
return str?.replace(/"/g, '');
|
||||
}
|
||||
|
||||
export const cmdkQueryAtom = atom('');
|
||||
export const cmdkValueAtom = atom('');
|
||||
|
||||
@@ -168,7 +172,6 @@ export const pageToCommand = (
|
||||
const commandLabel = label || {
|
||||
title: title,
|
||||
};
|
||||
const escapedTitle = escape(title);
|
||||
|
||||
return {
|
||||
id: page.id,
|
||||
@@ -176,13 +179,8 @@ export const pageToCommand = (
|
||||
// hack: when comparing, the part between >>> and <<< will be ignored
|
||||
// adding this patch so that CMDK will not complain about duplicated commands
|
||||
value:
|
||||
escapedTitle +
|
||||
valueWrapperStart +
|
||||
page.id +
|
||||
'.' +
|
||||
category +
|
||||
valueWrapperEnd,
|
||||
originalValue: escapedTitle,
|
||||
title + valueWrapperStart + page.id + '.' + category + valueWrapperEnd,
|
||||
originalValue: title,
|
||||
category: category,
|
||||
run: () => {
|
||||
if (!currentWorkspaceId) {
|
||||
@@ -429,7 +427,10 @@ export const customCommandFilter = (value: string, search: string) => {
|
||||
label = label.replace(contentMatchedWithoutSubtitle, '');
|
||||
}
|
||||
|
||||
const originalScore = commandScore(label, search);
|
||||
// use to remove double quotes from a string until this issue is fixed
|
||||
// https://github.com/pacocoursey/cmdk/issues/189
|
||||
const escapedSearch = removeDoubleQuotes(search) || '';
|
||||
const originalScore = commandScore(label, escapedSearch);
|
||||
|
||||
// hack to make the page title result always before the content result
|
||||
// if the command has matched the title but not the subtitle,
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
cmdkQueryAtom,
|
||||
cmdkValueAtom,
|
||||
customCommandFilter,
|
||||
removeDoubleQuotes,
|
||||
useCMDKCommandGroups,
|
||||
} from './data';
|
||||
import { HighlightLabel } from './highlight';
|
||||
@@ -78,11 +79,15 @@ const QuickSearchGroup = ({
|
||||
title: command.label,
|
||||
}
|
||||
: command.label;
|
||||
|
||||
// use to remove double quotes from a string until this issue is fixed
|
||||
// https://github.com/pacocoursey/cmdk/issues/189
|
||||
const escapeValue = removeDoubleQuotes(command.value);
|
||||
return (
|
||||
<Command.Item
|
||||
key={command.id}
|
||||
onSelect={() => onCommendSelect(command)}
|
||||
value={command.value}
|
||||
value={escapeValue}
|
||||
data-is-danger={
|
||||
command.id === 'editor:page-move-to-trash' ||
|
||||
command.id === 'editor:edgeless-move-to-trash'
|
||||
|
||||
Reference in New Issue
Block a user