<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>164519</bug_id>
          
          <creation_ts>2016-11-08 10:13:28 -0800</creation_ts>
          <short_desc>Word transformations apply to a single word instead of entire selection if selection is made by triple-clicking</short_desc>
          <delta_ts>2018-07-12 20:21:20 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>HTML Editing</component>
          <version>Other</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=187605</see_also>
          <bug_file_loc>data:text/html,&lt;div%20contenteditable&gt;Triple-click%20this%20sentence,%20then%20control-click%20and%20choose%20Transformations%20&amp;gt;%20Make%20Upper%20Case</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>mitz</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>darin</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1249077</commentid>
    <comment_count>0</comment_count>
    <who name="">mitz</who>
    <bug_when>2016-11-08 10:13:28 -0800</bug_when>
    <thetext>&lt;rdar://problem/27487147&gt;

To reproduce:
Navigate to the URL, triple-click the sentence to select it, then control-click and choose Transformations &gt; Make Upper Case

Result:
Only the word in which the control-click occurred is transformed and stays selected

Note:
The implementation of word transformations begins with performing the SelectWord command. The intent is to expand the selection to encompass whole words (that’s how the command behaves in NSTextView). When made with a triple-click, the selection’s base and extent are the same (the position of the click). It then expands to a word around that position. This happens in the VisibleSelection::setStartAndEndFromBaseAndExtentRespectingGranularity call from VisibleSelection::validate. It seems like we need a different code path for expanding to a desired granularity.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1250845</commentid>
    <comment_count>1</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2016-11-13 11:26:57 -0800</bug_when>
    <thetext>The function VisibleSelection::expandUsingGranularity exists; is that relevant?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1250846</commentid>
    <comment_count>2</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2016-11-13 11:27:11 -0800</bug_when>
    <thetext>And SelectionController::expandUsingGranularity.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1250853</commentid>
    <comment_count>3</comment_count>
    <who name="">mitz</who>
    <bug_when>2016-11-13 11:36:18 -0800</bug_when>
    <thetext>(In reply to comment #1)
&gt; The function VisibleSelection::expandUsingGranularity exists; is that
&gt; relevant?

Yes, VisibleSelection::expandUsingGranularity is the one calling VisibleSelection::validate in this case. Here’s the call stack:

WebCore::VisibleSelection::setStartAndEndFromBaseAndExtentRespectingGranularity(WebCore::TextGranularity) at Source/WebCore/editing/VisibleSelection.cpp:272
WebCore::VisibleSelection::validate(WebCore::TextGranularity) at Source/WebCore/editing/VisibleSelection.cpp:422
WebCore::VisibleSelection::expandUsingGranularity(WebCore::TextGranularity) at Source/WebCore/editing/VisibleSelection.cpp:198
WebCore::expandSelectionToGranularity(WebCore::Frame&amp;, WebCore::TextGranularity) at Source/WebCore/editing/EditorCommand.cpp:177
WebCore::executeSelectWord(WebCore::Frame&amp;, WebCore::Event*, WebCore::EditorCommandSource, WTF::String const&amp;) at Source/WebCore/editing/EditorCommand.cpp:1015
WebCore::Editor::Command::execute(WTF::String const&amp;, WebCore::Event*) const at Source/WebCore/editing/EditorCommand.cpp:1777
::-[WebHTMLView executeCoreCommandBySelector:](SEL) at Source/WebKit/mac/WebView/WebHTMLView.mm:2954
::-[WebHTMLView selectWord:](id) at Source/WebKit/mac/WebView/WebHTMLView.mm:3056
::-[WebHTMLView _changeWordCaseWithSelector:](SEL) at Source/WebKit/mac/WebView/WebHTMLView.mm:5824
::-[WebHTMLView uppercaseWord:](id) at Source/WebKit/mac/WebView/WebHTMLView.mm:5835

(In reply to comment #2)
&gt; And SelectionController::expandUsingGranularity.

I don’t see that one in TOT.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1250855</commentid>
    <comment_count>4</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2016-11-13 11:45:25 -0800</bug_when>
    <thetext>So I guess you are saying that this is a bug in WebCore::expandSelectionToGranularity/VisibleSelection::expandUsingGranularity.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1250858</commentid>
    <comment_count>5</comment_count>
    <who name="">mitz</who>
    <bug_when>2016-11-13 11:51:12 -0800</bug_when>
    <thetext>(In reply to comment #4)
&gt; So I guess you are saying that this is a bug in
&gt; WebCore::expandSelectionToGranularity/VisibleSelection::
&gt; expandUsingGranularity.

I am saying that those functions’ behavior doesn’t meet the requirements of word transformations. I don’t know how changing their behavior so that they never contract the selection will affect other uses. I also don’t know exactly how to do that. I tried, naively, to make VisibleSelection::expandUsingGranularity set the base and the extent to the start and end before calling validate, and then restore them, but that wasn’t quite right: it produced word selections that included the trailing space after the word.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1250882</commentid>
    <comment_count>6</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2016-11-13 16:53:10 -0800</bug_when>
    <thetext>I think the trick is to make test cases first that express the behavior we want. I don’t think it will be terribly difficult to get the implementation right.

Certainly the name &quot;expand selection to granularity&quot; implies the behavior of never contracting selections, so if we need different behavior for some purposes, those should be in functions with different names!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1250884</commentid>
    <comment_count>7</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2016-11-13 16:56:32 -0800</bug_when>
    <thetext>All those special cases in the WordGranularity section of setStartAndEndFromBaseAndExtentRespectingGranularity are probably the source of the difficulty with the trailing space after the word.

You mentioned setting the base and extent to the start and end before calling validate. Was the code you tried respecting m_baseIsFirst?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1250885</commentid>
    <comment_count>8</comment_count>
    <who name="">mitz</who>
    <bug_when>2016-11-13 16:59:49 -0800</bug_when>
    <thetext>(In reply to comment #7)
&gt; All those special cases in the WordGranularity section of
&gt; setStartAndEndFromBaseAndExtentRespectingGranularity are probably the source
&gt; of the difficulty with the trailing space after the word.
&gt; 
&gt; You mentioned setting the base and extent to the start and end before
&gt; calling validate. Was the code you tried respecting m_baseIsFirst?

Yes, it was naïve but not that naïve. I will take a deeper look and try to understand what’s going on.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1250886</commentid>
    <comment_count>9</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2016-11-13 17:03:26 -0800</bug_when>
    <thetext>Perhaps we should change things so the granularity is recorded alongside m_start and m_end. Then a call to expandUsingGranularity targeting any smaller granularity would automatically be a no-op.

This would not work for line vs. sentence granularity, but should work fine for character, word, sentence/line, paragraph, document.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>