Bug 18794 - -[WebHTMLView attributedSubstringFromRange:] result offset by one character
Summary: -[WebHTMLView attributedSubstringFromRange:] result offset by one character
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Nobody
URL: http://www.spikesoft.net/
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2008-04-28 17:41 PDT by Nicholas Riley
Modified: 2008-09-13 08:25 PDT (History)
2 users (show)

See Also:


Attachments
test application (Xcode project) (57.14 KB, application/zip)
2008-04-28 17:42 PDT, Nicholas Riley
no flags Details
minimized test case (326 bytes, text/html)
2008-04-28 17:42 PDT, Nicholas Riley
no flags Details
test application (Xcode 2.4 project) (64.73 KB, application/zip)
2008-05-15 02:20 PDT, Nicholas Riley
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nicholas Riley 2008-04-28 17:41:38 PDT
In a simple HTML document containing a comment before the HTML element and nested tables, when I select a substring and invoke -[WebHTMLView attributedSubstringFromRange:] I get a result which is offset by one character. 

Compile and run the attached test application (WebKitTest) then click the Test button.  It does the following (v is an editable WebView *):

    [v moveToBeginningOfDocument: nil];
    [v moveDown: nil];
    [v selectWord: nil];
    NSResponder<NSTextInput> *ti = [[self window] firstResponder]; // WebHTMLView
    NSLog(@"firstResponder %@ selectedRange %@", ti, NSStringFromRange([ti selectedRange]));
    NSLog(@"selected string: |%@|", [[ti attributedSubstringFromRange: [ti selectedRange]] string]);

You'll see the first word ("selection") selected, and the range appears OK, but the output is:

2008-04-28 19:31:59.795 WebKitTest[55407:10b] firstResponder <WebHTMLView: 0x156a7c0> selectedRange {0, 9}
2008-04-28 19:31:59.797 WebKitTest[55407:10b] selected string: | selectio|

The HTML file is attached separately for reference.  If I remove the comment or one of the nested tables, the problem goes away; however, if I add text below the tables, it exhibits the problem as well.

This problem was isolated from the spikesoft URL, which is a HTML disaster; the attached minimized version validates, however.
Comment 1 Nicholas Riley 2008-04-28 17:42:30 PDT
Created attachment 20879 [details]
test application (Xcode project)
Comment 2 Nicholas Riley 2008-04-28 17:42:57 PDT
Created attachment 20880 [details]
minimized test case
Comment 3 Alexey Proskuryakov 2008-05-05 11:54:11 PDT
Tentatively confirming, although I couldn't actually verify this - Xcode 3.0 says that the project was saved with a newer version, and then fails to build id. But this sounds as a typical attributedSubstringFromRange bug.
Comment 4 Nicholas Riley 2008-05-15 02:19:18 PDT
Sorry about that; I've resaved the nib and project file in older formats and will attach them.  I tested building on Tiger with Xcode 2.4.1, so it should work with that or later versions.

Searching for attributedSubstringFromRange and following the trail of bugs I'm led to #5610 which hasn't been touched in 2.5 years.  Is there a reason you haven't updated your patch after it was reviewed?  Should I start with that patch, or is there other ongoing work I could potentially help with, if I want to see this bug fixed sooner rather than later?

Thanks.
Comment 5 Nicholas Riley 2008-05-15 02:20:40 PDT
Created attachment 21156 [details]
test application (Xcode 2.4 project)
Comment 6 Alexey Proskuryakov 2008-05-15 03:38:49 PDT
The only reason is that it's hard - and often unclear what behavior would be correct, particularly when rendered text is significantly different than DOM (e.g. because of CSS transformations).

There is no ongoing work in this area, as far as I know. There's a related patch in bug 15680 that should probably be landed though.
Comment 7 Nicholas Riley 2008-05-15 04:14:52 PDT
(In reply to comment #6)
> The only reason is that it's hard - and often unclear what behavior would be
> correct, particularly when rendered text is significantly different than DOM
> (e.g. because of CSS transformations).

Yeah, I see how that could be painful.

A few of the offset-selection or extraneous-newline cases I've noticed so far seem to be relatively straightforward with no CSS or script-generated content involved.  I have a list of other URLs to investigate (some have regressed since Safari 3.1.1, such as http://blog.michaeltrier.com/, although that one goes away when I disable CSS) but haven't tried to minimize any of them because I wanted to see what happened with this bug.

Should I try to compile WebKit with the patch in bug 15680, and go from there? What information, code, test cases, etc. will help? I'm obviously not going to turn into a WebKit expert overnight but am certainly willing to invest some time into it.
Comment 8 Alexey Proskuryakov 2008-05-15 07:22:18 PDT
I've just landed the patch from bug 15680, it actually fixes some cases of  extraneous newline.

Feel free to discuss the issues you'd like to work on IRC or on webkit-dev@lists.webkit.org mailing list to keep this bug for comments about the specific issue at hand here.
Comment 9 Graham Perrin 2008-05-22 19:03:26 PDT
The description here, 'offset by one character' reminds me of

'Kupu 1.4.9: style application problems (most evident with the first letter of heading levels) in Safari 3.1.1 on Mac OS X 10.5.2 '
http://dev.plone.org/plone/ticket/8085

https://dev.plone.org/plone/attachment/ticket/8085/obvious%20problem%20with%20HTML%20%28before%20switching%20to%20HTML%20view%29.png demonstrates the symptoms; focus on the first letter of the words 'Background' and 'Outcomes'.

If this WebKit bug 18794 is an explanation for http://dev.plone.org/plone/ticket/8085 then it will affect users of Kupu in a very annoying way, in which case I should plead for escalation. 

Thanks
Graham
Comment 10 Alexey Proskuryakov 2008-07-28 01:49:37 PDT
<rdar://problem/6105526>
Comment 11 Graham Perrin 2008-09-12 07:26:41 PDT
Please, can you offer a progress report on this bug 18794
and/or on  <rdar://problem/6105526>?

Thanks
Graham

(I'm preparing to arrange Plone training for groups within our Centre, to include use of Kupu in Safari, and would like the experience to appear as professional as possible.)

(For myself alone, I have a Safari 4 developer preview but have refrained from installing it.)
Comment 12 Alexey Proskuryakov 2008-09-13 08:25:56 PDT
The whole history of this bug is in the above comments, there is no additional information. Help with fixing it would be welcome.