lexical icon indicating copy to clipboard operation
lexical copied to clipboard

Bug: Microsoft IME issue in Markdown shortcuts plugin

Open kkshinkai opened this issue 3 years ago • 2 comments

https://user-images.githubusercontent.com/38599375/233908666-48922abc-c8c2-4444-af81-489392a4009b.mp4

It seems that the composition key are not being properly cleared after formatting is applied, and the closing tag is still being inserted into the editor. This issue can be reproduced on Windows using Microsoft Pinyin (Simplified Chinese) input method. (I also tested the Apple Chinese input method on macOS, and did not encounter any issues.)

Lexical version: 0.10.0

To reproduce the issue:

  1. Set "Compatibility" in Windows settings (Language & region > Microsoft Pinyin > General) to use the previous version;
  2. Type **a in the Lexical playground;
  3. Switch to the Microsoft Pinyin (Simplified Chinese) input method;
  4. Type **, and instead of getting "a", you will get "a*".

I did some debugging, but I am not familiar with Lexical, so I was not able to identify the problem. I think we might be able to prevent errors by doing something during the text formatting process.

https://github.com/facebook/lexical/blob/1be64224e14231a1af09b29e1b3c2cbf482b7b38/packages/lexical-markdown/src/MarkdownShortcuts.ts#L121-L284

I'd be glad to help fix this issue, but I'm not sure how IME / composition key work in Lexical. Is there any documentation?

kkshinkai avatar Apr 24 '23 06:04 kkshinkai

After debugging all day, I came to the realization that this problem only arises when the user is using Microsoft Pinyin and has enabled the "Compatibility" option, which is a feature that most people will never come across.

But I am still intrigued as to what might be causing this issue. Could you please advise me on which specific part of the code I should prioritize for debugging?

kkshinkai avatar Apr 24 '23 09:04 kkshinkai

Tested on Windows 11 with Microsoft Pinyin (Simplified Chinese) on the latest playground (v0.46.0, main @ 4e0bc22).

Ran through the original repro (**a → switch to Pinyin → type **) and additional markdown shortcut scenarios (bold around Chinese text, headings with # , code blocks with triple backtick, blockquotes with > , lists with - ) with Compatibility mode enabled ("Use previous version of Microsoft Pinyin"). All produced the expected formatting with no extra * leaking through. Also verified normal (non-compatibility) mode works fine.

Likely fixed by #8503, which added an editor.isComposing() guard and COMPOSITION_END_TAG handling to the markdown shortcuts plugin so composition-committed triggers fire at the right time. Safe to close.

mayrang avatar Jul 01 '26 19:07 mayrang