ํ์
In Chrome (Blink/WebKit), when using Chinese IME to input text in heading elements (<h1>-<h6>), pressing Space to confirm composition causes both the raw Pinyin buffer and the confirmed characters to appear together.
์ฌํ ์์
- H2 or other heading element is focused.
- Windows Chinese IME is activated.
- Type Pinyin โnihaoโ (for Chinese characters โไฝ ๅฅฝโ).
- Press Space to confirm composition.
๊ด์ฐฐ๋ ๋์
- Duplicate text: Pinyin โnihaoโ and Chinese โไฝ ๅฅฝโ appear together โ โnihao ไฝ ๅฅฝโ
- Heading elements only: Behavior does not occur in paragraph elements (
<p>,<div>) - WebKit/Chromium issue: Similar to Safari behavior
- Firefox unaffected: Firefox does not exhibit this bug
์์ ๋์
- Pinyin buffer (โnihaoโ) should NOT be visible
- Only confirmed Chinese characters (โไฝ ๅฅฝโ) should appear
์ฐธ๊ณ ์ฌํญ ๋ฐ ๊ฐ๋ฅํ ํด๊ฒฐ ๋ฐฉํฅ
- Use semantic paragraphs: Replace
<h1>-<h6>with<p>+ CSS styling for headings - DOM cleanup in compositionend: Remove Pinyin text after composition completes
- Intercept Space key: Prevent Space key during composition to let IME handle naturally
์ฝ๋ ์์
const heading = document.querySelector('h2[contenteditable]');
let isComposing = false;
heading.addEventListener('compositionstart', () => {
isComposing = true;
});
heading.addEventListener('compositionend', () => {
isComposing = false;
// DOM cleanup: remove Pinyin
setTimeout(() => {
const text = heading.textContent;
const cleaned = text.replace(/[a-z]+/g, '');
heading.textContent = cleaned;
}, 0);
});
heading.addEventListener('keydown', (e) => {
if (isComposing && e.key === ' ') {
e.preventDefault();
// Let IME complete naturally
}
});