From 59162155deceb7f2c64c6f25acf52272333d93ef Mon Sep 17 00:00:00 2001 From: daboe01 Date: Wed, 1 Jul 2015 07:20:17 +0200 Subject: [PATCH] caret loc refac --- AppKit/CPTextView/CPLayoutManager.j | 7 +++---- AppKit/CPTextView/CPTextView.j | 11 +++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/AppKit/CPTextView/CPLayoutManager.j b/AppKit/CPTextView/CPLayoutManager.j index 24f5f5717..48f1ec470 100644 --- a/AppKit/CPTextView/CPLayoutManager.j +++ b/AppKit/CPTextView/CPLayoutManager.j @@ -693,17 +693,16 @@ _oncontextmenuhandler = function () { return false; }; return nil; } -- (CGPoint)_realCharacterLocationAtLocation:(unsigned)location +- (double)_characterOffsetAtLocation:(unsigned)location inTextContainer:(CPTextContainer)aContainer { var lineFragment = _objectWithLocationInRange(_lineFragments, location); if (!lineFragment) - return CGPointMake(0, 0); + return 0.0; var index = location - lineFragment._range.location; - return CGPointMake(lineFragment._glyphsFrames[index].origin.x, - lineFragment._glyphsFrames[index].origin.y + lineFragment._glyphsOffsets[index]); + return lineFragment._glyphsOffsets[index]; } - (void)setLineFragmentRect:(CGRect)fragmentRect forGlyphRange:(CPRange)glyphRange usedRect:(CGRect)usedRect diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 38c5d7951..62b3326af 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -663,7 +663,8 @@ var kDelegateRespondsTo_textShouldBeginEditing var placeholderString = [[CPAttributedString alloc] initWithString:aNativeField.innerHTML attributes:attributes]; [self insertText:placeholderString]; // FIXME: this hack to provide the visual space for the inputmanager should at least bypass the undomanager - var caretOrigin = [_layoutManager _realCharacterLocationAtLocation:MAX(0, _selectionRange.location - 1)]; + 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.x += 2; // two pixel offset to the LHS character #if PLATFORM(DOM) @@ -1775,16 +1776,14 @@ var kDelegateRespondsTo_textShouldBeginEditing } } else - { caretRect = [_layoutManager boundingRectForGlyphRange:CPMakeRange(_selectionRange.location, 1) inTextContainer:_textContainer]; - } - var caretOrigin = [_layoutManager _realCharacterLocationAtLocation:_selectionRange.location], + var caretOffset = [_layoutManager _characterOffsetAtLocation:_selectionRange.location inTextContainer:_textContainer], oldYPosition = CGRectGetMaxY(caretRect); - if (caretOrigin.x > 0 || caretOrigin.y > 0) + if (caretOffset > 0) { - caretRect.origin = caretOrigin; + caretRect.origin.y += caretOffset; caretRect.size.height = oldYPosition - caretRect.origin.y; }