<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[205870] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/205870">205870</a></dd>
<dt>Author</dt> <dd>timothy_horton@apple.com</dd>
<dt>Date</dt> <dd>2016-09-13 12:44:42 -0700 (Tue, 13 Sep 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Undoing a candidate insertion results in the replaced text being selected
https://bugs.webkit.org/show_bug.cgi?id=161894
&lt;rdar://problem/28225774&gt;

Reviewed by Simon Fraser.

Test: editing/mac/spelling/accept-candidate-undo-does-not-select.html

* WebCore.xcodeproj/project.pbxproj:
* editing/ReplaceRangeWithTextCommand.cpp: Added.
(WebCore::ReplaceRangeWithTextCommand::ReplaceRangeWithTextCommand):
(WebCore::ReplaceRangeWithTextCommand::doApply):
* editing/ReplaceRangeWithTextCommand.h: Added.
(WebCore::ReplaceRangeWithTextCommand::create):
Add a editor command that replaces a range with the given text.

* editing/Editor.cpp:
(WebCore::Editor::rangeForTextCheckingResult):
(WebCore::Editor::handleAcceptedCandidate):
(WebCore::Editor::selectTextCheckingResult): Deleted.
* editing/Editor.h:
Make use of the new editor command to do candidate insertion as a single
composite operation, so that it is undone as a unit. Otherwise, undo ends up
undoing the insertion, but not the selection, and we are left with the old
text, selected, which is undesirable.

* editing/mac/spelling/accept-candidate-allows-autocorrect-on-next-word-expected.txt:
* editing/mac/spelling/accept-candidate-replacing-multiple-words-expected.txt:
* editing/mac/spelling/accept-candidate-undo-does-not-select-expected.txt: Copied from LayoutTests/editing/mac/spelling/accept-candidate-replacing-multiple-words-expected.txt.
* editing/mac/spelling/accept-candidate-undo-does-not-select.html: Added.
* editing/mac/spelling/accept-candidate-without-adding-space-expected.txt:
* editing/mac/spelling/accept-candidate-without-crossing-editing-boundary-expected.txt:
Adjust some test results, and add a new test that ensures that undoing
a candidate insertion does not select the replaced text.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestseditingmacspellingacceptcandidateallowsautocorrectonnextwordexpectedtxt">trunk/LayoutTests/editing/mac/spelling/accept-candidate-allows-autocorrect-on-next-word-expected.txt</a></li>
<li><a href="#trunkLayoutTestseditingmacspellingacceptcandidatereplacingmultiplewordsexpectedtxt">trunk/LayoutTests/editing/mac/spelling/accept-candidate-replacing-multiple-words-expected.txt</a></li>
<li><a href="#trunkLayoutTestseditingmacspellingacceptcandidatewithoutaddingspaceexpectedtxt">trunk/LayoutTests/editing/mac/spelling/accept-candidate-without-adding-space-expected.txt</a></li>
<li><a href="#trunkLayoutTestseditingmacspellingacceptcandidatewithoutcrossingeditingboundaryexpectedtxt">trunk/LayoutTests/editing/mac/spelling/accept-candidate-without-crossing-editing-boundary-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreCMakeListstxt">trunk/Source/WebCore/CMakeLists.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCoreeditingEditingAllInOnecpp">trunk/Source/WebCore/editing/EditingAllInOne.cpp</a></li>
<li><a href="#trunkSourceWebCoreeditingEditorcpp">trunk/Source/WebCore/editing/Editor.cpp</a></li>
<li><a href="#trunkSourceWebCoreeditingEditorh">trunk/Source/WebCore/editing/Editor.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestseditingmacspellingacceptcandidateundodoesnotselectexpectedtxt">trunk/LayoutTests/editing/mac/spelling/accept-candidate-undo-does-not-select-expected.txt</a></li>
<li><a href="#trunkLayoutTestseditingmacspellingacceptcandidateundodoesnotselecthtml">trunk/LayoutTests/editing/mac/spelling/accept-candidate-undo-does-not-select.html</a></li>
<li><a href="#trunkSourceWebCoreeditingReplaceRangeWithTextCommandcpp">trunk/Source/WebCore/editing/ReplaceRangeWithTextCommand.cpp</a></li>
<li><a href="#trunkSourceWebCoreeditingReplaceRangeWithTextCommandh">trunk/Source/WebCore/editing/ReplaceRangeWithTextCommand.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (205869 => 205870)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-09-13 19:08:30 UTC (rev 205869)
+++ trunk/LayoutTests/ChangeLog        2016-09-13 19:44:42 UTC (rev 205870)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2016-09-13  Tim Horton  &lt;timothy_horton@apple.com&gt;
+
+        Undoing a candidate insertion results in the replaced text being selected
+        https://bugs.webkit.org/show_bug.cgi?id=161894
+        &lt;rdar://problem/28225774&gt;
+
+        Reviewed by Simon Fraser.
+
+        * editing/mac/spelling/accept-candidate-allows-autocorrect-on-next-word-expected.txt:
+        * editing/mac/spelling/accept-candidate-replacing-multiple-words-expected.txt:
+        * editing/mac/spelling/accept-candidate-undo-does-not-select-expected.txt: Copied from LayoutTests/editing/mac/spelling/accept-candidate-replacing-multiple-words-expected.txt.
+        * editing/mac/spelling/accept-candidate-undo-does-not-select.html: Added.
+        * editing/mac/spelling/accept-candidate-without-adding-space-expected.txt:
+        * editing/mac/spelling/accept-candidate-without-crossing-editing-boundary-expected.txt:
+        Adjust some test results, and add a new test that ensures that undoing
+        a candidate insertion does not select the replaced text.
+
</ins><span class="cx"> 2016-09-13  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: Should be able to pretty print module code (import / export statements)
</span></span></pre></div>
<a id="trunkLayoutTestseditingmacspellingacceptcandidateallowsautocorrectonnextwordexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/mac/spelling/accept-candidate-allows-autocorrect-on-next-word-expected.txt (205869 => 205870)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/mac/spelling/accept-candidate-allows-autocorrect-on-next-word-expected.txt        2016-09-13 19:08:30 UTC (rev 205869)
+++ trunk/LayoutTests/editing/mac/spelling/accept-candidate-allows-autocorrect-on-next-word-expected.txt        2016-09-13 19:44:42 UTC (rev 205870)
</span><span class="lines">@@ -70,9 +70,11 @@
</span><span class="cx"> EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 21 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document to 21 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 22 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document to 22 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</span><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><span class="cx"> EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
</span><del>-EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</del><span class="cx"> EDITING DELEGATE: shouldInsertText:extremely long replacingDOMRange:range from 2 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document to 15 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document givenAction:WebViewInsertActionTyped
</span><ins>+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 22 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document to 22 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 2 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document to 15 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 22 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document to 22 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 2 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document to 15 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</ins><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><ins>+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</ins><span class="cx"> EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 2 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 16 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document to 16 of #text &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</span><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><span class="cx"> EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
</span></span></pre></div>
<a id="trunkLayoutTestseditingmacspellingacceptcandidatereplacingmultiplewordsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/mac/spelling/accept-candidate-replacing-multiple-words-expected.txt (205869 => 205870)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/mac/spelling/accept-candidate-replacing-multiple-words-expected.txt        2016-09-13 19:08:30 UTC (rev 205869)
+++ trunk/LayoutTests/editing/mac/spelling/accept-candidate-replacing-multiple-words-expected.txt        2016-09-13 19:44:42 UTC (rev 205870)
</span><span class="lines">@@ -30,9 +30,11 @@
</span><span class="cx"> EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 8 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 8 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</span><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><span class="cx"> EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
</span><del>-EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</del><span class="cx"> EDITING DELEGATE: shouldInsertText:good idea  replacingDOMRange:range from 0 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document givenAction:WebViewInsertActionTyped
</span><ins>+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 0 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 0 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</ins><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><ins>+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</ins><span class="cx"> EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 10 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 10 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</span><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><span class="cx"> EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
</span></span></pre></div>
<a id="trunkLayoutTestseditingmacspellingacceptcandidateundodoesnotselectexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/mac/spelling/accept-candidate-undo-does-not-select-expected.txt (0 => 205870)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/mac/spelling/accept-candidate-undo-does-not-select-expected.txt                                (rev 0)
+++ trunk/LayoutTests/editing/mac/spelling/accept-candidate-undo-does-not-select-expected.txt        2016-09-13 19:44:42 UTC (rev 205870)
</span><span class="lines">@@ -0,0 +1,54 @@
</span><ins>+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 1 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 1 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 1 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 3 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 3 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 3 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 3 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 4 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 4 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 3 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 3 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 5 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 5 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 5 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 5 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 6 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 6 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 6 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 6 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 7 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 7 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 7 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 7 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 8 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 8 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 8 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 8 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: shouldInsertText:good idea  replacingDOMRange:range from 0 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document givenAction:WebViewInsertActionTyped
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 0 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 0 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 10 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 10 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 9 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 10 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 10 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+PASS successfullyParsed is true
+
+TEST COMPLETE
+This test verifies that undoing an accepted candidate replacement doesn't select the original text.
+
+goo didea.
</ins></span></pre></div>
<a id="trunkLayoutTestseditingmacspellingacceptcandidateundodoesnotselecthtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/mac/spelling/accept-candidate-undo-does-not-select.html (0 => 205870)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/mac/spelling/accept-candidate-undo-does-not-select.html                                (rev 0)
+++ trunk/LayoutTests/editing/mac/spelling/accept-candidate-undo-does-not-select.html        2016-09-13 19:44:42 UTC (rev 205870)
</span><span class="lines">@@ -0,0 +1,52 @@
</span><ins>+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=../../editing.js&gt;&lt;/script&gt;
+&lt;script src=&quot;../../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+
+function editingTest() {
+    if (window.testRunner) {
+        testRunner.waitUntilDone();
+        testRunner.dumpAsText(true);
+    }
+
+    edit = document.getElementById('edit');
+    edit.focus();
+    typeCharacterCommand('g');
+    typeCharacterCommand('o');
+    typeCharacterCommand('o');
+    typeCharacterCommand(' ');
+    typeCharacterCommand('d');
+    typeCharacterCommand('i');
+    typeCharacterCommand('d');
+    typeCharacterCommand('e');
+    typeCharacterCommand('a');    
+
+    // Wait a bit before swapping in the candidate, because otherwise 
+    // AppKit can combine the undo of the candidate insertion with the other text.
+    setTimeout(function () {
+        if (window.internals)
+            internals.handleAcceptedCandidate(&quot;good idea &quot;, 0, 9);
+
+        undoCommand();
+
+        // If the undo wrongly left &quot;goo didea&quot; selected, this will replace it.
+        typeCharacterCommand('.');
+
+        testRunner.notifyDone();
+    }, 100);
+}
+
+&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;p&gt;This test verifies that undoing an accepted candidate replacement doesn't select the original text.&lt;/p&gt;
+&lt;div style=&quot;border:1px solid black;&quot;&gt;
+    &lt;div contenteditable=&quot;true&quot; id=&quot;edit&quot;&gt;&lt;/div&gt;
+&lt;/div&gt;
+&lt;script&gt;
+runEditingTest();
+&lt;/script&gt;
+&lt;script src=&quot;../../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestseditingmacspellingacceptcandidatewithoutaddingspaceexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/mac/spelling/accept-candidate-without-adding-space-expected.txt (205869 => 205870)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/mac/spelling/accept-candidate-without-adding-space-expected.txt        2016-09-13 19:08:30 UTC (rev 205869)
+++ trunk/LayoutTests/editing/mac/spelling/accept-candidate-without-adding-space-expected.txt        2016-09-13 19:44:42 UTC (rev 205870)
</span><span class="lines">@@ -8,9 +8,11 @@
</span><span class="cx"> EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 1 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</span><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><span class="cx"> EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
</span><del>-EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</del><span class="cx"> EDITING DELEGATE: shouldInsertText:is replacingDOMRange:range from 0 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document givenAction:WebViewInsertActionTyped
</span><ins>+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 0 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 0 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</ins><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><ins>+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</ins><span class="cx"> EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</span><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><span class="cx"> EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
</span></span></pre></div>
<a id="trunkLayoutTestseditingmacspellingacceptcandidatewithoutcrossingeditingboundaryexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/mac/spelling/accept-candidate-without-crossing-editing-boundary-expected.txt (205869 => 205870)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/mac/spelling/accept-candidate-without-crossing-editing-boundary-expected.txt        2016-09-13 19:08:30 UTC (rev 205869)
+++ trunk/LayoutTests/editing/mac/spelling/accept-candidate-without-crossing-editing-boundary-expected.txt        2016-09-13 19:44:42 UTC (rev 205870)
</span><span class="lines">@@ -8,9 +8,11 @@
</span><span class="cx"> EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 1 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</span><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><span class="cx"> EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
</span><del>-EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</del><span class="cx"> EDITING DELEGATE: shouldInsertText:happy  replacingDOMRange:range from 0 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document givenAction:WebViewInsertActionTyped
</span><ins>+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 0 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 0 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 2 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</ins><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><ins>+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</ins><span class="cx"> EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 0 of DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document toDOMRange:range from 6 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document to 6 of #text &gt; DIV &gt; DIV &gt; BODY &gt; HTML &gt; #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
</span><span class="cx"> EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
</span><span class="cx"> EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
</span></span></pre></div>
<a id="trunkSourceWebCoreCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/CMakeLists.txt (205869 => 205870)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/CMakeLists.txt        2016-09-13 19:08:30 UTC (rev 205869)
+++ trunk/Source/WebCore/CMakeLists.txt        2016-09-13 19:44:42 UTC (rev 205870)
</span><span class="lines">@@ -1559,6 +1559,7 @@
</span><span class="cx">     editing/RemoveNodePreservingChildrenCommand.cpp
</span><span class="cx">     editing/RenderedPosition.cpp
</span><span class="cx">     editing/ReplaceNodeWithSpanCommand.cpp
</span><ins>+    editing/ReplaceRangeWithTextCommand.cpp
</ins><span class="cx">     editing/ReplaceSelectionCommand.cpp
</span><span class="cx">     editing/SetNodeAttributeCommand.cpp
</span><span class="cx">     editing/SetSelectionCommand.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (205869 => 205870)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-09-13 19:08:30 UTC (rev 205869)
+++ trunk/Source/WebCore/ChangeLog        2016-09-13 19:44:42 UTC (rev 205870)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2016-09-13  Tim Horton  &lt;timothy_horton@apple.com&gt;
+
+        Undoing a candidate insertion results in the replaced text being selected
+        https://bugs.webkit.org/show_bug.cgi?id=161894
+        &lt;rdar://problem/28225774&gt;
+
+        Reviewed by Simon Fraser.
+
+        Test: editing/mac/spelling/accept-candidate-undo-does-not-select.html
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * editing/ReplaceRangeWithTextCommand.cpp: Added.
+        (WebCore::ReplaceRangeWithTextCommand::ReplaceRangeWithTextCommand):
+        (WebCore::ReplaceRangeWithTextCommand::doApply):
+        * editing/ReplaceRangeWithTextCommand.h: Added.
+        (WebCore::ReplaceRangeWithTextCommand::create):
+        Add a editor command that replaces a range with the given text.
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::rangeForTextCheckingResult):
+        (WebCore::Editor::handleAcceptedCandidate):
+        (WebCore::Editor::selectTextCheckingResult): Deleted.
+        * editing/Editor.h:
+        Make use of the new editor command to do candidate insertion as a single
+        composite operation, so that it is undone as a unit. Otherwise, undo ends up
+        undoing the insertion, but not the selection, and we are left with the old
+        text, selected, which is undesirable.
+
</ins><span class="cx"> 2016-09-13  Dave Hyatt  &lt;hyatt@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [CSS Parser] Add CSS Variable Parsing support
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (205869 => 205870)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2016-09-13 19:08:30 UTC (rev 205869)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2016-09-13 19:44:42 UTC (rev 205870)
</span><span class="lines">@@ -1231,6 +1231,8 @@
</span><span class="cx">                 2DCB837A19F99BBA00A7FBE4 /* NSSharingServiceSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DCB837819F99BBA00A7FBE4 /* NSSharingServiceSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 2DDB97F419F9AECA002025D8 /* NSExtensionSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DDB97F319F9AECA002025D8 /* NSExtensionSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 2DE70023192FE82A00B0975C /* DisplayRefreshMonitorMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DE70022192FE82A00B0975C /* DisplayRefreshMonitorMac.h */; };
</span><ins>+                2DF512CD1D873E47001D6780 /* ReplaceRangeWithTextCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2DF512CB1D873E47001D6780 /* ReplaceRangeWithTextCommand.cpp */; };
+                2DF512CE1D873E47001D6780 /* ReplaceRangeWithTextCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DF512CC1D873E47001D6780 /* ReplaceRangeWithTextCommand.h */; };
</ins><span class="cx">                 2E0888D41148848A00AF4265 /* JSDOMFormData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2E0888D21148848A00AF4265 /* JSDOMFormData.cpp */; };
</span><span class="cx">                 2E0888D51148848A00AF4265 /* JSDOMFormData.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E0888D31148848A00AF4265 /* JSDOMFormData.h */; };
</span><span class="cx">                 2E19516B1B6598D200DF6EEF /* WheelEventDeltaFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2E19516A1B6598D200DF6EEF /* WheelEventDeltaFilter.cpp */; };
</span><span class="lines">@@ -8159,6 +8161,8 @@
</span><span class="cx">                 2DCB837819F99BBA00A7FBE4 /* NSSharingServiceSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSSharingServiceSPI.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2DDB97F319F9AECA002025D8 /* NSExtensionSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSExtensionSPI.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2DE70022192FE82A00B0975C /* DisplayRefreshMonitorMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisplayRefreshMonitorMac.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                2DF512CB1D873E47001D6780 /* ReplaceRangeWithTextCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReplaceRangeWithTextCommand.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
+                2DF512CC1D873E47001D6780 /* ReplaceRangeWithTextCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReplaceRangeWithTextCommand.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 2E0888C3114883A900AF4265 /* DOMFormData.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DOMFormData.idl; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2E0888D21148848A00AF4265 /* JSDOMFormData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMFormData.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2E0888D31148848A00AF4265 /* JSDOMFormData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMFormData.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -17618,6 +17622,8 @@
</span><span class="cx">                                 93309DB6099E64910056E581 /* RemoveNodeCommand.h */,
</span><span class="cx">                                 93309DB7099E64910056E581 /* RemoveNodePreservingChildrenCommand.cpp */,
</span><span class="cx">                                 93309DB8099E64910056E581 /* RemoveNodePreservingChildrenCommand.h */,
</span><ins>+                                2DF512CB1D873E47001D6780 /* ReplaceRangeWithTextCommand.cpp */,
+                                2DF512CC1D873E47001D6780 /* ReplaceRangeWithTextCommand.h */,
</ins><span class="cx">                                 9B32CDA813DF7FA900F34D13 /* RenderedPosition.cpp */,
</span><span class="cx">                                 9B32CDA713DF7FA900F34D13 /* RenderedPosition.h */,
</span><span class="cx">                                 A89CCC500F44E98100B5DA10 /* ReplaceNodeWithSpanCommand.cpp */,
</span><span class="lines">@@ -26791,6 +26797,7 @@
</span><span class="cx">                                 26FAE4CF1852E3A5004C8C46 /* SynchronousResourceHandleCFURLConnectionDelegate.h in Headers */,
</span><span class="cx">                                 0F03C0741884695E00A5F8CA /* SystemMemory.h in Headers */,
</span><span class="cx">                                 CDA07FBE18E0A16A004699FA /* SystemSleepListener.h in Headers */,
</span><ins>+                                2DF512CE1D873E47001D6780 /* ReplaceRangeWithTextCommand.h in Headers */,
</ins><span class="cx">                                 CDA07FC218E0A22B004699FA /* SystemSleepListenerMac.h in Headers */,
</span><span class="cx">                                 5D5975B319635F1100D00878 /* SystemVersion.h in Headers */,
</span><span class="cx">                                 51E399021D6E4750009C8831 /* GameControllerGamepadProvider.h in Headers */,
</span><span class="lines">@@ -29599,6 +29606,7 @@
</span><span class="cx">                                 CDEA763014608A53008B31F1 /* PlatformClockCA.cpp in Sources */,
</span><span class="cx">                                 CDAA8D0A14D71B2E0061EA60 /* PlatformClockCM.mm in Sources */,
</span><span class="cx">                                 26601EC014B3B9AD0012C0FE /* PlatformEventFactoryIOS.mm in Sources */,
</span><ins>+                                2DF512CD1D873E47001D6780 /* ReplaceRangeWithTextCommand.cpp in Sources */,
</ins><span class="cx">                                 BCAA486F14A052530088FAC4 /* PlatformEventFactoryMac.mm in Sources */,
</span><span class="cx">                                 F544F78815CFB2A800AF33A8 /* PlatformLocale.cpp in Sources */,
</span><span class="cx">                                 070E091B1875EF71003A1D3C /* PlatformMediaSession.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingEditingAllInOnecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/EditingAllInOne.cpp (205869 => 205870)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/EditingAllInOne.cpp        2016-09-13 19:08:30 UTC (rev 205869)
+++ trunk/Source/WebCore/editing/EditingAllInOne.cpp        2016-09-13 19:44:42 UTC (rev 205870)
</span><span class="lines">@@ -60,6 +60,7 @@
</span><span class="cx"> #include &lt;RemoveNodePreservingChildrenCommand.cpp&gt;
</span><span class="cx"> #include &lt;RenderedPosition.cpp&gt;
</span><span class="cx"> #include &lt;ReplaceNodeWithSpanCommand.cpp&gt;
</span><ins>+#include &lt;ReplaceRangeWithTextCommand.cpp&gt;
</ins><span class="cx"> #include &lt;ReplaceSelectionCommand.cpp&gt;
</span><span class="cx"> #include &lt;SetNodeAttributeCommand.cpp&gt;
</span><span class="cx"> #include &lt;SetSelectionCommand.cpp&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingEditorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/Editor.cpp (205869 => 205870)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/Editor.cpp        2016-09-13 19:08:30 UTC (rev 205869)
+++ trunk/Source/WebCore/editing/Editor.cpp        2016-09-13 19:44:42 UTC (rev 205870)
</span><span class="lines">@@ -75,6 +75,7 @@
</span><span class="cx"> #include &quot;RenderTextControl.h&quot;
</span><span class="cx"> #include &quot;RenderedDocumentMarker.h&quot;
</span><span class="cx"> #include &quot;RenderedPosition.h&quot;
</span><ins>+#include &quot;ReplaceRangeWithTextCommand.h&quot;
</ins><span class="cx"> #include &quot;ReplaceSelectionCommand.h&quot;
</span><span class="cx"> #include &quot;Settings.h&quot;
</span><span class="cx"> #include &quot;ShadowRoot.h&quot;
</span><span class="lines">@@ -3616,21 +3617,17 @@
</span><span class="cx">     const VisibleSelection&amp; selection = m_frame.selection().selection();
</span><span class="cx">     return makeRange(startOfParagraph(selection.visibleStart()), endOfParagraph(selection.visibleEnd()));
</span><span class="cx"> }
</span><del>-    
-void Editor::selectTextCheckingResult(const TextCheckingResult&amp; result)
</del><ins>+
+RefPtr&lt;Range&gt; Editor::rangeForTextCheckingResult(const TextCheckingResult&amp; result) const
</ins><span class="cx"> {
</span><span class="cx">     if (!result.length)
</span><del>-        return;
-    
</del><ins>+        return nullptr;
+
</ins><span class="cx">     RefPtr&lt;Range&gt; contextRange = contextRangeForCandidateRequest();
</span><span class="cx">     if (!contextRange)
</span><del>-        return;
-    
-    RefPtr&lt;Range&gt; replacementRange = TextIterator::subrange(contextRange.get(), result.location, result.length);
-    if (!replacementRange)
-        return;
-    
-    m_frame.selection().setSelectedRange(replacementRange.get(), UPSTREAM, true);
</del><ins>+        return nullptr;
+
+    return TextIterator::subrange(contextRange.get(), result.location, result.length);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Editor::handleAcceptedCandidate(TextCheckingResult acceptedCandidate)
</span><span class="lines">@@ -3639,8 +3636,13 @@
</span><span class="cx"> 
</span><span class="cx">     m_isHandlingAcceptedCandidate = true;
</span><span class="cx"> 
</span><del>-    selectTextCheckingResult(acceptedCandidate);
-    insertText(acceptedCandidate.replacement, 0);
</del><ins>+    if (auto range = rangeForTextCheckingResult(acceptedCandidate)) {
+        if (shouldInsertText(acceptedCandidate.replacement, range.get(), EditorInsertActionTyped)) {
+            Ref&lt;ReplaceRangeWithTextCommand&gt; replaceCommand = ReplaceRangeWithTextCommand::create(range.get(), acceptedCandidate.replacement);
+            applyCommand(replaceCommand.ptr());
+        }
+    } else
+        insertText(acceptedCandidate.replacement, nullptr);
</ins><span class="cx"> 
</span><span class="cx">     RefPtr&lt;Range&gt; insertedCandidateRange = rangeExpandedByCharactersInDirectionAtWordBoundary(selection.visibleStart(), acceptedCandidate.replacement.length(), DirectionBackward);
</span><span class="cx">     if (insertedCandidateRange)
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingEditorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/Editor.h (205869 => 205870)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/Editor.h        2016-09-13 19:08:30 UTC (rev 205869)
+++ trunk/Source/WebCore/editing/Editor.h        2016-09-13 19:44:42 UTC (rev 205870)
</span><span class="lines">@@ -467,7 +467,7 @@
</span><span class="cx">     WEBCORE_EXPORT String stringForCandidateRequest() const;
</span><span class="cx">     WEBCORE_EXPORT void handleAcceptedCandidate(TextCheckingResult);
</span><span class="cx">     WEBCORE_EXPORT RefPtr&lt;Range&gt; contextRangeForCandidateRequest() const;
</span><del>-    void selectTextCheckingResult(const TextCheckingResult&amp;);
</del><ins>+    RefPtr&lt;Range&gt; rangeForTextCheckingResult(const TextCheckingResult&amp;) const;
</ins><span class="cx">     bool isHandlingAcceptedCandidate() const { return m_isHandlingAcceptedCandidate; }
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingReplaceRangeWithTextCommandcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/editing/ReplaceRangeWithTextCommand.cpp (0 => 205870)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/ReplaceRangeWithTextCommand.cpp                                (rev 0)
+++ trunk/Source/WebCore/editing/ReplaceRangeWithTextCommand.cpp        2016-09-13 19:44:42 UTC (rev 205870)
</span><span class="lines">@@ -0,0 +1,68 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;ReplaceRangeWithTextCommand.h&quot;
+
+#include &quot;AlternativeTextController.h&quot;
+#include &quot;Document.h&quot;
+#include &quot;DocumentFragment.h&quot;
+#include &quot;Editor.h&quot;
+#include &quot;Frame.h&quot;
+#include &quot;ReplaceSelectionCommand.h&quot;
+#include &quot;SetSelectionCommand.h&quot;
+#include &quot;TextIterator.h&quot;
+#include &quot;markup.h&quot;
+
+namespace WebCore {
+
+ReplaceRangeWithTextCommand::ReplaceRangeWithTextCommand(RefPtr&lt;Range&gt; rangeToBeReplaced, const String&amp; text)
+    : CompositeEditCommand(rangeToBeReplaced-&gt;startContainer().document())
+    , m_rangeToBeReplaced(rangeToBeReplaced)
+    , m_text(text)
+{
+}
+
+void ReplaceRangeWithTextCommand::doApply()
+{
+    VisibleSelection selection = *m_rangeToBeReplaced;
+
+    if (!m_rangeToBeReplaced)
+        return;
+
+    if (!frame().selection().shouldChangeSelection(selection))
+        return;
+
+    String previousText = plainText(m_rangeToBeReplaced.get());
+    if (!previousText.length())
+        return;
+
+    applyCommandToComposite(SetSelectionCommand::create(selection, FrameSelection::defaultSetSelectionOptions()));
+
+    auto fragment = createFragmentFromText(*m_rangeToBeReplaced, m_text);
+    applyCommandToComposite(ReplaceSelectionCommand::create(document(), WTFMove(fragment), ReplaceSelectionCommand::MatchStyle, EditActionPaste));
+}
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCoreeditingReplaceRangeWithTextCommandh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/editing/ReplaceRangeWithTextCommand.h (0 => 205870)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/ReplaceRangeWithTextCommand.h                                (rev 0)
+++ trunk/Source/WebCore/editing/ReplaceRangeWithTextCommand.h        2016-09-13 19:44:42 UTC (rev 205870)
</span><span class="lines">@@ -0,0 +1,48 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include &quot;CompositeEditCommand.h&quot;
+#include &quot;Range.h&quot;
+
+namespace WebCore {
+
+class ReplaceRangeWithTextCommand : public CompositeEditCommand {
+public:
+    static Ref&lt;ReplaceRangeWithTextCommand&gt; create(RefPtr&lt;Range&gt; rangeToBeReplaced, const String&amp; text)
+    {
+        return adoptRef(*new ReplaceRangeWithTextCommand(rangeToBeReplaced, text));
+    }
+
+private:
+    ReplaceRangeWithTextCommand(RefPtr&lt;Range&gt; rangeToBeReplaced, const String&amp; text);
+    void doApply() override;
+
+    RefPtr&lt;Range&gt; m_rangeToBeReplaced;
+    String m_text;
+};
+
+} // namespace WebCore
</ins></span></pre>
</div>
</div>

</body>
</html>