diff --git a/AppKit/CPTextView/CPLayoutManager.j b/AppKit/CPTextView/CPLayoutManager.j index cb4f7f0ca..ca5764bce 100644 --- a/AppKit/CPTextView/CPLayoutManager.j +++ b/AppKit/CPTextView/CPLayoutManager.j @@ -693,7 +693,7 @@ _oncontextmenuhandler = function () { return false; }; return nil; } -- (double)_characterOffsetAtLocation:(unsigned)location inTextContainer:(CPTextContainer)aContainer +- (double)_characterOffsetAtLocation:(unsigned)location { var lineFragment = _objectWithLocationInRange(_lineFragments, location); @@ -705,6 +705,18 @@ _oncontextmenuhandler = function () { return false; }; return lineFragment._glyphsOffsets[index]; } +- (double)_descentAtLocation:(unsigned)location +{ + var lineFragment = _objectWithLocationInRange(_lineFragments, location); + + if (!lineFragment) + return 0.0; + + var index = location - lineFragment._range.location; + + return lineFragment._glyphsFrames[index]._descent; +} + - (void)setLineFragmentRect:(CGRect)fragmentRect forGlyphRange:(CPRange)glyphRange usedRect:(CGRect)usedRect { var lineFragment = _objectWithLocationInRange(_lineFragments, glyphRange.location); @@ -911,10 +923,13 @@ _oncontextmenuhandler = function () { return false; }; { if (CPLocationInRange(fragment._range.location + j, selectedCharRange)) { + var correctedRect = CGRectCreateCopy(frames[j]); + correctedRect.size.height -= frames[j]._descent; + correctedRect.origin.y -= frames[j]._descent; if (!rect) - rect = CGRectCreateCopy(frames[j]); + rect = CGRectCreateCopy(correctedRect); else - rect = CGRectUnion(rect, frames[j]); + rect = CGRectUnion(rect, correctedRect); if (_isNewlineCharacter([[_textStorage string] characterAtIndex:MAX(0, CPMaxRange(selectedCharRange) - 1)])) { @@ -1027,7 +1042,6 @@ var _sortRange = function(location, anObject) return CPOrderedAscending; } -// fixme: filter for a textContainer var _objectWithLocationInRange = function(aList, aLocation) { var index = [aList _indexOfObject:aLocation sortedByFunction:_sortRange context:nil]; @@ -1169,8 +1183,9 @@ var _objectsInRange = function(aList, aRange) for (var i = 0; i < count; i++) { - _glyphsFrames[i] = CGRectMake(origin.x, origin.y - someAdvancements[i].descent, someAdvancements[i].width, height); - _glyphsOffsets[i] = height-someAdvancements[i].height + someAdvancements[i].descent; + _glyphsFrames[i] = CGRectMake(origin.x, origin.y, someAdvancements[i].width, height); + _glyphsFrames[i]._descent = someAdvancements[i].descent + _glyphsOffsets[i] = height - someAdvancements[i].height; origin.x += someAdvancements[i].width; } } diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 887b9b7aa..64fd2f455 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -663,7 +663,7 @@ var kDelegateRespondsTo_textShouldBeginEditing [self insertText:placeholderString]; // FIXME: this hack to provide the visual space for the inputmanager should at least bypass the undomanager var caretOrigin = [_layoutManager boundingRectForGlyphRange:CPMakeRange(MAX(0, _selectionRange.location - 1), 1) inTextContainer:_textContainer].origin; - caretOrigin.y += [_layoutManager _characterOffsetAtLocation:MAX(0, _selectionRange.location - 1) inTextContainer:_textContainer]; + caretOrigin.y += [_layoutManager _characterOffsetAtLocation:MAX(0, _selectionRange.location - 1)]; caretOrigin.x += 2; // two pixel offset to the LHS character #if PLATFORM(DOM) @@ -922,7 +922,7 @@ var kDelegateRespondsTo_textShouldBeginEditing rectSource = [_layoutManager boundingRectForGlyphRange:CPMakeRange(sindex, 1) inTextContainer:_textContainer], point = rectSource.origin; - if (point.y <= 0) + if (point.y <= 2) return; if (_stickyXLocation) @@ -1780,14 +1780,19 @@ var kDelegateRespondsTo_textShouldBeginEditing else caretRect = [_layoutManager boundingRectForGlyphRange:CPMakeRange(_selectionRange.location, 1) inTextContainer:_textContainer]; - var caretOffset = [_layoutManager _characterOffsetAtLocation:_selectionRange.location inTextContainer:_textContainer], - oldYPosition = CGRectGetMaxY(caretRect); + var caretOffset = [_layoutManager _characterOffsetAtLocation:_selectionRange.location], + oldYPosition = CGRectGetMaxY(caretRect), + caretDescend = [_layoutManager _descentAtLocation:_selectionRange.location]; if (caretOffset > 0) { caretRect.origin.y += caretOffset; caretRect.size.height = oldYPosition - caretRect.origin.y; } + if (caretDescend < 0) + { + caretRect.size.height -= caretDescend; + } caretRect.origin.x += _textContainerOrigin.x; caretRect.origin.y += _textContainerOrigin.y; diff --git a/AppKit/CPTextView/CPTypesetter.j b/AppKit/CPTextView/CPTypesetter.j index b5844fd90..4e67c6f94 100644 --- a/AppKit/CPTextView/CPTypesetter.j +++ b/AppKit/CPTextView/CPTypesetter.j @@ -313,6 +313,7 @@ var CPSystemTypesetterFactory; wrapRange = CPMakeRangeCopy(lineRange); wrapWidth = rangeWidth; wrapRange._height = _lineHeight; + wrapRange._base = _lineBase; break; default: @@ -333,6 +334,7 @@ var CPSystemTypesetterFactory; lineRange = wrapRange; _lineWidth = wrapWidth; _lineHeight = wrapRange._height; + _lineBase = wrapRange._base; } isNewline = YES;