Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions core/src/actions_normalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ bool km::core::actions_normalize(
To adjust, we remove one codepoint at a time from the app_context until
its normalized form matches the cached_context normalized form.
*/
std::u32string context_final = U"";

while(!app_context_string.empty()) {
auto app_context_nfd = app_context_string;
Expand All @@ -141,7 +142,16 @@ bool km::core::actions_normalize(
return false;
}

if(app_context_nfd == cached_context_string) {
/*
We are working in NFD as we backtrack in the context, but input variable
app_context_string is NFC. The last character of the context may be part
of a composed character, so we need to track decomposition. For example,
'tä' + BKSP should result in 'ta', but delete back 1 in app_context_string
will give us 't', so we need to remember 'a', and add it back afterwards
(see output_nfc variable).
*/
if(app_context_nfd == cached_context_string.substr(0, app_context_nfd.length())) {
context_final = cached_context_string.substr(app_context_nfd.length());
break;
}

Expand All @@ -155,7 +165,7 @@ bool km::core::actions_normalize(
Normalize our output string
*/

auto output_nfc = output;
auto output_nfc = context_final + output;
if(!km::core::util::normalize_nfc(output_nfc)) {
DebugLog("nfc->normalize failed");
return false;
Expand Down Expand Up @@ -197,6 +207,8 @@ bool km::core::actions_normalize(
actions.output = new_output;
actions.code_points_to_delete = nfu_to_delete;

// Outcome will be: <app_context><context_final><output>|

return true;
}

Expand Down
11 changes: 11 additions & 0 deletions core/tests/unit/kmnkbd/actions_normalize.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,17 @@ void run_actions_normalize_tests() {
/* app_context: */ u"abcệ"
);

test_actions_normalize(
"One backspace to delete last NFD character (#15487)",
/* app context pre transform: */ u"abcê", // NFC
/* cached context post transform: */ u"abce",
/* cached context post transform: */ nullptr,
/* action del, output: */ 1, U"", // NFD input; delete 1: \u0302
// ---- results ----
/* action del, output: */ 1, U"e", // NFC output; delete 1: e
/* app_context: */ u"abce"
);

test_actions_normalize(
"One backspace for NFD converts into one char in NFC (ê) and recombine",
/* app context pre transform: */ u"abcê",
Expand Down