|
| 1 | +Clear-Then-Type Field Entry |
| 2 | +=========================== |
| 3 | + |
| 4 | +Setting a field's value reliably means *clearing* whatever is there first, then |
| 5 | +entering the new text — otherwise automation appends to or corrupts the existing |
| 6 | +content. The framework has ``write`` (types, but raises on emoji / CJK / chars |
| 7 | +outside the layout table) and ``set_clipboard`` / ``hotkey`` separately, but no |
| 8 | +single "focus → clear → set value" primitive and no paste strategy for text that |
| 9 | +``write`` cannot type. This adds the Playwright ``fill`` idiom. |
| 10 | + |
| 11 | +:func:`plan_field_set` builds the deterministic op-plan (pure, unit-testable); |
| 12 | +:func:`set_field_text` dispatches it through an injectable ``sink`` so it is |
| 13 | +tested without real input. Imports no ``PySide6``. |
| 14 | + |
| 15 | +Headless API |
| 16 | +------------ |
| 17 | + |
| 18 | +.. code-block:: python |
| 19 | +
|
| 20 | + from je_auto_control import set_field_text, plan_field_set |
| 21 | +
|
| 22 | + set_field_text("new value") # select-all, delete, type |
| 23 | + set_field_text("café 🚀", paste=True) # via clipboard (Unicode-safe) |
| 24 | + set_field_text("appended", clear="none") # no clear, just type |
| 25 | + set_field_text("値", paste=True, modifier="command") # macOS |
| 26 | +
|
| 27 | + plan_field_set("hi") |
| 28 | + # [{'op': 'hotkey', 'keys': ['ctrl', 'a']}, |
| 29 | + # {'op': 'key', 'key': 'delete'}, |
| 30 | + # {'op': 'type', 'text': 'hi'}] |
| 31 | +
|
| 32 | +``clear`` is ``"select_all"`` (the ``modifier``+A then Delete clear) or |
| 33 | +``"none"``. ``paste=True`` enters the text through the clipboard (``modifier``+V) |
| 34 | +— the reliable path for Unicode / emoji / CJK that ``write`` cannot type — rather |
| 35 | +than typing key by key. ``modifier`` is the platform command key (``"ctrl"``; use |
| 36 | +``"command"`` on macOS). An unknown ``clear`` mode raises ``ValueError``. |
| 37 | + |
| 38 | +Executor commands |
| 39 | +----------------- |
| 40 | + |
| 41 | +``AC_set_field_text`` takes ``text`` plus ``clear`` / ``paste`` / ``modifier`` and |
| 42 | +returns ``{ops, plan}``. It is exposed as the MCP tool ``ac_set_field_text`` and |
| 43 | +as a Script Builder command under **Keyboard**. |
0 commit comments