Commit 69d34166 authored by Sidney San Martín's avatar Sidney San Martín Committed by Commit Bot

[Mac] Move selection validation to a Touch Bar-specific place.

Effectively changes three things from r612882:
1. Reverts the checks in OnTextSelectionChanged(). This drops
   DumpWithoutCrashing(), which was louder than intended, and avoids
   potentially changing non-Touch Bar behavior.
2. Preserves the new behavior of ignoring an invalid selection instead of
   clearing the existing suggestions by removing the selection-clearing code.
3. Adds a bounds check that was removed in (1) into Touch Bar code.

Bug: 893038, 910950
Change-Id: I6fdb30a71ce64680fb06ce73072c9171da36da32
Reviewed-on: https://chromium-review.googlesource.com/c/1358695Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Sidney San Martín <sdy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613105}
parent 5afcca7a
......@@ -250,19 +250,15 @@ void ExtractUnderlines(NSAttributedString* string,
updateWithInsertionPointVisibility:textSelectionRange_.is_empty()];
if (!touchBarItem.candidateListVisible)
return;
if (!textSelectionRange_.IsValid()) {
[touchBarItem setCandidates:@[]
forSelectedRange:NSMakeRange(NSNotFound, 0)
inString:nil];
// Bump the sequence number so that any request in flight is ignored.
textSuggestionsSequenceNumber_ += 1;
if (!textSelectionRange_.IsValid() ||
textSelectionOffset_ > textSelectionRange_.GetMin())
return;
}
NSRange selectionRange = textSelectionRange_.ToNSRange();
NSString* selectionText = base::SysUTF16ToNSString(textSelectionText_);
selectionRange.location -= textSelectionOffset_;
if (NSMaxRange(selectionRange) > selectionText.length)
return;
NSSpellChecker* spell_checker = spellCheckerForTesting_
? spellCheckerForTesting_
: [NSSpellChecker sharedSpellChecker];
......
......@@ -11,7 +11,6 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/debug/dump_without_crashing.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/mac/mac_util.h"
......@@ -657,23 +656,6 @@ void RenderWidgetHostViewMac::OnTextSelectionChanged(
if (!selection)
return;
if (!selection->range().IsValid()) {
LOG(ERROR) << "Invalid selection range.";
base::debug::DumpWithoutCrashing();
return;
}
gfx::Range text_range(selection->offset(),
selection->text().length() + selection->offset());
if (selection->range().GetMin() < text_range.GetMin() ||
selection->range().GetMax() > text_range.GetMax()) {
LOG(ERROR) << "Selection with range " << selection->range().ToString()
<< " in a chunk of text which only covers "
<< text_range.ToString() << ".";
base::debug::DumpWithoutCrashing();
return;
}
ns_view_bridge_->SetTextSelection(selection->text(), selection->offset(),
selection->range());
}
......
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