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

+55 -1
View File
@@ -18,8 +18,24 @@ static void register_control(HINSTANCE instance, const WCHAR *nativeName, const
static const WCHAR *editClass = L"Edit";
#endif
static HWND editor, password;
static HWND editor, password, history;
static int step;
static int history_position;
// Model MUSHclient's PreTranslateMessage: consume queued arrows before the
// Edit procedure, then use SetWindowText and SetSel to recall a command.
static BOOL history_input(const MSG *message) {
if (message->hwnd != history || message->message != WM_KEYDOWN ||
(message->wParam != VK_UP && message->wParam != VK_DOWN)) return FALSE;
if (message->wParam == VK_UP && history_position < 2) ++history_position;
else if (message->wParam == VK_DOWN && history_position > 0) --history_position;
else return TRUE;
const WCHAR *commands[] = {L"", L"history north", L"history south"};
SetWindowTextW(history, commands[history_position]);
int length = GetWindowTextLengthW(history);
SendMessageW(history, EM_SETSEL, length, length);
return TRUE;
}
static void key(UINT key, BOOL control, BOOL shift) {
BYTE saved[256], state[256];
@@ -194,6 +210,43 @@ static LRESULT CALLBACK window_proc(HWND window, UINT message, WPARAM wp, LPARAM
SendMessageW(editor, WM_CHAR, L'%', 1);
if (GetWindowTextLengthW(editor) != 4) ExitProcess(2);
break;
case 41:
// Keep this field away from the managed-label regression's static labels.
history = CreateWindowW(editClass, L"", WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL,
100, 150, 300, 25, window, NULL, GetModuleHandleW(NULL), NULL);
SetFocus(history);
break;
case 42: PostMessageW(history, WM_KEYDOWN, VK_UP, 1); break;
case 43: PostMessageW(history, WM_KEYDOWN, VK_UP, 1); break;
case 44: PostMessageW(history, WM_KEYDOWN, VK_DOWN, 1); break;
case 45: PostMessageW(history, WM_KEYDOWN, VK_DOWN, 1); break;
case 46:
// Rapid recalls must stay ordered, including equal-length commands.
PostMessageW(history, WM_KEYDOWN, VK_UP, 1);
PostMessageW(history, WM_KEYDOWN, VK_UP, 1);
PostMessageW(history, WM_KEYDOWN, VK_DOWN, 1);
break;
case 47:
// Ordinary navigation after a recall must use the refreshed snapshot.
PostMessageW(history, WM_KEYDOWN, VK_LEFT, 1);
PostMessageW(history, WM_KEYDOWN, VK_RIGHT, 1);
break;
case 48:
SetWindowTextW(history, L"programmatic history sentinel");
PostMessageW(history, WM_KEYDOWN, VK_DOWN, 1);
break;
case 49:
PostMessageW(history, WM_KEYDOWN, VK_DOWN, 1); // no history change
break;
case 50:
SendMessageW(history, EM_SETPASSWORDCHAR, L'*', 0);
PostMessageW(history, WM_KEYDOWN, VK_UP, 1);
break;
case 51:
SetFocus(password);
SendMessageW(history, EM_SETPASSWORDCHAR, 0, 0);
PostMessageW(history, WM_KEYDOWN, VK_UP, 1); // background recall
break;
default:
DestroyWindow(window); break;
}
@@ -245,6 +298,7 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE previous, LPSTR args, int show)
SetTimer(window, 1, 1500, NULL);
MSG message;
while (GetMessageW(&message, NULL, 0, 0) > 0) {
if (history_input(&message)) continue;
TranslateMessage(&message); DispatchMessageW(&message);
}
return 0;