Closed Bug 394688 Opened 17 years ago Closed 17 years ago

setCaretOffset() is off by one character (should be 0-indexed?)

Categories

(Core :: Disability Access APIs, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: jdiggs, Assigned: aaronlev)

References

(Blocks 1 open bug)

Details

(Keywords: access)

Attachments

(2 files, 2 obsolete files)

Steps to reproduce:

1. Launch Accerciser and highlight the document frame of the attached test case.

2. Type the following in the iPython Console:

    text = acc.queryText()
    text.setCaretOffset(3)
    text.caretOffset

Expected results:  3 would be returned

Actual results:  2 is returned

Notes:

1. Looking at the position of the caret on screen, 2 is the correct offset as offsets are 0-indexed.  It seems that it's setCaretOffset() that is off by one.  

2. This was introduced in Gecko/2007080404; in 2007080308 the offsets match.
That's when we checked in bug 348901, so maybe we're forgetting to convert from hypertext offsets internal source offsets. Internally we need to convert it to a source offset before we use it.
Wait, so are we setting the correct caret position but returning the wrong offset?
Nope, just the opposite.  You're returning the correct offset. setCaretOffset(x) is currently setting the offset to x-1 instead of x.
Are the results affected by source whitespace?
As a matter of fact, they are.  :-) I added additional whitespace in the source and the results changed.  It's not a 1-to-1 correspondence, but it's definitely related.  I should have known/guessed that. :-)
Attached patch First attempt -- needs testing (obsolete) — Splinter Review
Joanie, this patch works for me with that change I mentioned. I think because you build statically you have to rebuild more than mozilla/accessible -- maybe in mozilla/browser as well. I'm not sure.
Attached patch WIP -- don't test this yet (obsolete) — Splinter Review
Attached patch Patch for reviewSplinter Review
Attachment #279541 - Attachment is obsolete: true
Attachment #279734 - Attachment is obsolete: true
Attachment #279738 - Flags: review?(surkov.alexander)
Setting the caret to -1 will be taken care of in a different bug.
Attachment #279738 - Flags: review?(surkov.alexander) → review?(david.bolter)
Please ignore the first hunk in the diff of nsHyperTextAccessible.cpp, because it was going to help deal with setting the caret to -1. I'm going to work on that separately as I said.
Comment on attachment 279738 [details] [diff] [review]
Patch for review

Looks good (except for the GetCharacterCount hunk we discussed on IRC)
Attachment #279738 - Flags: review?(david.bolter) → review+
Attachment #279738 - Flags: approval1.9?
Attachment #279738 - Flags: approval1.9? → approval1.9+
Status: NEW → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: