mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-11 11:07:07 +00:00
selection fixes
This commit is contained in:
1 parent
dbc7808c70
commit
7b8249442d
1 file changed
+22
-18
@@ -1800,26 +1800,27 @@ var kDelegateRespondsTo_textShouldBeginEditing
|
||||
}
|
||||
|
||||
- (CPRange)_characterRangeForIndex:(unsigned)index inRange:(CPRange) aRange asDefinedByRegex:(JSObject)regex
|
||||
{
|
||||
return [self _characterRangeForIndex:index inRange:aRange asDefinedByLRegex:regex andRRegex:regex]
|
||||
}
|
||||
|
||||
- (CPRange)_characterRangeForIndex:(unsigned)index inRange:(CPRange) aRange asDefinedByLRegex:(JSObject)lregex andRRegex:(JSObject)rregex
|
||||
{
|
||||
var wordRange = CPMakeRange(index, 0),
|
||||
numberOfCharacters = [_layoutManager numberOfCharacters],
|
||||
string = [_textStorage string];
|
||||
|
||||
if (regex.exec(_characterTripletFromStringAtIndex([_textStorage string], index)) !== null)
|
||||
{
|
||||
// -> extend to the left
|
||||
for (var searchIndex = index - 1; searchIndex >= 0 && regex.exec(_characterTripletFromStringAtIndex(string, searchIndex)) !== null; searchIndex--)
|
||||
wordRange.location = searchIndex;
|
||||
// extend to the left
|
||||
for (var searchIndex = index - 1; searchIndex >= 0 && _regexMatchesStringAtIndex(lregex, string, searchIndex); searchIndex--)
|
||||
wordRange.location = searchIndex;
|
||||
|
||||
// -> extend to the right
|
||||
searchIndex = index + 1;
|
||||
// extend to the right
|
||||
searchIndex = index + 1;
|
||||
|
||||
while (searchIndex < numberOfCharacters && regex.exec(_characterTripletFromStringAtIndex(string, searchIndex)) !== null)
|
||||
searchIndex++;
|
||||
while (searchIndex < numberOfCharacters && _regexMatchesStringAtIndex(rregex, string, searchIndex))
|
||||
searchIndex++;
|
||||
|
||||
return _MakeRangeFromAbs(wordRange.location, MIN(MAX(0, numberOfCharacters - 1), searchIndex));
|
||||
}
|
||||
return _MakeRangeFromAbs(wordRange.location, MIN(MAX(0, numberOfCharacters), index));
|
||||
return _MakeRangeFromAbs(wordRange.location, MIN(MAX(0, numberOfCharacters), searchIndex));
|
||||
}
|
||||
|
||||
- (CPRange)selectionRangeForProposedRange:(CPRange)proposedRange granularity:(CPSelectionGranularity)granularity
|
||||
@@ -1836,17 +1837,18 @@ var kDelegateRespondsTo_textShouldBeginEditing
|
||||
proposedRange.length = textStorageLength - proposedRange.location;
|
||||
|
||||
var string = [_textStorage string],
|
||||
regex,
|
||||
lregex,
|
||||
rregex,
|
||||
loc = proposedRange.location;
|
||||
|
||||
|
||||
switch (granularity)
|
||||
{
|
||||
case CPSelectByWord:
|
||||
regex = _isWhitespaceCharacter([string characterAtIndex:loc])? [[self class] _whitespaceRegex] : [[self class] _wordBoundaryRegex];
|
||||
lregex = _isWhitespaceCharacter([string characterAtIndex:loc])? [[self class] _whitespaceRegex] : [[self class] _wordBoundaryRegex];
|
||||
rregex = _isWhitespaceCharacter([string characterAtIndex:CPMaxRange(proposedRange)])? [[self class] _whitespaceRegex] : [[self class] _wordBoundaryRegex];
|
||||
break;
|
||||
case CPSelectByParagraph:
|
||||
regex = [[self class] _paragraphBoundaryRegex];
|
||||
lregex = rregex = [[self class] _paragraphBoundaryRegex];
|
||||
|
||||
// triple click right in last line of a paragraph-> select this paragraph completely
|
||||
if (loc > 0 && _isNewlineCharacter([string characterAtIndex:loc]) &&
|
||||
@@ -1860,7 +1862,8 @@ var kDelegateRespondsTo_textShouldBeginEditing
|
||||
|
||||
var granularRange = [self _characterRangeForIndex:loc
|
||||
inRange:proposedRange
|
||||
asDefinedByRegex:regex];
|
||||
asDefinedByLRegex:lregex
|
||||
andRRegex:rregex];
|
||||
|
||||
if (proposedRange.length == 0 && _isNewlineCharacter([string characterAtIndex:proposedRange.location]))
|
||||
return _MakeRangeFromAbs(_isNewlineCharacter([string characterAtIndex:loc])? proposedRange.location : granularRange.location, proposedRange.location + 1);
|
||||
@@ -1868,7 +1871,8 @@ var kDelegateRespondsTo_textShouldBeginEditing
|
||||
if (proposedRange.length)
|
||||
granularRange = CPUnionRange(granularRange, [self _characterRangeForIndex:CPMaxRange(proposedRange)
|
||||
inRange:proposedRange
|
||||
asDefinedByRegex:regex]);
|
||||
asDefinedByLRegex:lregex
|
||||
andRRegex:rregex]);
|
||||
|
||||
if (granularity == CPSelectByParagraph && _isNewlineCharacter([string characterAtIndex:CPMaxRange(granularRange)]))
|
||||
granularRange.length++;
|
||||
|
||||
Reference in new issue
Block a user