Add configurable offline layout correction and latest Windows release
This commit is contained in:
+97
-1
@@ -8,6 +8,10 @@ HWND host{}, field{};
|
||||
ks::Clip saved;
|
||||
bool captured = false, failed = false;
|
||||
int stage = 0, ru = -1, en = -1;
|
||||
size_t punctuationCase = 0;
|
||||
const std::vector<std::pair<std::wstring, std::wstring>> punctuationCases{
|
||||
{L"(ljvf) ", L"(дома) "}, {L"[ljvf] ", L"[дома] "}, {L"{ljvf} ", L"{дома} "},
|
||||
{L"ljvf: ", L"дома: "}, {L"ljvf; ", L"дома; "}, {L"#ljvf%; ", L"#дома%; "}};
|
||||
ULONGLONG deadline{};
|
||||
std::wstring sentinel = L"KSwitcher integration clipboard sentinel";
|
||||
void require(bool ok, const char *name)
|
||||
@@ -58,6 +62,9 @@ void finish()
|
||||
}
|
||||
LRESULT CALLBACK procedure(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
// Model a host that does not forward layout requests to its embedded editor.
|
||||
if (msg == WM_INPUTLANGCHANGEREQUEST)
|
||||
return 0;
|
||||
if (msg == WM_TIMER)
|
||||
{
|
||||
try
|
||||
@@ -119,9 +126,98 @@ LRESULT CALLBACK procedure(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
require(start == end && start == 14, "verified snippet cursor placement");
|
||||
require(ks::readClipboard(app->window).text() == sentinel,
|
||||
"clipboard restored after repeated copy transactions");
|
||||
finish();
|
||||
app->settings.autoCorrect = true;
|
||||
app->settings.switchLayout = true;
|
||||
app->settings.autoLanguages = {L"en", L"ru"};
|
||||
app->settings.cycle = {app->layouts[en].id, app->layouts[ru].id};
|
||||
ActivateKeyboardLayout(app->layouts[en].handle, 0);
|
||||
prepare(L"ghbdtn ", false);
|
||||
record(L"ghbdtn ");
|
||||
app->transform(ks::AutoCorrect);
|
||||
break;
|
||||
}
|
||||
case 8:
|
||||
require(text() == L"привет ", "automatic dictionary correction in native editor");
|
||||
require(ks::windowLayout(host) == app->layouts[ru].handle,
|
||||
"auto-correction switches focused editor layout even when host ignores requests");
|
||||
app->transform(ks::Undo);
|
||||
break;
|
||||
case 9:
|
||||
require(text() == L"ghbdtn ", "automatic correction undo retains space");
|
||||
require(ks::windowLayout(host) == app->layouts[en].handle,
|
||||
"undo restores the original keyboard layout");
|
||||
prepare(L"ghbdtn ", false);
|
||||
record(L"ghbdtn ");
|
||||
app->transform(ks::AutoCorrect);
|
||||
break;
|
||||
case 10:
|
||||
require(text() == L"ghbdtn ", "undo prevents repeated automatic correction");
|
||||
prepare(L"hello ", false);
|
||||
record(L"hello ");
|
||||
app->transform(ks::AutoCorrect);
|
||||
break;
|
||||
case 11:
|
||||
require(text() == L"hello ", "known word stays unchanged in editor");
|
||||
require(ks::readClipboard(app->window).text() == sentinel,
|
||||
"automatic correction restores clipboard");
|
||||
app->autoCorrector = ks::AutoCorrector{};
|
||||
prepare(L"OLDghbdtn ", false);
|
||||
record(L"ghbdtn ");
|
||||
app->transform(ks::AutoCorrect);
|
||||
break;
|
||||
case 12:
|
||||
require(text() == L"OLDghbdtn ", "automatic correction refuses partial word replacement");
|
||||
DestroyWindow(field);
|
||||
field = CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_PASSWORD, 20, 20,
|
||||
590, 30, host, nullptr, GetModuleHandleW(nullptr), nullptr);
|
||||
prepare(L"ghbdtn ", false);
|
||||
record(L"ghbdtn ");
|
||||
app->transform(ks::AutoCorrect);
|
||||
break;
|
||||
case 13:
|
||||
require(text() == L"ghbdtn ", "password input is never automatically corrected");
|
||||
require(ks::readClipboard(app->window).text() == sentinel,
|
||||
"password input never copied to clipboard");
|
||||
DestroyWindow(field);
|
||||
field = CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER, 20, 20, 590, 30, host,
|
||||
nullptr, GetModuleHandleW(nullptr), nullptr);
|
||||
prepare(L"(ljvf ", false);
|
||||
record(L"(ljvf ");
|
||||
app->transform(ks::AutoCorrect);
|
||||
break;
|
||||
case 14:
|
||||
require(text() == L"(дома ", "automatic correction preserves opening parenthesis in editor");
|
||||
app->transform(ks::Undo);
|
||||
break;
|
||||
case 15:
|
||||
require(text() == L"(ljvf ", "undo preserves opening parenthesis in editor");
|
||||
require(ks::readClipboard(app->window).text() == sentinel,
|
||||
"parenthesized correction restores clipboard");
|
||||
app->settings.autoPrefixChars += L"#";
|
||||
app->settings.autoSuffixChars += L"%";
|
||||
app->autoCorrector = ks::AutoCorrector{};
|
||||
prepare(punctuationCases[0].first.c_str(), false);
|
||||
record(punctuationCases[0].first);
|
||||
app->transform(ks::AutoCorrect);
|
||||
break;
|
||||
case 16:
|
||||
require(text() == punctuationCases[punctuationCase].second,
|
||||
"configured punctuation preserved in editor");
|
||||
if (++punctuationCase < punctuationCases.size())
|
||||
{
|
||||
ActivateKeyboardLayout(app->layouts[en].handle, 0);
|
||||
prepare(punctuationCases[punctuationCase].first.c_str(), false);
|
||||
record(punctuationCases[punctuationCase].first);
|
||||
app->transform(ks::AutoCorrect);
|
||||
stage = 16;
|
||||
}
|
||||
else
|
||||
app->transform(ks::Undo);
|
||||
break;
|
||||
case 17:
|
||||
require(text() == punctuationCases.back().first, "undo preserves custom punctuation");
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
|
||||
Reference in New Issue
Block a user