Slide 21
Slide 21 text
macOS native (/6TUFQͱ$PDPUSPO
© 2019 1024jp
(/6TUFQ$PDPUSPOͷ׆༻
ドキュメントとAppleの実装の差異に関して
メモが残ってたりする。
NSTextView_actions.m
/*
TODO: find out what affinity is supposed to mean
My current assumption:
Affinity deals with which direction we are selecting in, ie. which end of
the selected range is the moving end, and which is the anchor.
NSSelectionAffinityUpstream means that the minimum index of the selected
range is moving (ie. _selected_range.location).
NSSelectionAffinityDownstream means that the maximum index of the selected
range is moving (ie. _selected_range.location+_selected_range.length).
Thus, when moving and selecting, we use the affinity to find out which end
of the selected range to move, and after moving, we compare the character
index we moved to with the anchor and set the range and affinity.
The affinity is important when making keyboard selection have sensible
behavior. Example:
If, in the string "abcd", the insertion point is between the "c" and the "d"
(selected range is (3,0)), and the user hits shift-left twice, we select
the "c" and "b" (1,2) and set the affinity to NSSelectionAffinityUpstream.
If the user hits shift-right, only the "c" will be selected (2,1).
If the insertion point is between the "a" and the "b" (1,0) and the user hits
shift-right twice, we again select the "b" and "c" (1,2), but the affinity
is NSSelectionAffinityDownstream. If the user hits shift-right, the "d" is
added to the selection (1,3).
*/
- (unsigned int) _movementOrigin
{
NSRange range = [self selectedRange];