feat(autofill): "Clear the field before typing" setting (default ON)

The Ctrl+A + Del sent before each field misbehaves on targets where Ctrl+A
isn't select-all (terminals, some remote desktops). New synced setting
(autofillClearField, Settings > Autofill) gates it: JS appends clear=0 to
cmd://autofill/execute when off; ExecuteAutofill wraps the three
SendSelectAllAndDelete calls behind AClearFirst. Absent param = ON, so
existing behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
r-zakarya
2026-07-12 04:52:35 +01:00
parent da1284cfc3
commit b869effee5
4 changed files with 55 additions and 13 deletions
+8 -2
View File
@@ -105,6 +105,9 @@ type
// True when the pending autofill should type ONLY the username (quick
// search "autofill username" — right-click / Shift+Enter in fill mode).
FAutofillPendingUserOnly: Boolean;
// Send Ctrl+A + Del before typing each field (user setting, default ON;
// OFF for targets where Ctrl+A isn't select-all — terminals, RDP).
FAutofillPendingClear: Boolean;
// Created dynamically in FormCreate so the directive can pick either
// TTMSFNCWebBrowser or TTMSFNCEdgeWebBrowser at compile time without
// needing two .fmx variants. Aligned to Client to fill the remaining
@@ -897,6 +900,7 @@ begin
FAutofillPendingHWND := FAutofillTargetHWND;
FAutofillPendingHide := GetParam('hide_after') = '1';
FAutofillPendingUserOnly := GetParam('field') = 'user';
FAutofillPendingClear := GetParam('clear') <> '0'; // absent = ON
FAutofillTargetHWND := 0;
// Small timer so SetForegroundWindow has time to take effect before
@@ -1449,7 +1453,7 @@ procedure TMainForm.AutofillTimerTick(Sender: TObject);
var
TargetHwnd: HWND;
PendingUser, PendingPass: string;
HideAfter, UserOnly: Boolean;
HideAfter, UserOnly, ClearFirst: Boolean;
ForegroundAfter: HWND;
begin
TargetHwnd := FAutofillPendingHWND;
@@ -1457,11 +1461,13 @@ begin
PendingPass := FAutofillPendingPass;
HideAfter := FAutofillPendingHide;
UserOnly := FAutofillPendingUserOnly;
ClearFirst := FAutofillPendingClear;
FAutofillPendingHWND := 0;
FAutofillPendingUser := '';
FAutofillPendingPass := '';
FAutofillPendingHide := False;
FAutofillPendingUserOnly := False;
FAutofillPendingClear := False;
TTimer(Sender).Enabled := False;
TTimer(Sender).Free;
@@ -1470,7 +1476,7 @@ begin
// (quick-search beside the target), it stays visible during the fill; if it
// started hidden, the MinimizeToTray below re-hides it anyway.
var LFillOk := FBridge.ExecuteAutofill(TargetHwnd, PendingUser, PendingPass,
UserOnly, not HideAfter);
UserOnly, not HideAfter, ClearFirst);
ForegroundAfter := GetForegroundWindow;
LogLine(Format('Autofill executed — target=%s, foreground_after=%s, ok=%s',
[IntToHex(TargetHwnd, 8), IntToHex(ForegroundAfter, 8),