케이스 ce-0232-chinese-ime-pinyin-heading-safari-ko · 시나리오 scenario-ime-duplicate-text-heading

WebKit에서 제목(H1-H6)에서 IME 컴포지션 시 Pinyin 노출

OS: macOS 13+ 기기: Desktop (Mac) Any 브라우저: Safari 17+ 키보드: Chinese (IME) - macOS Chinese Input 초안
compositionimeheadingchinesewebkitduplicate-text

현상

Safari(WebKit)에서 제목 요소(H1-H6)에 중국어 IME로 텍스트를 입력할 때, 컴포지션 확정 시 원본 Pinyin 버퍼가 노출되는 버그입니다.

재현 예시

  1. H2 또는 다른 제목 요소에 포커스합니다.
  2. macOS 중국어 IME를 활성화합니다.
  3. Pinyin “nihao”를 입력합니다 (한자 “你好”의 후보).
  4. Space 키를 눌러 컴포지션을 확정합니다.

관찰된 동작

  • 중복 텍스트: Pinyin “nihao”와 한자 “你好”가 함께 표시됨 → “nihao 你好”
  • 제목 요소에서만 발생: P 요소(<p>, <div>)에서는 정상 작동
  • WebKit 특유: Chrome에서도 발생할 수 있으나, Safari에서 명확하게 확인됨
  • Firefox에서는 정상: Firefox에서는 Pinyin 버퍼가 노출되지 않음

예상 동작

  • Pinyin 버퍼(“nihao”)는 보이지 않아야 함
  • 확정된 한자(“你好”)만 표시되어야 함

참고사항 및 가능한 해결 방향

  • 제목 요소 사용 피하기: <h1>~<h6> 대신 <p> + CSS 스타일링(font-size, font-weight) 사용
  • compositionend 이벤트로 DOM 정리: 컴포지션 완료 후 불필요한 Pinyin 텍스트 제거
  • Space 키 가로채기: 컴포지션 중 Space 키를 막아서 IME가 자연스럽게 완료되도록 함

코드 예시

const heading = document.querySelector('h2[contenteditable]');
let isComposing = false;

heading.addEventListener('compositionstart', () => {
  isComposing = true;
});

heading.addEventListener('compositionend', () => {
  isComposing = false;
  // DOM 정리: Pinyin 제거
  setTimeout(() => {
    const text = heading.textContent;
    // 알파벳만 제거 (Pinyin 버퍼)
    const cleaned = text.replace(/[a-z]+/g, '');
    heading.textContent = cleaned;
  }, 0);
});

heading.addEventListener('keydown', (e) => {
  if (isComposing && e.key === ' ') {
    e.preventDefault();
    // IME가 컴포지션 완료하도록 대기
  }
});

이 시나리오의 변형

케이스 OS 브라우저 상태
ce-0232-chinese-ime-pinyin-heading-safari-ko macOS 13+ Safari 17+ 초안
ce-0233-chinese-ime-pinyin-heading-chrome-en-ko Windows 10/11 Chrome 120+ 초안

Playground for this case

Use the reported environment as a reference and record what happens in your environment while interacting with the editable area.

Reported environment
OS: macOS 13+
Device: Desktop (Mac) Any
Browser: Safari 17+
Keyboard: Chinese (IME) - macOS Chinese Input
Your environment
Sample HTML:
Event log
Use this log together with the case description when filing or updating an issue.
0 events
Interact with the editable area to see events here.