Closed Bug 75676 Opened 24 years ago Closed 24 years ago

textField.textLength() is broken

Categories

(Core :: Layout, defect)

All
Mac System 8.5
defect
Not set
normal

Tracking

()

VERIFIED FIXED
mozilla0.9

People

(Reporter: sfraser_bugs, Assigned: sfraser_bugs)

References

()

Details

Attachments

(3 files)

The textLength attribute on text fields is broken; it always returns the length of the initial value, even after editing. This is because it erroneously always returns the length of the cached value (see nsGfxTextControlFrame2::GetTextLength()).
Attached patch nsGfxTextControlFrame2 fix (deleted) — Splinter Review
Attached patch Correct patch this time (deleted) — Splinter Review
The fix is to expose a InvalidateCachedState() method from nsGfxTextControlFrame2, which is called by nsTextInputListener's NotifySelectionChanged method. This means that any edit will invalidate the cached value (as will moving the caret). This ensures that later calls to GetTextLength() do the right thing. In future I think we need to do better value caching here, to avoid expensive calls to the output system. We should probably hook up a transaction listener or something, rather than using selection changed. See the URL for a testcase. Looking for r=(anthonyd, mjudge) and sr=(kin)
Status: NEW → ASSIGNED
Target Milestone: --- → mozilla0.9
Attached patch Better fix (deleted) — Splinter Review
The 3rd attachment contains a better fix. Rather than invalidate the cached state on every selectin change, we do it when the nsTextInputListener tells us that the content changed. I'll remove the commented out code in nsTextInputListener::NotifySelectionChanged().
Fix checked in (i'll get a posthumous r=mjudge).
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
Marking verified per last comments.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: