<?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>4681</bug_id>
          
          <creation_ts>2005-08-26 23:20:19 -0700</creation_ts>
          <short_desc>-[WebHTMLView insertText:] needs to support NSTextInputReplacementRangeAttributeName</short_desc>
          <delta_ts>2007-07-01 22:28:47 -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>420+</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>OS X 10.4</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>13664</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Evan Gross">evan</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>ian</cc>
    
    <cc>oliver</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>17735</commentid>
    <comment_count>0</comment_count>
    <who name="Evan Gross">evan</who>
    <bug_when>2005-08-26 23:20:19 -0700</bug_when>
    <thetext>The current comment in -insertText reads:

// we don&apos;t yet support inserting an attributed string but input methods
// don&apos;t appear to require this.

This is not true. In order for kEventClassTextInput/kEventTextInputUpdateActiveInputArea events that 
specify the kEventParamTextInputSendReplaceRange parameter, the &quot;hidden&quot; 
NSTextInputReplacementRangeAttributeName attribute must be extracted and used.

Seems like a simple change to select that range before calling _insertText basically does the trick. There 
are some issues with space runs (a separate problem), so there may be a better way. But the following 
is a big improvement:

- (void)insertText:(id)string
{
    NSString *text;
    if ([string isKindOfClass:[NSAttributedString class]]) {
	text = [string string];
        // we need to support the attribute:NSTextInputReplacementRangeAttributeName if it exists.
        // The AppKit adds a &apos;secret&apos; property to the string that contains the replacement
        // range.  The replacement range is the range of the text that should be replaced
        // with the new string.
        NSString *rangeString = [string attribute:NSTextInputReplacementRangeAttributeName atIndex:0 
longestEffectiveRange:NULL inRange:NSMakeRange(0, [text length])];
        if (rangeString) {
            [[self _bridge] selectNSRange:NSRangeFromString(rangeString)];
        }
    } else {
	text = string;
    }

    [self _insertText:text selectInsertedText:NO];
}

Again, probably not enough error checking, and instead of calling _insertText some sort of string 
replacement method should be called instead.

But this alone improves things with my input method. Kotoeri also uses this event, if I&apos;m not mistaken. I 
filed a radar on this one long, long ago...

(Note I&apos;ve edited the comment to read &quot;the&quot; instead of &quot;the the&quot; - this comment was copied and pasted 
from -setMarkedText:selectedRange).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>19447</commentid>
    <comment_count>1</comment_count>
      <attachid>3874</attachid>
    <who name="Evan Gross">evan</who>
    <bug_when>2005-09-12 01:36:19 -0700</bug_when>
    <thetext>Created attachment 3874
proposed patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20713</commentid>
    <comment_count>2</comment_count>
    <who name="Maciej Stachowiak">mjs</who>
    <bug_when>2005-09-27 23:38:46 -0700</bug_when>
    <thetext>Sounds like a good patch, but how to test this? What steps with what input method will demonstrate it?
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20716</commentid>
    <comment_count>3</comment_count>
      <attachid>3874</attachid>
    <who name="Maciej Stachowiak">mjs</who>
    <bug_when>2005-09-28 00:56:53 -0700</bug_when>
    <thetext>Comment on attachment 3874
proposed patch

The patch looks good but r- for lack of test case or even steps to reproduce.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20717</commentid>
    <comment_count>4</comment_count>
    <who name="Evan Gross">evan</who>
    <bug_when>2005-09-28 01:04:09 -0700</bug_when>
    <thetext>Indeed, not too many input methods use this.

Here&apos;s how to reproduce the problem and verify the fix:

Download Spell Catcher X (my product, the one input method I know that uses this - though I think 
Kotoeri might as well):

&lt;http://www.rainmakerinc.com/downloads/&gt;

Install it, run it in trial mode.

Test with whatever app you like - I use Blot, use Safari with contenteditable, or even try with Mail on 
Tiger.

The critical setting: In Spell Catcher Preferences, Interactive pane, Typing tab, the &quot;Make replacements 
directly...&quot; checkbox controls whether UAIA is called with a replacement range (no backspacing) or not 
(backspaces over the error/shorthand abbreviation).

Run with that checkbox on (the default).
Activate Spell Catcher&apos;s input method.
Type a word that will automatically get corrected - like &quot;teh&quot; or &quot;recieve&quot; (US English, anyway)
Try with the shipping WebKit. See that there are remnants of the word you type.
Try with a WebKit built with this patch. See that it works (no remnants, no backspacing).
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20852</commentid>
    <comment_count>5</comment_count>
      <attachid>3874</attachid>
    <who name="Maciej Stachowiak">mjs</who>
    <bug_when>2005-09-28 14:08:04 -0700</bug_when>
    <thetext>Comment on attachment 3874
proposed patch

Putting back in review? since steps to reproduce are now provided</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20977</commentid>
    <comment_count>6</comment_count>
      <attachid>3874</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2005-09-30 07:45:34 -0700</bug_when>
    <thetext>Comment on attachment 3874
proposed patch

This patch doesn&apos;t really match the title of this bug. It&apos;s great to support
NSTextInputReplacementRangeAttributeName, but is that really &quot;supporting
inserting attributed strings&quot;? Another way to ask this is: &quot;Is this the only
attribute we need to support here?&quot; Was this bug originally filed specifically
just for the replacement range attribute or are there other pending issues?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>21044</commentid>
    <comment_count>7</comment_count>
    <who name="Evan Gross">evan</who>
    <bug_when>2005-09-30 17:59:03 -0700</bug_when>
    <thetext>You&apos;re quite right, the title of the bug more closely matches the comment that was intially in the code - 
as it say&apos;s inserting attributed strings isn&apos;t supported because input methods don&apos;t require it.

So sure, the basics are that the NSTextInputReplacementRangeAttributeName attribute needs to be 
supported. Other attributes, I honestly have no idea. Not sure if any of the TSM Glyph Access stuff 
might funnel through here - my input method doesn&apos;t use it. I think that the Character Palette may 
(insert with font), but haven&apos;t tested that a whole lot. I may well take a look, though.

And YES, there&apos;s no way my proposed patch is good enough. It&apos;s a proof that there is a way to get UAIA 
with kEventParamTextInputSendReplaceRange working in WebView.

There ARE other issues (as stated in my original comment) related to the way space runs are dealt with. 
That&apos;s a more general -insertText issue - I have a radar on that filed, and suppose I need to report it 
here. I&apos;ll need help on that one, as the whole deal with WebView and spaces/option spaces/space runs 
is a bit mysterious to me.

To correctly fix this one, I need a bit of help as well. PROPERLY implemented, if there&apos;s a replacement 
range, the behavior should be the same as how TextEdit&apos;s &quot;Paste and Match Style&quot; command works. I 
haven&apos;t done enough testing to see whether this patch behaves that way already. I suspect it doesn&apos;t. 
The key idea is that replacing a word that&apos;s (say) bold should leave you with a bold replacement.

Additionally, we have to make sure that we don&apos;t behave like NSTextView in one way - it will scroll the 
selection into view regardless of the replacement range. That&apos;s bad, it should be possible to replace any 
arbitrary range, independent of the current selection or insertion point, without any such side-effects.

I&apos;ll be taking another look at this in the next day or so, and I&apos;ll write up the other issue that insertText 
has in general with text that contains space runs (easy to see for yourself if you do some testing with 
Spell Catcher X, or even TypeIt4Me - don&apos;t think any of Apple&apos;s input methods will do the trick here).
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>21215</commentid>
    <comment_count>8</comment_count>
      <attachid>3874</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2005-10-02 20:53:52 -0700</bug_when>
    <thetext>Comment on attachment 3874
proposed patch

OK, lets work on a version of this that gets as many as possible of the fine
points Evan mentions working.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5824</commentid>
    <comment_count>9</comment_count>
    <who name="Oliver Hunt">oliver</who>
    <bug_when>2007-06-30 17:32:59 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of 13664 ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5799</commentid>
    <comment_count>10</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2007-06-30 23:52:34 -0700</bug_when>
    <thetext>Although fixing this issue would hide the symptoms of bug 13664, they are not duplicates (see bug 13664 comment 19).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5784</commentid>
    <comment_count>11</comment_count>
    <who name="Oliver Hunt">oliver</who>
    <bug_when>2007-07-01 15:20:15 -0700</bug_when>
    <thetext>No, this is a duplicate.  The problems seen in 13364 are very blatantly due to us not correctly handling the case where we&apos;ve been given a replacement range.  That is the bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5754</commentid>
    <comment_count>12</comment_count>
    <who name="Oliver Hunt">oliver</who>
    <bug_when>2007-07-01 22:28:14 -0700</bug_when>
    <thetext>Whoops, should be resolved duplicate</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5755</commentid>
    <comment_count>13</comment_count>
    <who name="Oliver Hunt">oliver</who>
    <bug_when>2007-07-01 22:28:47 -0700</bug_when>
    <thetext>re-duplicating

*** This bug has been marked as a duplicate of 13664 ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>3874</attachid>
            <date>2005-09-12 01:36:19 -0700</date>
            <delta_ts>2005-10-02 20:53:52 -0700</delta_ts>
            <desc>proposed patch</desc>
            <filename>insertText.txt</filename>
            <type>text/plain</type>
            <size>1431</size>
            <attacher name="Evan Gross">evan</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYkhUTUxWaWV3Lm0KPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQpSQ1MgZmlsZTogL2N2cy9yb290L1dlYktp
dC9XZWJWaWV3LnN1YnByb2ovV2ViSFRNTFZpZXcubSx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yBwcm9wZXJ0eSB0byB0aGUgc3RyaW5nIHRoYXQgY29udGFpbnMg
dGhlIHJlcGxhY2VtZW50CisgICAgICAgIC8vIHJhbmdlLiAgVGhlIHJlcGxhY2VtZW50IHJhbmdl
IGlzIHRoZSByYW5nZSBvZiB0aGUgdGV4dCB0aGF0IHNob3VsZCBiZSByZXBsYWNlZAorICAgICAg
ICAvLyB3aXRoIHRoZSBuZXcgc3RyaW5nLgorICAgICAgICBOU1N0cmluZyAqcmFuZ2VTdHJpbmcg
PSBbc3RyaW5nIGF0dHJpYnV0ZTpOU1RleHRJbnB1dFJlcGxhY2VtZW50UmFuZ2VBdHRyaWJ1dGVO
YW1lIGF0SW5kZXg6MCBsb25nZXN0RWZmZWN0aXZlUmFuZ2U6TlVMTCBpblJhbmdlOk5TTWFrZVJh
bmdlKDAsIFt0ZXh0IGxlbmd0aF0pXTsKKyAgICAgICAgaWYgKHJhbmdlU3RyaW5nKSB7CisgICAg
ICAgICAgICBbW3NlbGYgX2JyaWRnZV0gc2VsZWN0TlNSYW5nZTpOU1JhbmdlRnJvbVN0cmluZyhy
YW5nZVN0cmluZyldOworICAgICAgICB9CiAgICAgfSBlbHNlIHsKIAl0ZXh0ID0gc3RyaW5nOwog
ICAgIH0K
</data>
<flag name="review"
          id="631"
          type_id="1"
          status="-"
          setter="darin"
    />
          </attachment>
      

    </bug>

</bugzilla>