Fix: edit a date picker from the keyboard - #859
Open
DTW-Thalion wants to merge 3 commits into
Open
Conversation
NSDatePickerCell gave its formatter no format, so the cell had nothing to draw from and fell back to the description of the date object. The picker showed a full date and time whatever its datePickerElements were, in the local time zone rather than the one it was set to, and in a form no locale writes. Build the format from the elements. Each element contributes a letter to a template, and the pattern generator returns the pattern that locale writes those elements in; a build without ICU has no generator and gets a fixed order instead. The format is rebuilt whenever the elements or the locale change. NSCell keeps the text its formatter made at the time the value was set, and -[NSDateFormatter stringForObjectValue:] builds that text from a %-style format rather than from the pattern, so take -stringValue from -stringFromDate: instead. A cell decoded without a formatter gets one, as a cell built in code does.
A date picker took no keys at all, so the date it held could only be changed in code. The pattern the cell shows is split into the parts the locale writes. The left and right arrow keys move between those parts, the up and down arrow keys step the part they are on, and a digit types into it. A step is a step of the calendar, so it carries into the parts above it, a day the next month is too short for moves back to that month's last day, and the result stays inside the minimum and maximum dates. A digit joins the digits already typed while the number they make can still grow, and is taken on its own once it cannot. The part being edited is drawn the way selected text is, while the picker holds the keyboard of a key window. An edit sends the action of the control. The delegate is asked to validate the proposed date, both for an edit and for a date set in code, and the date it hands back is the one the picker takes. NSDatePickerCell holds three more ivars, for the part being edited and for the digits typed into it.
This was referenced Jul 29, 2026
START_SET creates an autorelease pool and END_SET releases it, so the pool these tests create around the set is redundant.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A date picker took no keys at all, so the date it held could only be changed in code.
The pattern the cell shows is split into the parts the locale writes. The left and right arrow keys move between those parts, the up and down arrow keys step the part they are on, and a digit types into it. A step is a step of the calendar, so it carries into the parts above it, a day the next month is too short for moves back to that month's last day, and the result stays inside the minimum and maximum dates. The part being edited is drawn the way selected text is while the picker holds the keyboard. An edit sends the action of the control, and the delegate is asked to validate the proposed date. The values are those AppKit produces for the same keys.
NSDatePickerCell holds three more ivars. Clicking a part, the stepper, and the clock and calendar style are not part of this. The branch is cut off #858 and needs it.
Tests/gui/NSDatePicker/keyboard.m and selection.m: 24 assertions fail before the change and 0 after, 77 green across the two picker directories.
Refers to #95