Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
nitsakh committed Oct 15, 2018
1 parent c46860a commit e6956b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
33 changes: 16 additions & 17 deletions atom/renderer/api/atom_api_spell_check_client.cc
Expand Up @@ -4,7 +4,7 @@

#include "atom/renderer/api/atom_api_spell_check_client.h"

#include <algorithm>
#include <map>
#include <vector>

#include "atom/common/native_mate_converters/string16_converter.h"
Expand Down Expand Up @@ -52,7 +52,7 @@ class SpellCheckClient::SpellcheckRequest {
}
~SpellcheckRequest() {}

base::string16& text() { return text_; }
const base::string16& text() const { return text_; }
blink::WebTextCheckingCompletion* completion() { return completion_; }
WordMap& wordmap() { return word_map_; }

Expand Down Expand Up @@ -146,35 +146,29 @@ void SpellCheckClient::SpellCheckText() {

SpellCheckScope scope(*this);
base::string16 word;
int word_start;
int word_length;
std::vector<base::string16> words;
auto& word_map = pending_request_param_->wordmap();
for (auto status =
text_iterator_.GetNextWord(&word, &word_start, &word_length);
status != SpellcheckWordIterator::IS_END_OF_TEXT;
status = text_iterator_.GetNextWord(&word, &word_start, &word_length)) {
blink::WebTextCheckingResult result;
for (;;) { // Run until end of text
const auto status =
text_iterator_.GetNextWord(&word, &result.location, &result.length);
if (status == SpellcheckWordIterator::IS_END_OF_TEXT)
break;
if (status == SpellcheckWordIterator::IS_SKIPPABLE)
continue;

// If the given word is a concatenated word of two or more valid words
// (e.g. "hello:hello"), we should treat it as a valid word.
std::vector<base::string16> contraction_words;
if (!IsContraction(scope, word, &contraction_words)) {
blink::WebTextCheckingResult result;
result.location = word_start;
result.length = word_length;
words.push_back(word);
word_map[word].push_back(result);
} else {
// For a contraction, we want check the spellings of each individual
// part, but mark the entire word incorrect if any part is misspelt
// part, but mark the entire word incorrect if any part is misspelled
// Hence, we use the same word_start and word_length values for every
// part of the contraction.
for (const auto& w : contraction_words) {
blink::WebTextCheckingResult result;
result.location = word_start;
result.length = word_length;
words.push_back(w);
word_map[w].push_back(result);
}
Expand All @@ -186,15 +180,20 @@ void SpellCheckClient::SpellCheckText() {
}

void SpellCheckClient::OnSpellCheckDone(
const std::vector<base::string16>& misspelt_words) {
const std::vector<base::string16>& misspelled_words) {
std::vector<blink::WebTextCheckingResult> results;
auto* const completion_handler = pending_request_param_->completion();

auto& word_map = pending_request_param_->wordmap();

for (const auto& word : misspelt_words) {
// Take each word from the list of misspelled words received, find their
// corresponding WebTextCheckingResult that's stored in the map and pass
// all the results to blink through the completion callback.
for (const auto& word : misspelled_words) {
auto iter = word_map.find(word);
if (iter != word_map.end()) {
// Word found in map, now gather all the occurrences of the word
// from the map value
auto& words = iter->second;
results.insert(results.end(), words.begin(), words.end());
words.clear();
Expand Down
7 changes: 3 additions & 4 deletions atom/renderer/api/atom_api_spell_check_client.h
Expand Up @@ -5,7 +5,6 @@
#ifndef ATOM_RENDERER_API_ATOM_API_SPELL_CHECK_CLIENT_H_
#define ATOM_RENDERER_API_ATOM_API_SPELL_CHECK_CLIENT_H_

#include <map>
#include <memory>
#include <string>
#include <vector>
Expand Down Expand Up @@ -67,7 +66,7 @@ class SpellCheckClient : public blink::WebSpellCheckPanelHostClient,

// Call JavaScript to check spelling a word.
// The javascript function will callback OnSpellCheckDone
// with the results of all the misspelt words.
// with the results of all the misspelled words.
void SpellCheckWords(const SpellCheckScope& scope,
const std::vector<base::string16>& words);

Expand All @@ -79,8 +78,8 @@ class SpellCheckClient : public blink::WebSpellCheckPanelHostClient,
const base::string16& word,
std::vector<base::string16>* contraction_words);

// Callback for the JS API which returns the list of misspelt words.
void OnSpellCheckDone(const std::vector<base::string16>& misspelt_words);
// Callback for the JS API which returns the list of misspelled words.
void OnSpellCheckDone(const std::vector<base::string16>& misspelled_words);

// Represents character attributes used for filtering out characters which
// are not supported by this SpellCheck object.
Expand Down

0 comments on commit e6956b3

Please sign in to comment.