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
+18 -10
View File
@@ -171,9 +171,10 @@ type
// the caller trays it after the fill.
// Returns False when nothing was typed: elevated target (UIPI would
// silently drop the keystrokes) or focus never left our own window.
// AClearFirst: send Ctrl+A + Del before each field (user setting).
function ExecuteAutofill(ATargetHWND: HWND;
const AUsername, APassword: string; AUsernameOnly: Boolean = False;
ARestoreAfter: Boolean = False): Boolean;
ARestoreAfter: Boolean = False; AClearFirst: Boolean = True): Boolean;
property SecureClipboard: TSecureClipboard read FSecureClipboard;
property TrayAdded: Boolean read FTrayAdded;
property AutofillRegistered: Boolean read FAutofillRegistered;
@@ -1187,10 +1188,21 @@ end;
function TPMBridge.ExecuteAutofill(ATargetHWND: HWND;
const AUsername, APassword: string; AUsernameOnly: Boolean = False;
ARestoreAfter: Boolean = False): Boolean;
ARestoreAfter: Boolean = False; AClearFirst: Boolean = True): Boolean;
const
MinimizeSettleMs = 80;
FocusSettleDelayMs = 120;
// Ctrl+A + Del to empty the target field — skipped when the user turned
// "Clear the field before typing" off (Ctrl+A isn't select-all everywhere:
// terminals, some remote desktops).
procedure ClearFieldIfWanted;
begin
if not AClearFirst then Exit;
SendSelectAllAndDelete;
Sleep(60);
end;
var
OwnFormHwnd: HWND;
begin
@@ -1233,28 +1245,24 @@ begin
// no password. Used by the quick-search right-click / Shift+Enter path.
if AUsernameOnly then
begin
SendSelectAllAndDelete;
Sleep(60);
ClearFieldIfWanted;
SendUnicodeString(AUsername);
Exit;
end;
if AUsername = '' then
begin
SendSelectAllAndDelete;
Sleep(60);
ClearFieldIfWanted;
SendUnicodeString(APassword);
Exit;
end;
SendSelectAllAndDelete;
Sleep(60);
ClearFieldIfWanted;
SendUnicodeString(AUsername);
Sleep(200);
SendVKey(VK_TAB);
Sleep(200);
SendSelectAllAndDelete;
Sleep(60);
ClearFieldIfWanted;
SendUnicodeString(APassword);
end;