vuepress / core

Vue-Powered Static Site Generator
https://vuepress.vuejs.org
MIT License
2.17k stars 923 forks source link

fix(plugin-docsearch): open docsearch with slash key before run initi… #1323

Closed viniciusteixeiradias closed 1 year ago

viniciusteixeiradias commented 1 year ago

…alize

Before submitting the PR, please make sure you do the following

Solving this problem: https://github.com/vuejs/docs/issues/2240.

What is the purpose of this pull request?

Description

Previously, the initializate method was called in onMounted Docsearch.ts, but there was a change that removed it and the method responsible for triggering docsearch before executing the initializate became useDocsearchHotkeyListener, this method defines a keydown eventLintener when mounting the component.

My change was to add the '/' key to the useDocsearchHotkeyListener validation.

Mister-Hope commented 1 year ago

Docsearch only support command + k. Adding / is confusing.

viniciusteixeiradias commented 1 year ago

Docsearch only support command + k. Adding / is confusing.

@Mister-Hope Confused? What do you mean? The / works in Docsearch, the problem happens on the first load.

Mister-Hope commented 1 year ago

Didn't know that, I will test that later

viniciusteixeiradias commented 1 year ago

@Mister-Hope Maybe we need to add this validation below:

const isEditingContent = (e: KeyboardEvent): boolean => {
  const element = e.target as HTMLElement;
  const tagName = element.tagName;
  return (
    element.isContentEditable ||
    tagName === 'INPUT' ||
    tagName === 'SELECT' ||
    tagName === 'TEXTAREA'
  );
}

I am still awaiting your feedback to keep working on this issue.

Mister-Hope commented 1 year ago

Hi there, holiday during April 29th - May 3rd in Chinese, will be back later.

meteorlxy commented 1 year ago

Also didn't know that slash is the default hot key of docsearch. Nice catch!