Keep the switching order when changing input methods

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Heinemeier HanssonandClaude Opus 5.5 committed 2026-10-10 23:10:52 +09:00
1 parent 7b260bed17
commit d1e96fd86d
2 files changed
+11 -5

No files matched your search

+5 -4
View File
@@ -82,11 +82,12 @@ def input_catalog(items):
def input_items(items, selected, overrides=None):
keyboard = [item for item in items if item[0].startswith("keyboard-")]
if not keyboard:
if not any(item[0].startswith("keyboard-") for item in items):
raise RuntimeError("The current input group has no keyboard input")
existing = {**(overrides or {}), **dict(items)}
return keyboard + [[name, existing.get(name, "")] for name in selected]
# Retained entries keep their switching order; new engines follow them.
kept = [item for item in items if item[0].startswith("keyboard-") or item[0] in selected]
current = dict(items)
return kept + [[name, (overrides or {}).get(name, "")] for name in selected if name not in current]
def set_inputs(group, layout, before, after):
+6 -1
View File
@@ -48,9 +48,14 @@ class TypingSetupTest(unittest.TestCase):
def test_input_deselection_keeps_keyboard_and_selected_overrides(self):
items = [["keyboard-us", ""], ["mozc", "jp"], ["hangul", ""], ["custom", "de"]]
self.assertEqual(typing.input_items(items, ["custom", "mozc"]), [["keyboard-us", ""], ["custom", "de"], ["mozc", "jp"]])
self.assertEqual(typing.input_items(items, ["custom", "mozc"]), [["keyboard-us", ""], ["mozc", "jp"], ["custom", "de"]])
self.assertEqual(typing.input_items(items, []), [["keyboard-us", ""]])
def test_input_changes_keep_the_switching_order(self):
items = [["keyboard-us", ""], ["mozc", ""], ["keyboard-fr", ""], ["hangul", ""]]
self.assertEqual(typing.input_items(items, ["mozc"]), [["keyboard-us", ""], ["mozc", ""], ["keyboard-fr", ""]])
self.assertEqual(typing.input_items(items, ["pinyin", "hangul", "mozc"]), items + [["pinyin", ""]])
def test_cancellation_does_not_change_input_settings(self):
with patch.object(typing.setup, "live_group", return_value=("Default", "us", [["keyboard-us", ""]])), patch.object(typing, "input_catalog", return_value=({"mozc": "Japanese"}, {"mozc": "Japanese"})), patch.object(typing, "choose", return_value=None), patch.object(typing.setup, "live_set") as setter:
self.assertFalse(typing.configure_inputs())