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

fix: Prevent IME-exiting Enter press from sending message on Safari #2175

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

programmablereya
Copy link

@programmablereya programmablereya commented Jan 21, 2025

Description

On most browsers, pressing Enter to end IME composition produces this sequence of events:

  • keydown (keycode 229, key Processing/Unidentified, isComposing true)
  • compositionend
  • keyup (keycode 13, key Enter, isComposing false)

On Safari, the sequence is different:

  • compositionend
  • keydown (keycode 229, key Enter, isComposing false)
  • keyup (keycode 13, key Enter, isComposing false)

This causes Safari users to mistakenly send their messages when they press Enter to confirm their choice in an IME.

The workaround is to treat the next keydown with keycode 229 as if it were part of the IME composition period if it occurs within a short time of the compositionend event.

Fixes #2103, but needs confirmation from a Safari user.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

On most browsers, pressing Enter to end IME composition produces this
sequence of events:
* keydown (keycode 229, key Processing/Unidentified, isComposing true)
* compositionend
* keyup (keycode 13, key Enter, isComposing false)

On Safari, the sequence is different:
* compositionend
* keydown (keycode 229, key Enter, isComposing false)
* keyup (keycode 13, key Enter, isComposing false)

This causes Safari users to mistakenly send their messages when they
press Enter to confirm their choice in an IME.

The workaround is to treat the next keydown with keycode 229 as if it
were part of the IME composition period if it occurs within a short time
of the compositionend event.

Fixes cinnyapp#2103, but needs confirmation from a Safari user.
Copy link

github-actions bot commented Jan 21, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@programmablereya
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

ajbura added a commit to cinnyapp/cla that referenced this pull request Jan 21, 2025
Copy link

@dvcrn dvcrn left a comment

Choose a reason for hiding this comment

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

Pathes for these 2 imports is incorrect so it can't get resolved properly

Besides that, this PR fixes IME errors for me. I can type in Japanese normally ❤️

@@ -47,6 +47,7 @@ import { settingsAtom } from '../../state/settings';
import { isMacOS } from '../../utils/user-agent';
import { KeySymbol } from '../../utils/key-symbol';
import { useMatrixClient } from '../../hooks/useMatrixClient';
import { isComposing } from '../../utils/keyboard.js';
Copy link

Choose a reason for hiding this comment

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

Suggested change
import { isComposing } from '../../utils/keyboard.js';
import { isComposing } from '../../utils/keyboard;

@@ -27,6 +27,7 @@ import { useKeyDown } from '../../hooks/useKeyDown';
import { openSearch } from '../../../client/action/navigation';
import { useMatrixClient } from '../../hooks/useMatrixClient';
import { factoryRoomIdByActivity } from '../../utils/sort';
import { isComposing } from '../../utils/keyboard.js';
Copy link

Choose a reason for hiding this comment

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

Suggested change
import { isComposing } from '../../utils/keyboard.js';
import { isComposing } from '../../utils/keyboard';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When in Japanese input, 'enter' should not immediately send the message
2 participants