Release v0.6.31: verify trailing spaces omitted by editor copy
This commit is contained in:
+93
-1
@@ -29,6 +29,8 @@ int pasteBehavior = 0;
|
||||
int enterPresses = 0;
|
||||
int copyFailuresRemaining = 0, copyRequests = 0;
|
||||
int droppedSelectionKeys = 0;
|
||||
bool trimCopiedSpaces = false;
|
||||
int trimmedCopies = 0;
|
||||
bool temporaryClipboardExcluded = true;
|
||||
bool clipboardAccessTimedOut = false;
|
||||
LRESULT CALLBACK observeEnter(HWND w, UINT message, WPARAM wp, LPARAM lp, UINT_PTR, DWORD_PTR)
|
||||
@@ -77,6 +79,37 @@ LRESULT CALLBACK observeEnter(HWND w, UINT message, WPARAM wp, LPARAM lp, UINT_P
|
||||
--copyFailuresRemaining;
|
||||
return 0;
|
||||
}
|
||||
if (trimCopiedSpaces)
|
||||
{
|
||||
auto result = DefSubclassProc(w, message, wp, lp);
|
||||
// Native EDIT closes the clipboard in its copy handler, including
|
||||
// our outer opening. Reopen it before changing its published data.
|
||||
if (!OpenClipboard(w))
|
||||
{
|
||||
clipboardAccessTimedOut = true;
|
||||
return result;
|
||||
}
|
||||
auto handle = GetClipboardData(CF_UNICODETEXT);
|
||||
auto data = handle ? static_cast<const wchar_t *>(GlobalLock(handle)) : nullptr;
|
||||
if (data)
|
||||
{
|
||||
std::wstring copied(data);
|
||||
GlobalUnlock(handle);
|
||||
const auto originalSize = copied.size();
|
||||
while (!copied.empty() && copied.back() == L' ') copied.pop_back();
|
||||
auto replacement = GlobalAlloc(GMEM_MOVEABLE, (copied.size() + 1) * sizeof(wchar_t));
|
||||
auto output = GlobalLock(replacement);
|
||||
memcpy(output, copied.c_str(), (copied.size() + 1) * sizeof(wchar_t));
|
||||
GlobalUnlock(replacement);
|
||||
if (!EmptyClipboard() || !SetClipboardData(CF_UNICODETEXT, replacement))
|
||||
{
|
||||
GlobalFree(replacement);
|
||||
clipboardAccessTimedOut = true;
|
||||
}
|
||||
else if (copied.size() != originalSize) ++trimmedCopies;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (message == WM_PASTE && pasteBehavior)
|
||||
@@ -464,6 +497,65 @@ LRESULT CALLBACK procedure(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
require(text() == L"=тревога" && pasteBehavior == 0,
|
||||
"native Edit retries one ignored paste only while original remains selected");
|
||||
require(ks::readClipboard(app->window).text() == sentinel, "native paste retry restores clipboard");
|
||||
trimCopiedSpaces = true;
|
||||
app->settings.writeLog = false;
|
||||
prepare(L"OLDghbdtn NEXT", false);
|
||||
SendMessageW(field, EM_SETSEL, 11, 11);
|
||||
record(L"ghbdtn ");
|
||||
app->transform(ks::Direct + ru);
|
||||
break;
|
||||
}
|
||||
case 50:
|
||||
require(text() == L"OLDпривет NEXT", "trimmed clipboard recovery preserves two spaces and surrounding text without logging");
|
||||
app->transform(ks::Direct + en);
|
||||
break;
|
||||
case 51:
|
||||
require(text() == L"OLDghbdtn NEXT", "repeat conversion preserves accessibility-proven spaces");
|
||||
app->transform(ks::Undo);
|
||||
break;
|
||||
case 52:
|
||||
require(text() == L"OLDпривет NEXT", "undo preserves accessibility-proven spaces");
|
||||
prepare(L"ghbdtn", false);
|
||||
record(L"ghbdtn ");
|
||||
app->transform(ks::Direct + ru);
|
||||
break;
|
||||
case 53:
|
||||
require(text() == L"ghbdtn", "missing real space cannot be inferred from tracked keys");
|
||||
prepare(L"wrong ", false);
|
||||
record(L"ghbdtn ");
|
||||
app->transform(ks::Direct + ru);
|
||||
break;
|
||||
case 54:
|
||||
require(text() == L"wrong ", "unrelated selection remains rejected with trimmed clipboard");
|
||||
app->settings.autoCorrect = true;
|
||||
app->settings.autoLanguages = {L"en", L"ru"};
|
||||
app->autoCorrector = ks::AutoCorrector{};
|
||||
ActivateKeyboardLayout(app->layouts[en].handle, 0);
|
||||
prepare(L"ghbdtn ", false);
|
||||
record(L"ghbdtn ");
|
||||
app->transform(ks::AutoCorrect);
|
||||
break;
|
||||
case 55:
|
||||
require(text() == L"привет ", "automatic correction recovers copied trailing space without logging");
|
||||
app->transform(ks::Undo);
|
||||
break;
|
||||
case 56:
|
||||
{
|
||||
require(text() == L"ghbdtn ", "automatic correction undo retains recovered space");
|
||||
require(ks::readClipboard(app->window).text() == sentinel, "space recovery restores clipboard");
|
||||
pasteBehavior = 1;
|
||||
prepare(L"ghbdtn ", false);
|
||||
record(L"ghbdtn ");
|
||||
app->transform(ks::Direct + ru);
|
||||
break;
|
||||
}
|
||||
case 57:
|
||||
{
|
||||
require(text() == L"ghbdtn " && !ks::InputRegressionAccess::hasLast(*app),
|
||||
"recovered selection with blocked paste clears repeat state even without logging");
|
||||
require(trimmedCopies >= 7, "fixture actually stripped spaces during recovery scenarios");
|
||||
pasteBehavior = 0;
|
||||
trimCopiedSpaces = false;
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
@@ -868,7 +960,7 @@ int main(int argc, char **argv)
|
||||
field =
|
||||
CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE | ES_WANTRETURN,
|
||||
20, 20, 590, 230, host, nullptr, cls.hInstance, nullptr);
|
||||
deadline = GetTickCount64() + 30000;
|
||||
deadline = GetTickCount64() + 60000;
|
||||
SetWindowSubclass(field, observeEnter, 1, 0);
|
||||
if (typosOnly || (argc > 1 && std::string(argv[1]) == "--typing-only"))
|
||||
stage = 20;
|
||||
|
||||
Reference in New Issue
Block a user