Fix: click a date picker to pick and step a part of the date - #860
Open
DTW-Thalion wants to merge 5 commits into
Open
Fix: click a date picker to pick and step a part of the date#860DTW-Thalion wants to merge 5 commits into
DTW-Thalion wants to merge 5 commits into
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.
A date picker could only be reached with the tab key, and the text field and stepper style drew no stepper. A click takes the keyboard and picks the part of the date under the pointer, so the arrow keys and the digits go to the part that was clicked. The style that asks for a stepper draws one at its trailing edge through the theme, keeps room for it in the cell size and in the text, and a click on its upper or lower half steps the part that is picked. A click that lands on no part is left to NSControl as before. The stepper does not repeat while the button is held.
GCC has no declaration of it in this file and takes the return value for an id, which does not compile.
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 could only be reached with the tab key, and the text field and stepper style drew no stepper.
A click now takes the keyboard and picks the part of the date under the pointer, so the arrow keys and the digits act on the part that was clicked. The style that asks for a stepper draws one at its trailing edge through the theme, keeps room for it in the cell size and in the text it draws, and a click on the upper or lower half of it steps the part that is picked and sends the action. A click that lands on no part is left to NSControl as before.
The stepper does not repeat while the button is held. The clock and calendar style is not part of this. The branch is cut off #859, which is itself cut off #858, and needs both.
Tests/gui/NSDatePicker/mouse.m holds 9 assertions. Before the change the first click reaches NSControl and waits there for a mouse up that a test has no way to send, so the file cannot run at all; after it the 9 assertions pass. Tests/gui runs 4384 assertions green.
Refers to #95