From 71d45a67b76fbfeda3559cb7d737b21fb1386dbe Mon Sep 17 00:00:00 2001 From: daboe01 Date: Sat, 1 Oct 2016 18:28:44 +0200 Subject: [PATCH] fixed: dragging placeholder did not always look like dragged text --- AppKit/CPTextView/CPTextView.j | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 917ef99d7..ddc986bb5 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -938,24 +938,33 @@ var kDelegateRespondsTo_textShouldBeginEditing if ([self selectionGranularity] == CPSelectByCharacter && CPLocationInRange(_startTrackingLocation, _selectionRange)) { - _movingSelection = CPMakeRange(_startTrackingLocation, 0); - var placeholderRect = CGRectIntersection([_layoutManager boundingRectForGlyphRange:_selectionRange inTextContainer:_textContainer], _frame), - dragPlaceholder; + var lineBeginningIndex = [_layoutManager _firstLineFragmentForLineFromLocation:_selectionRange.location]._range.location, + placeholderRange = _MakeRangeFromAbs(lineBeginningIndex, CPMaxRange(_selectionRange)), + placeholderString = [_textStorage attributedSubstringFromRange:placeholderRange], + placeholderFrame = CGRectIntersection([_layoutManager boundingRectForGlyphRange:placeholderRange inTextContainer:_textContainer], _frame), + rangeToHide = CPMakeRange(0, _selectionRange.location - lineBeginningIndex), + dragPlaceholder; - placeholderRect.size.width += 2; // prevent wrapping - dragPlaceholder = [[CPTextView alloc] initWithFrame:placeholderRect]; - [dragPlaceholder insertText:[_textStorage attributedSubstringFromRange:CPMakeRangeCopy(_selectionRange)]]; + [placeholderString addAttribute:CPForegroundColorAttributeName + value:[CPColor colorWithRed:1 green:1 blue:1 alpha:0] + range:CPMakeRangeCopy(rangeToHide)]; + + _movingSelection = CPMakeRange(_startTrackingLocation, 0); + + placeholderFrame.size.width += 2; // prevent wrapping + dragPlaceholder = [[CPTextView alloc] initWithFrame:placeholderFrame]; + [dragPlaceholder insertText:placeholderString]; [dragPlaceholder setBackgroundColor:[CPColor colorWithRed:1 green:1 blue:1 alpha:0]]; [dragPlaceholder setAlphaValue:0.5]; - + var stringForPasting = [_textStorage attributedSubstringFromRange:CPMakeRangeCopy(_selectionRange)], - richData = [_CPRTFProducer produceRTF:stringForPasting documentAttributes:@{}], - draggingPasteboard = [CPPasteboard pasteboardWithName:CPDragPboard]; + richData = [_CPRTFProducer produceRTF:stringForPasting documentAttributes:@{}], + draggingPasteboard = [CPPasteboard pasteboardWithName:CPDragPboard]; [draggingPasteboard declareTypes:[CPRTFPboardType] owner:nil]; [draggingPasteboard setString:richData forType:CPRTFPboardType]; [self dragView:dragPlaceholder - at:placeholderRect.origin + at:placeholderFrame.origin offset:nil event:event pasteboard:draggingPasteboard