Text: a cancelled Japanese composition does not make the next one Japanese

Kana seen while composing are cleared when a new composition starts, so a
composition cancelled with Escape no longer turns the space after a later
Chinese or accented commit into an ideographic one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013phQ3ekq6uGBEWD6FjFYG2
This commit is contained in:
con3codeandClaude Opus 5.5 committed 2026-10-25 16:24:24 +09:00
1 parent c2ef34f1f5
commit bf42dee573
1 file changed
+18
+18
View File
@@ -2771,6 +2771,11 @@ pub(crate) fn has_kana(text: &str) -> bool {
fn ime_event(app: &mut DesignApp, e: egui::ImeEvent, vi: designcraft_engine::ViewInfo) {
let r = match e {
egui::ImeEvent::Preedit { text, active_range_chars } => {
// A new composition: kana from one the input method cancelled (Escape) don't count.
// The empty preedit before a commit keeps them, as something is still marked then.
if app.ime_marked.is_none() {
app.ime_kana_seen = false;
}
app.ime_marked = Some(text.clone()).filter(|t| !t.is_empty());
app.ime_kana_seen |= has_kana(&text);
app.session.tool_preedit(&text, active_range_chars, vi).map_err(|e| e.to_string())
@@ -5727,6 +5732,19 @@ mod tests {
}
}
/// Kana from a composition cancelled with Escape (the input method clears the marked text and
/// commits nothing) don't make the next composition Japanese.
#[test]
fn a_cancelled_japanese_composition_does_not_carry_over() {
let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
let ctx = egui::Context::default();
let sid = typing_app(&mut app, &ctx, "");
ime_frame(&mut app, &ctx, vec![preedit("にほ", 2), preedit("", 0)]);
ime_frame(&mut app, &ctx, vec![preedit("ni", 2), preedit("", 0), egui::Event::Ime(egui::ImeEvent::Commit("你".into()))]);
ime_frame(&mut app, &ctx, vec![egui::Event::Text(" ".into())]);
assert_eq!(story_text(&mut app, &sid), "你 ");
}
#[test]
#[allow(deprecated)] // `ImeEvent::Enabled` / `Disabled`: egui no longer sends them, other integrations may.
fn ime_events_compose_in_the_story_with_the_candidate_window_at_the_caret() {