Closed Bug 237585 Opened 21 years ago Closed 19 years ago

backspace/delete in editor don't handle Unicode plane 1 characters correctly (UTF-16 surrogate pairs)

Categories

(Core :: DOM: Editor, defect, P2)

x86
Linux
defect

Tracking

()

RESOLVED FIXED
Future

People

(Reporter: dbaron, Assigned: dbaron)

References

Details

(Whiteboard: [patch])

Attachments

(2 files, 2 obsolete files)

[This comment is in UTF-8.] Backspace and delete in the editor (or in text inputs at least, but I assume it's a general problem) don't handle Unicode characters outside of plane 0 (the BMP, U+0000 to U+FFFF) correctly. What appears to be happening is that they treat the two surrogates as separate characters, and a single backspace or delete only deletes one of the surrogates rather than the whole character. (Note to the uninformed: UTF-16 encodes characters in the range U+10000 to U+10FFFF using two 16-bit values, a high surrogate (in the range U+D800 to U+DBFF) followed by a low surrogate (in the range U+DC00 to U+DFFF).) It's worth noting that selection seems to handle non-BMP characters fine. The attached testcase contains a text input with the string "a
Attached file testcase described in comment 0 (deleted) —
I think the place to fix this is probably somewhere around the 4 calls to CreateTxnForDeleteText in nsEditor::CreateTxnForDeleteInsertionPoint .
(Although I wonder why there need to be two separate implementations -- why can't backspace and delete when the selection is collapsed be implemented by extending the selection and then deleting it?)
Attached patch patch (obsolete) (deleted) — Splinter Review
This works, but I need to go over the error-handling and make sure it's correct, and also test in a debug build.
*** Bug 173541 has been marked as a duplicate of this bug. ***
Assignee: mozeditor → dbaron
Priority: -- → P2
Whiteboard: [patch]
Target Milestone: --- → mozilla1.8alpha
Comment on attachment 144151 [details] [diff] [review] patch So, I don't remember what error handling issue I wanted to look at, and it seems fine in a debug build, so requesting review.
Attachment #144151 - Flags: review?(daniel)
Attachment #144151 - Flags: superreview?(sfraser_bugs)
Attachment #144151 - Flags: review?(jshin1987)
Attachment #144151 - Flags: review?(daniel)
Attachment #144151 - Flags: review?(jshin1987) → review?(smontagu)
Attachment #144151 - Attachment description: patch (work in progress) → patch
Target Milestone: mozilla1.8alpha1 → mozilla1.8beta2
Comment on attachment 144151 [details] [diff] [review] patch This doesn't work correctly when deleting the last character in the testfield with delete. i.e. in the testcase I delete the last character, and then place the caret before the Deseret character and press delete. It also doesn't seem to work at all in HTML editing.
Attachment #144151 - Flags: review?(smontagu) → review-
(In reply to comment #7) > (From update of attachment 144151 [details] [diff] [review] [edit]) > This doesn't work correctly when deleting the last character in the testfield > with delete. i.e. in the testcase I delete the last character, and then place > the caret before the Deseret character and press delete. > > It also doesn't seem to work at all in HTML editing. > Confirmed both of these. Whenever a plane 1 character is last in line, backspace works but delete leaves a lone surrogate behind. In gmail you can easily choose plain text or rich text. Rich text delete and backspace both leave surrogates behind, but plain text works (except for the last character). Shavian characters after hitting delete on the last one in the line:
Attached patch patch (obsolete) (deleted) — Splinter Review
This should fix the delete-at-last-character bug (I haven't tested it yet, but it was a pretty obvious mistake in the patch). I'm no longer interested enough in this bug to figure out where the relevant HTML editing codepath is. If you'd prefer that the patch doesn't land without HTML editing fixed as well, please reassign the bug to nobody@mozilla.org .
Attachment #144151 - Attachment is obsolete: true
Attachment #187136 - Flags: review?(smontagu)
Attachment #144151 - Flags: superreview?(sfraser_bugs)
I'd like to see this fixed for html editing as well. Otherwise it's not totally fixed. I could investigate it myself, but I'm not all up on C++ or Mozilla coding. Can anyone grab this?
Target Milestone: mozilla1.8beta2 → Future
Comment on attachment 187136 [details] [diff] [review] patch r=smontagu. HTML editing can be a separate bug.
Attachment #187136 - Flags: review?(smontagu) → review+
Attachment #187136 - Flags: superreview?(roc)
Comment on attachment 187136 [details] [diff] [review] patch Can you change your &0xFC00 magic to use IS_HIGH_SURROGATE/IS_LOW_SURROGATE? Other than that it looks fine
Attachment #187136 - Flags: superreview?(roc) → superreview+
Attached patch patch (deleted) — Splinter Review
Attachment #187136 - Attachment is obsolete: true
Fix checked in to trunk. Filed bug 332636 for HTML, and also filed bug 332635.
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
*** Bug 346482 has been marked as a duplicate of this bug. ***
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: