Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve the problem that / cannot evoke toolbox in Chinese input method… #2750

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/components/modules/blockEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class BlockEvents extends Module {
*
* @todo probably using "beforeInput" event would be better here
*/
if (event.key === '/' && !event.ctrlKey && !event.metaKey) {
if (event.code === 'Slash' && !event.ctrlKey && !event.metaKey) {
this.slashPressed(event);
}

Expand Down Expand Up @@ -252,14 +252,9 @@ export default class BlockEvents extends Module {
return;
}

/**
* The Toolbox will be opened with immediate focus on the Search input,
* and '/' will be added in the search input by default — we need to prevent it and add '/' manually
*/
event.preventDefault();
this.Editor.Caret.insertContentAtCaretPosition('/');

this.activateToolbox();
setTimeout(() => {
this.activateToolbox();
}, 0);
Comment on lines +255 to +257
Copy link
Member

@neSpecc neSpecc Jun 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. this change looks unclear for me. Previous solution looks more explicit. Why it is not working?

  2. We're trying to get rid of setTimeout in a code since it leads of problems of caret behavior which are hard to maintain.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason the toolbox cannot be invoked with the Chinese input method / is that the Chinese / corresponds to event.key = Process instead of /, so event.code === 'Slash' is used to determine if / is pressed. Using setTimeout to invoke the toolbox is mainly to asynchronously invoke the toolbox because the original code's event.preventDefault() cannot prevent the / input in Chinese mode, causing / to be automatically entered in the SearchInput. I don't have any ideas for better asynchronous calls yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the original code's event.preventDefault() cannot prevent the / input in Chinese mode, causing / to be automatically entered in the SearchInput.

So how it prevented now?

}

/**
Expand Down
Loading