Skip to content

[Bug]: On Linux Chrome, selecting a character with Chinese IME (like Sogou) may trigger Space Ask AI #11541

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

Closed
1 task
UNIDY2002 opened this issue Apr 8, 2025 · 2 comments
Assignees

Comments

@UNIDY2002
Copy link
Contributor

What happened?

Steps to reproduce:

  • Enter an empty paragraph.
  • Type a character with IME.
  • Select the first candidate with "Space".

Expected behavior:

  • The candidate should be committed to the screen

Actual behavior:

  • The Space Ask AI is triggered

Screenshots:

Image

Image

Distribution version

Web (https://app.affine.pro)

App Version

0.21.0

What browsers are you seeing the problem on if you're using web version?

Chrome

Are you self-hosting?

  • Yes

Self-hosting Version

No response

Relevant log output

Anything else?

The problem seems to lie in

export function setupSpaceAIEntry(panel: AffineAIPanelWidget) {
panel.handleEvent('keyDown', ctx => {
const host = panel.host;
const keyboardState = ctx.get('keyboardState');
if (
AIProvider.actions.chat &&
keyboardState.raw.key === ' ' &&
!keyboardState.raw.isComposing
) {
const selection = host.selection.find(TextSelection);
if (selection && selection.isCollapsed() && selection.from.index === 0) {
const block = host.view.getBlock(selection.blockId);
if (!block?.model?.text || block.model.text?.length > 0) return;
keyboardState.raw.preventDefault();
handleInlineAskAIAction(host);
}
}
});
}

In this case, the key code of the event is the 32 (Space) instead of the 229 (Processing).

@affine-issue-bot
Copy link

affine-issue-bot bot commented Apr 8, 2025

Issue Status: 🧑‍💻 To Reproduce

🧑‍💻 To Reproduce

We will try to find the steps needed to reproduce the issue on our side.

This is an automatic reply by the bot.

@CatsJuice CatsJuice moved this from 🆕 *Untriaged to 🧑‍💻 To Reproduce in AFFiNE Project Apr 9, 2025
graphite-app bot pushed a commit that referenced this issue Apr 15, 2025
### TL;DR
Refactor space-triggered AI Widget activation logic from `keydown` to `keypress` event listeners

### Background

The `keydown` event triggered by a space may originate from:
1. Normal space insertion
2. Space triggered by input method confirming candidate words

In scenarios like (2), some browsers (see [ISSUE](#11541)) and input method callbacks produce events identical to scenario (1),making it impossible to distinguish between the two.

To fix this, the space-activated AI listener uses the `keypress` event:
In scenario 2, `event.which !== 32` (may be `30430` or other values) can be used to differentiate from scenario 1.

> CLOSE BS-3081
@UNIDY2002
Copy link
Contributor Author

Fixed in the latest nightly version. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🧑‍💻 To Reproduce
Development

No branches or pull requests

2 participants