Commit a21c91f0 authored by Shu Chen's avatar Shu Chen Committed by Commit Bot

Fix several bugs in rulebased engine.

1. Reset the rulebased engine correctly when processing keys like Enter, ArrowLeft, etc.
2. Determine invalid match when the match start position is in the middle of (ambi + ch) for history state.

Bug: 859432
Change-Id: I5b48490443c0d9ba4ee7528d7e155c816f376c09
Reviewed-on: https://chromium-review.googlesource.com/c/1319227
Commit-Queue: Shu Chen <shuchen@chromium.org>
Reviewed-by: default avatarLeo Zhang <googleo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605931}
parent 2b002979
......@@ -44,16 +44,17 @@ ProcessKeyResult Engine::ProcessKey(const std::string& code,
ProcessKeyResult res;
// The fallback result should commit the existing composition text.
res.commit_text = context_;
if (!current_data_)
return res;
if (modifier_state > 7)
if (!current_data_ || modifier_state > 7) {
Reset();
return res;
}
const KeyMap* key_map = current_data_->GetKeyMapByModifiers(modifier_state);
auto it = key_map->find(code);
if (it == key_map->end()) {
if (code == "Backspace" && !context_.empty())
return ProcessBackspace();
Reset();
return res;
}
......
......@@ -327,6 +327,14 @@ bool RulesData::Transform(const std::string& context,
auto& re = *(std::get<0>(rule));
const std::string& repl = std::get<1>(rule);
// Don't transform if matching happens in the middle of |appended| string.
if (re.Match(str, 0, str.length(), re2::RE2::Anchor::UNANCHORED,
matches.get(), nmatch)) {
size_t match_start = matches[0].data() - str.data();
if (match_start > str.length() - appended.length())
return false;
}
re2::RE2::Replace(&str, re, repl);
re2::RE2::Replace(&str, "\u001d", "");
*transformed = str;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment