Skip to content

Conversation

cc-hearts
Copy link
Contributor

resolve #7747

@cc-hearts cc-hearts marked this pull request as ready for review September 5, 2024 16:05
Copy link

github-actions bot commented Nov 6, 2024

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the Stale label Nov 6, 2024
@github-actions github-actions bot closed this Nov 13, 2024
@Limoer96
Copy link

@cc-hearts 试了一下,这种修改方式会在中文输入时异常,我觉得更好的方式是在处理searchText分词前,执行一下props.onSearch

@alicemw
Copy link

alicemw commented Mar 5, 2025

@cc-hearts 试了一下,这种修改方式会在中文输入时异常,我觉得更好的方式是在处理searchText分词前,执行一下props.onSearch

具体怎么弄的啊?大佬

@Limoer96
Copy link

Limoer96 commented Mar 5, 2025

@cc-hearts 试了一下,这种修改方式会在中文输入时异常,我觉得更好的方式是在处理searchText分词前,执行一下props.onSearch

具体怎么弄的啊?大佬

找到vc-select/BaseSelect.tsx文件,修改onInternalSearch函数为以下代码:

const onInternalSearch = (searchText: string, fromTyping: boolean, isCompositing: boolean) => {
  let ret = true;
  let newSearchText = searchText;
  // Check if match the `tokenSeparators`
  const patchLabels: string[] = isCompositing
    ? null
    : getSeparatedContent(searchText, props.tokenSeparators);
  props.onActiveValueChange?.(null);
  if (props.onSearch && mergedSearchValue.value !== newSearchText) {
    props.onSearch(newSearchText, {
      source: fromTyping ? 'typing' : 'effect',
    });
  }
  // Ignore combobox since it's not split-able
  if (props.mode !== 'combobox' && patchLabels) {
    newSearchText = '';
    // should trigger onSearch again if splitable
    nextTick(() => {
      props.onSearch?.(newSearchText, {
        source: 'blur',
      });
    });

    props.onSearchSplit?.(patchLabels);

    // Should close when paste finish
    onToggleOpen(false);

    // Tell Selector that break next actions
    ret = false;
  }
  return ret;
};

@alicemw
Copy link

alicemw commented Mar 6, 2025

@cc-hearts 试了一下,这种修改方式会在中文输入时异常,我觉得更好的方式是在处理searchText分词前,执行一下props.onSearch

具体怎么弄的啊?大佬

找到vc-select/BaseSelect.tsx文件,修改onInternalSearch函数为以下代码:

const onInternalSearch = (searchText: string, fromTyping: boolean, isCompositing: boolean) => {
  let ret = true;
  let newSearchText = searchText;
  // Check if match the `tokenSeparators`
  const patchLabels: string[] = isCompositing
    ? null
    : getSeparatedContent(searchText, props.tokenSeparators);
  props.onActiveValueChange?.(null);
  if (props.onSearch && mergedSearchValue.value !== newSearchText) {
    props.onSearch(newSearchText, {
      source: fromTyping ? 'typing' : 'effect',
    });
  }
  // Ignore combobox since it's not split-able
  if (props.mode !== 'combobox' && patchLabels) {
    newSearchText = '';
    // should trigger onSearch again if splitable
    nextTick(() => {
      props.onSearch?.(newSearchText, {
        source: 'blur',
      });
    });

    props.onSearchSplit?.(patchLabels);

    // Should close when paste finish
    onToggleOpen(false);

    // Tell Selector that break next actions
    ret = false;
  }
  return ret;
};

非常感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

复制内容到自动分词模式选择器的bug

3 participants