Files
orca/tests/e2e/terminal-ime-observed-event-sequences.ts
T
NeilandOrca 17cfc968cf Revert the terminal IME composition-ownership change (#13282)
* Revert "test(ime): restore coverage the composition-ownership change removed (#13168)"

This reverts commit 25a8c517e1.

* Revert "refactor(terminal): return IME composition ownership to xterm (#13128)"

This reverts commit 17b3dff3c4.

* test(ime): keep the architecture-neutral Korean trace coverage

The recorded IBus/fcitx5 and Windows MS-Korean traces from #13168 assert PTY
byte order, not composition ownership, so they still hold once the terminal
composition layer is restored. The mobile accessory-order test pinned the new
handleLiveInputChange signature and does not.

Co-authored-by: Orca <help@stably.ai>

* fix(terminal): keep the macOS Backslash bypass through the revert

The restored native-text forwarder only claims keys for input sources in its
hardcoded CJK allowlist, so third-party IMEs off that list (Qingg, #10896) still
get a raw backslash. #13128 added this bypass as a partial replacement; keep it
rather than trade the open issue back.

Scoped to the bare backslash key. The rest of shouldBypassXtermForMacNativeText
bypassed all unmodified non-ASCII text, which would race the restored forwarder.

Co-authored-by: Orca <help@stably.ai>

* fix(mobile): move the mirror-step ref write out of render

The restored hook assigned runMirrorStepRef during render, which is not
replay-safe — React can discard render work, so the mutation can leak from UI
that never commits. Its only read is inside the held-commit timer, which fires
long after commit, and the ref has a safe default, so an effect is soon enough.

Surfaced by the changed-lines React Doctor gate: the rule postdates this code,
so restoring the file re-introduced it as a new violation.

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
2026-08-08 19:06:50 -07:00

90 lines
3.2 KiB
TypeScript

import type { Page } from '@stablyai/playwright-test'
async function dispatchObservedIbusHangulSequence(
page: Page,
variant: 'mixed' | 'retained'
): Promise<void> {
await page.evaluate((selectedVariant) => {
const textarea = document.activeElement
if (!(textarea instanceof HTMLTextAreaElement)) {
throw new Error('xterm helper textarea is not focused')
}
const composition = (type: string, data = ''): void => {
textarea.dispatchEvent(new CompositionEvent(type, { bubbles: true, data }))
}
const input = (type: 'beforeinput' | 'input', inputType: string, data?: string): void => {
textarea.dispatchEvent(
new InputEvent(type, {
bubbles: true,
cancelable: type === 'beforeinput',
composed: true,
data: data ?? null,
inputType
})
)
}
const replaceAndInput = (value: string, inputType: string, data?: string): void => {
input('beforeinput', inputType, data)
textarea.value = value
input('input', inputType, data)
}
const keydown = (key: string, code: string, keyCode: number, isComposing = false): void => {
const event = new KeyboardEvent('keydown', { bubbles: true, code, isComposing, key })
Object.defineProperty(event, 'keyCode', { value: keyCode })
textarea.dispatchEvent(event)
}
const update = (prefix: string, text: string): void => {
composition('compositionupdate', text)
replaceAndInput(`${prefix}${text}`, 'insertCompositionText', text)
}
const begin = (text: string): string => {
const prefix = textarea.value
textarea.setSelectionRange(prefix.length, prefix.length)
composition('compositionstart')
keydown('Process', 'KeyG', 229, true)
update(prefix, text)
return prefix
}
const end = (prefix: string): void => {
composition('compositionupdate')
replaceAndInput(prefix, 'deleteContentBackward')
composition('compositionend')
}
const commit = (prefix: string, text: string): void => {
end(prefix)
replaceAndInput(`${prefix}${text}`, 'insertText', text)
}
if (selectedVariant === 'mixed') {
let prefix = begin('한')
commit(prefix, '한')
for (const character of 'abc') {
keydown(character, `Key${character.toUpperCase()}`, character.charCodeAt(0))
replaceAndInput(`${textarea.value}${character}`, 'insertText', character)
}
prefix = begin('글')
commit(prefix, '글')
keydown('Enter', 'Enter', 13)
return
}
const prefix = begin('테')
composition('compositionend', '테')
keydown('a', 'KeyA', 65)
keydown('Process', 'KeyR', 229, true)
textarea.setSelectionRange(prefix.length + 1, prefix.length + 1)
composition('compositionstart')
update(`${prefix}테`, '스')
composition('compositionend', '스')
keydown('Enter', 'Enter', 13)
}, variant)
}
export async function dispatchObservedIbusHangulMixedSequence(page: Page): Promise<void> {
await dispatchObservedIbusHangulSequence(page, 'mixed')
}
export async function dispatchObservedIbusHangulRetainedCommitSequence(page: Page): Promise<void> {
await dispatchObservedIbusHangulSequence(page, 'retained')
}