Read command-history recalls in Wine edit fields

MUSHclient consumes queued Up/Down keys in PreTranslateMessage before the
Edit control receives WM_KEYDOWN. It recalls commands with SetWindowText
followed by SetSel at the end of the replacement. The editor subclass only
refreshed its snapshot for WM_SETTEXT, so the recalled command was silent
or followed by a stray character or blank from the caret update. Recalling
equal-length commands also leaves the final caret position unchanged.

Observe Up/Down for the focused standard Edit control in WH_GETMESSAGE,
excluding Ctrl-modified navigation. Associate the next successful
WM_SETTEXT with that retrieved key and announce the bounded recalled text
as an existing ordered text-read action. Report empty input as blank.
Consume the pending recall after the replacement and suppress the ensuing
EM_SETSEL feedback so each recalled command is announced once.

Reset recall tracking on subsequent retrieved messages, actual focus and
ordinary dispatched navigation. Preserve snapshot refreshes and normal
Left/Right reading after recalls. Keep password and foreground/focus
exclusion in place, leave unrelated programmatic text updates silent, and
check the control class before accessing the shared attachment property
so Scintilla's different state structure is untouched. Both native hook
architectures receive the fix through the existing build.

Extend the Edit fixture with application-side pretranslation of queued
history arrows. Assert the exact ordered feedback for Up/Down, equal-length
entries, rapid recalls, empty input and horizontal navigation afterward.
Require silence for unchanged history boundaries, unrelated programmatic
updates, protected fields and independently unprotected background fields.
Document history behavior and live MUSHclient acceptance steps.

Validation used a private Xorg dummy display, disposable Wine prefixes and
recording D-Bus services, with GUI checks run sequentially:

- cmake --build build --parallel
- ctest --test-dir build --output-on-failure: all four checks passed
- python3 tests/menu_integration.py --build-dir build --fixture edit
- The Edit check with --32-bit, --32-bit --late-helper, and
  --32-bit --restart-helper
- python3 tests/menu_integration.py --build-dir build --fixture winforms
  --32-bit
- python3 tests/menu_integration.py --build-dir build --fixture notepad
- python3 tests/menu_integration.py --build-dir build --fixture menu
  --32-bit
- git diff --check

The new 32-bit history regression failed against the original hook,
recording only blank actions, and passed with the fix. Final 32-bit,
64-bit and Windows Forms editor checks passed, including existing typing,
selection, deletion, Unicode, password and read-only assertions.

Built and installed the helper into the existing user-local installation,
backed up the previous five files and verified the installed artifacts.
The user subsequently confirmed that the installed fix works in MUSHclient.
Physical braille acceptance was not separately established.
This commit is contained in:
deedra committed 2026-10-14 15:46:26 -07:00
1 parent 7d3ac09ea1
commit b808c6686a
5 files changed
+112 -12

No files matched your search

+29 -1
View File
@@ -14,6 +14,7 @@ typedef struct EditState {
WCHAR *text;
DWORD length;
BOOL busy, known, destroyed;
BOOL history_key, history_replaced;
WCHAR pending_high;
DWORD pending_caret;
} EditState;
@@ -101,6 +102,10 @@ static LRESULT CALLBACK edit_proc(HWND window, UINT message, WPARAM wp, LPARAM l
BOOL requested_focus = message == RegisterWindowMessageW(EDIT_FOCUS_MESSAGE);
BOOL focus = message == WM_SETFOCUS || requested_focus;
BOOL selected = message == EM_SETSEL;
// A dispatched arrow belongs to ordinary caret navigation. Applications
// such as MUSHclient consume history arrows before DispatchMessage instead.
if (navigation || focus) state->history_key = state->history_replaced = FALSE;
BOOL history_replacement = message == WM_SETTEXT && state->history_key;
if (!navigation && !changing && !focus && !selected && message != EM_SETPASSWORDCHAR)
return DefSubclassProc(window, message, wp, lp);
@@ -151,7 +156,17 @@ static LRESULT CALLBACK edit_proc(HWND window, UINT message, WPARAM wp, LPARAM l
if (focus) {
current_line(window, start, text);
kind = WINE_ACCESS_TEXT_FOCUS; report = TRUE;
} else if ((navigation || selected) && (start != old_start || end != old_end)) {
} else if (history_replacement && result) {
// Pretranslated Up/Down recalls arrive as SetWindowText followed by
// SetSel, without any WM_KEYDOWN reaching this procedure. Read the whole
// recalled command once, including blank and equal-length replacements.
if (state->text) copy_range(text, state->text, 0, state->length);
else current_line(window, start, text);
state->history_key = FALSE;
state->history_replaced = TRUE;
report = TRUE;
} else if ((navigation || (selected && !state->history_replaced)) &&
(start != old_start || end != old_end)) {
if (start != end && state->text && end <= state->length) {
// Speak the changed portion when extending or shrinking a selection.
DWORD first = start, last = end;
@@ -260,6 +275,19 @@ __declspec(dllexport) LRESULT CALLBACK WineAccessInputHook(int code, WPARAM wp,
HWND focus = GetFocus();
if (wine_access_watch_edit(focus))
SendMessageW(focus, RegisterWindowMessageW(EDIT_FOCUS_MESSAGE), 0, 0);
EditState *state = (EditState *)GetPropW(focus, EDIT_STATE_PROPERTY);
WCHAR class_name[64];
// Scintilla uses the same attachment property with a different state.
if (state && GetClassNameW(focus, class_name, 64) &&
wine_access_class_matches(class_name, L"Edit") && !state->busy) {
const MSG *message = (const MSG *)lp;
// Restrict replacement feedback to this retrieved input message.
// Timers, unrelated programmatic changes and background edits stay silent.
state->history_key = message->hwnd == focus && message->message == WM_KEYDOWN &&
(message->wParam == VK_UP || message->wParam == VK_DOWN) &&
!(GetKeyState(VK_CONTROL) & 0x8000);
state->history_replaced = FALSE;
}
#ifdef _WIN64
wine_access_scintilla_input(focus, (const MSG *)lp);
#endif