From 5736d2c9ccc729fda6eeffef9e1af5f4450ef5e2 Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Thu, 22 Jan 2015 13:31:04 -0500 Subject: [PATCH 01/23] Formatting: CPView Previously CPView used "==" as an equality checker. This commit changes these to use "===" for consistency. --- AppKit/CPView.j | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/AppKit/CPView.j b/AppKit/CPView.j index 18d09d25e..b614a1381 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -380,7 +380,7 @@ var CPViewFlags = { }, */ - (void)setToolTip:(CPString)aToolTip { - if (_toolTip == aToolTip) + if (_toolTip === aToolTip) return; if (aToolTip && ![aToolTip isKindOfClass:CPString]) @@ -525,7 +525,7 @@ var CPViewFlags = { }, [[self window] _dirtyKeyViewLoop]; // If this is already one of our subviews, remove it. - if (aSubview._superview == self) + if (aSubview._superview === self) { var index = [_subviews indexOfObjectIdenticalTo:aSubview]; @@ -796,7 +796,7 @@ var CPViewFlags = { }, do { - if (view == aView) + if (view === aView) return YES; } while(view = [view superview]) @@ -911,7 +911,7 @@ var CPViewFlags = { }, - (CPView)viewWithTag:(CPInteger)aTag { - if ([self tag] == aTag) + if ([self tag] === aTag) return self; var index = 0, @@ -1342,7 +1342,7 @@ var CPViewFlags = { }, { var mask = [self autoresizingMask]; - if (mask == CPViewNotSizable) + if (mask === CPViewNotSizable) return; var frame = _superview._frame, @@ -1525,7 +1525,7 @@ var CPViewFlags = { }, { do { - if (self == view) + if (self === view) { [_window makeFirstResponder:[self nextValidKeyView]]; break; @@ -1595,7 +1595,7 @@ var CPViewFlags = { }, */ - (void)setAlphaValue:(float)anAlphaValue { - if (_opacity == anAlphaValue) + if (_opacity === anAlphaValue) return; _opacity = anAlphaValue; @@ -1799,10 +1799,10 @@ var CPViewFlags = { }, */ - (void)setBackgroundColor:(CPColor)aColor { - if (_backgroundColor == aColor) + if (_backgroundColor === aColor) return; - if (aColor == [CPNull null]) + if (aColor === [CPNull null]) aColor = nil; _backgroundColor = aColor; @@ -1845,7 +1845,7 @@ var CPViewFlags = { }, var image = slices[i], size = [image size]; - if (!size || (size.width == 0 && size.height == 0)) + if (!size || (size.width === 0 && size.height === 0)) size = nil; _DOMImageSizes[i] = size; @@ -1900,10 +1900,12 @@ var CPViewFlags = { }, CPDOMDisplayServerSetStyleSize(_DOMImageParts[0], size.width, size.height); } else + { _DOMElement.style.background = colorCSS; if (patternImage) CPDOMDisplayServerSetStyleBackgroundSize(_DOMElement, [patternImage size].width + "px", [patternImage size].height + "px"); + } } else { @@ -1937,7 +1939,7 @@ var CPViewFlags = { }, partIndex++; } - if (_backgroundType == BackgroundNinePartImage) + if (_backgroundType === BackgroundNinePartImage) { var left = _DOMImageSizes[0] ? _DOMImageSizes[0].width : 0, right = _DOMImageSizes[2] ? _DOMImageSizes[2].width : 0, @@ -1998,7 +2000,7 @@ var CPViewFlags = { }, CPDOMDisplayServerSetStyleRightBottom(_DOMImageParts[partIndex], NULL, 0.0, 0.0); } } - else if (_backgroundType == BackgroundVerticalThreePartImage) + else if (_backgroundType === BackgroundVerticalThreePartImage) { var top = _DOMImageSizes[0] ? _DOMImageSizes[0].height : 0, bottom = _DOMImageSizes[2] ? _DOMImageSizes[2].height : 0; @@ -2030,7 +2032,7 @@ var CPViewFlags = { }, CPDOMDisplayServerSetStyleSize(_DOMImageParts[partIndex], frameSize.width, bottom); } } - else if (_backgroundType == BackgroundHorizontalThreePartImage) + else if (_backgroundType === BackgroundHorizontalThreePartImage) { var left = _DOMImageSizes[0] ? _DOMImageSizes[0].width : 0, right = _DOMImageSizes[2] ? _DOMImageSizes[2].width : 0; @@ -2913,7 +2915,7 @@ setBoundsOrigin: */ - (void)setLayer:(CALayer)aLayer { - if (_layer == aLayer) + if (_layer === aLayer) return; if (_layer) From aee5a2cbe479627db7f4c506d66ff40b96ed6dd5 Mon Sep 17 00:00:00 2001 From: daboe01 Date: Wed, 28 Sep 2016 11:55:56 +0200 Subject: [PATCH 02/23] refactor point conversion to private method _characterIndexFromEvent --- AppKit/CPTextView/CPTextView.j | 64 +++++++++++++++++----------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 7080aa297..893694004 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -153,6 +153,7 @@ var kDelegateRespondsTo_textShouldBeginEditing CPTimer _scrollingTimer; BOOL _scrollingDownward; + BOOL _movingSelection; int _stickyXLocation; @@ -899,6 +900,24 @@ var kDelegateRespondsTo_textShouldBeginEditing }, 500); } +- (CGPoint)_characterIndexFromEvent:(CPEvent)event +{ + var fraction = [], + point = [self convertPoint:[event locationInWindow] fromView:nil]; + + // convert to container coordinate + point.x -= _textContainerOrigin.x; + point.y -= _textContainerOrigin.y; + + var index = [_layoutManager glyphIndexForPoint:point inTextContainer:_textContainer fractionOfDistanceThroughGlyph:fraction]; + + if (index === CPNotFound) + index = [_layoutManager numberOfCharacters]; + else if (fraction[0] > 0.5) + index++; + + return index; +} #pragma mark - #pragma mark Mouse Events @@ -907,24 +926,16 @@ var kDelegateRespondsTo_textShouldBeginEditing { [_CPNativeInputManager cancelCurrentInputSessionIfNeeded]; - var fraction = [], - point = [self convertPoint:[event locationInWindow] fromView:nil], - granularities = [CPNotFound, CPSelectByCharacter, CPSelectByWord, CPSelectByParagraph]; - - [_caret setVisibility:NO]; - - // convert to container coordinate - point.x -= _textContainerOrigin.x; - point.y -= _textContainerOrigin.y; - - _startTrackingLocation = [_layoutManager glyphIndexForPoint:point inTextContainer:_textContainer fractionOfDistanceThroughGlyph:fraction]; - - if (_startTrackingLocation === CPNotFound) - _startTrackingLocation = [_layoutManager numberOfCharacters]; - else if (fraction[0] > 0.5) - _startTrackingLocation++; - + _startTrackingLocation = [self _characterIndexFromEvent:event]; + + var granularities = [CPNotFound, CPSelectByCharacter, CPSelectByWord, CPSelectByParagraph]; [self setSelectionGranularity:granularities[[event clickCount]]]; + + if ([self selectionGranularity] == CPSelectByCharacter && CPLocationInRange(_startTrackingLocation, _selectionRange)) + { + _movingSelection = YES; + return; + } var setRange = CPMakeRange(_startTrackingLocation, 0); @@ -943,22 +954,11 @@ var kDelegateRespondsTo_textShouldBeginEditing - (void)mouseDragged:(CPEvent)event { - var fraction = [], - point = [self convertPoint:[event locationInWindow] fromView:nil]; - - // convert to container coordinate - point.x -= _textContainerOrigin.x; - point.y -= _textContainerOrigin.y; - + if (_movingSelection) + return; + var oldRange = [self selectedRange], - index = [_layoutManager glyphIndexForPoint:point - inTextContainer:_textContainer - fractionOfDistanceThroughGlyph:fraction]; - - if (index === CPNotFound) - index = _scrollingDownward ? CPMaxRange(oldRange) : oldRange.location; - else if (fraction[0] > 0.5) - index++; + index = [self _characterIndexFromEvent:event]; if (index > oldRange.location) _scrollingDownward = YES; From 4e14ad7821243f764ebfa16e7edcf89a1bfde91d Mon Sep 17 00:00:00 2001 From: daboe01 Date: Wed, 28 Sep 2016 15:12:26 +0200 Subject: [PATCH 03/23] basic support of text selection dragging --- AppKit/CPTextView/CPTextView.j | 88 ++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 14 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 893694004..7c83858e0 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -153,7 +153,7 @@ var kDelegateRespondsTo_textShouldBeginEditing CPTimer _scrollingTimer; BOOL _scrollingDownward; - BOOL _movingSelection; + CPRange _movingSelection; int _stickyXLocation; @@ -204,7 +204,7 @@ var kDelegateRespondsTo_textShouldBeginEditing _typingAttributes = [[CPDictionary alloc] initWithObjects:[_font, _textColor] forKeys:[CPFontAttributeName, CPForegroundColorAttributeName]]; } - [self registerForDraggedTypes:[CPColorDragType]]; + [self registerForDraggedTypes:[CPColorDragType, CPRTFPboardType]]; return self; } @@ -900,10 +900,10 @@ var kDelegateRespondsTo_textShouldBeginEditing }, 500); } -- (CGPoint)_characterIndexFromEvent:(CPEvent)event +- (CGPoint)_characterIndexFromRawPoint:(CGPoint)point { var fraction = [], - point = [self convertPoint:[event locationInWindow] fromView:nil]; + point = [self convertPoint:point fromView:nil]; // convert to container coordinate point.x -= _textContainerOrigin.x; @@ -918,6 +918,10 @@ var kDelegateRespondsTo_textShouldBeginEditing return index; } +- (CGPoint)_characterIndexFromEvent:(CPEvent)event +{ + return [self _characterIndexFromRawPoint:[event locationInWindow]]; +} #pragma mark - #pragma mark Mouse Events @@ -925,7 +929,9 @@ var kDelegateRespondsTo_textShouldBeginEditing - (void)mouseDown:(CPEvent)event { [_CPNativeInputManager cancelCurrentInputSessionIfNeeded]; - + + [_caret setVisibility:NO]; + _startTrackingLocation = [self _characterIndexFromEvent:event]; var granularities = [CPNotFound, CPSelectByCharacter, CPSelectByWord, CPSelectByParagraph]; @@ -933,12 +939,32 @@ var kDelegateRespondsTo_textShouldBeginEditing if ([self selectionGranularity] == CPSelectByCharacter && CPLocationInRange(_startTrackingLocation, _selectionRange)) { - _movingSelection = YES; + _movingSelection = CPMaxRange(_startTrackingLocation, 0); + var dragPlaceholder = [CPTextField new], + originPoint = [_layoutManager locationForGlyphAtIndex:[self selectedRange].location]; + + [dragPlaceholder setStringValue:[[self stringValue] substringWithRange:_selectionRange]]; + [dragPlaceholder sizeToFit]; + + var stringForPasting = [_textStorage attributedSubstringFromRange:CPMakeRangeCopy(_selectionRange)], + richData = [_CPRTFProducer produceRTF:stringForPasting documentAttributes:@{}], + draggingPasteboard = [CPPasteboard pasteboardWithName:CPDragPboard]; + [draggingPasteboard declareTypes:[CPRTFPboardType] owner:nil]; + [draggingPasteboard setString:richData forType:CPRTFPboardType]; + + [self dragView:dragPlaceholder + at:originPoint + offset:nil + event:event + pasteboard:draggingPasteboard + source:self + slideBack:YES]; + return; } - + var setRange = CPMakeRange(_startTrackingLocation, 0); - + if ([event modifierFlags] & CPShiftKeyMask) setRange = _MakeRangeFromAbs(_startTrackingLocation < _MidRange(_selectionRange) ? CPMaxRange(_selectionRange) : _selectionRange.location, _startTrackingLocation); else @@ -977,7 +1003,9 @@ var kDelegateRespondsTo_textShouldBeginEditing - (void)mouseUp:(CPEvent)event { - /* will post CPTextViewDidChangeSelectionNotification */ + _movingSelection = nil; + + // will post CPTextViewDidChangeSelectionNotification _previousSelectionGranularity = [self selectionGranularity]; [self setSelectionGranularity:CPSelectByCharacter]; [self setSelectedRange:[self selectedRange] affinity:0 stillSelecting:NO]; @@ -1965,19 +1993,43 @@ var kDelegateRespondsTo_textShouldBeginEditing [_caret startBlinking]; } +- (void)draggingUpdated:(CPDraggingInfo)info +{ + var point = [info draggingLocation], + location = [self _characterIndexFromRawPoint:point]; + + _movingSelection = CPMakeRange(location, 0) + [_caret _drawCaretAtLocation:_movingSelection.location]; + [_caret setVisibility:YES]; +} #pragma mark - #pragma mark Dragging operation - (void)performDragOperation:(CPDraggingInfo)aSender { - var location = [self convertPoint:[aSender draggingLocation] fromView:nil], + var location = [self convertPoint:[aSender draggingLocation] fromView:nil], pasteboard = [aSender draggingPasteboard]; + + if ([pasteboard availableTypeFromArray:[CPRTFPboardType]]) + { + [_caret setVisibility:NO]; + + if (CPLocationInRange(_movingSelection.location, _selectionRange)) + { + [self setSelectedRange:_movingSelection]; + return; + } - if (![pasteboard availableTypeFromArray:[CPColorDragType]]) - return NO; - - [self setTextColor:[CPKeyedUnarchiver unarchiveObjectWithData:[pasteboard dataForType:CPColorDragType]] range:_selectionRange]; + [self _deleteForRange:_selectionRange]; + [self setSelectedRange:_movingSelection]; + + var dataForPasting = [pasteboard stringForType:CPRTFPboardType]; + [self insertText:[[_CPRTFParser new] parseRTF:dataForPasting]]; + } + + if ([pasteboard availableTypeFromArray:[CPColorDragType]]) + [self setTextColor:[CPKeyedUnarchiver unarchiveObjectWithData:[pasteboard dataForType:CPColorDragType]] range:_selectionRange]; } @end @@ -2254,6 +2306,12 @@ var CPTextViewAllowsUndoKey = @"CPTextViewAllowsUndoKey", _caretTimer = nil; } } + +- (void)_drawCaretAtLocation:(int)aLoc +{ + var rect = [_textView._layoutManager boundingRectForGlyphRange:CPMakeRange(aLoc, 1) inTextContainer:_textView._textContainer]; + [self setRect:rect]; +} @end @@ -2639,6 +2697,7 @@ var _CPCopyPlaceholder = '-'; -(void) _setRegularExpression:(JSObject)re toFontTrait:(CPFontTrait)aTrait { + var match; while (match = re.exec(_string)) { var attribs = [[self attributesAtIndex:match.index effectiveRange:nil] copy], @@ -2650,6 +2709,7 @@ var _CPCopyPlaceholder = '-'; -(void) _replaceEveryOccurenceOfRegularExpression:(JSObject)re withString:(CPString)aString { + var match; while (match = re.exec(_string)) [self replaceCharactersInRange:CPMakeRange(match.index, match[0].length) withString:aString]; } From 39d01a1da88a77192d36cbc69502b33be367b626 Mon Sep 17 00:00:00 2001 From: daboe01 Date: Wed, 28 Sep 2016 16:15:31 +0200 Subject: [PATCH 04/23] sizing correction for dragging --- AppKit/CPTextView/CPTextView.j | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 7c83858e0..d98000baa 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -942,7 +942,11 @@ var kDelegateRespondsTo_textShouldBeginEditing _movingSelection = CPMaxRange(_startTrackingLocation, 0); var dragPlaceholder = [CPTextField new], originPoint = [_layoutManager locationForGlyphAtIndex:[self selectedRange].location]; - + + originPoint.y -= [_layoutManager _descentAtLocation:_selectionRange.location]; + originPoint.x += _textContainerOrigin.x; + originPoint.y += _textContainerOrigin.y; + [dragPlaceholder setStringValue:[[self stringValue] substringWithRange:_selectionRange]]; [dragPlaceholder sizeToFit]; From 2217b560cbf2d2e51992a1e6df3a163847714f0a Mon Sep 17 00:00:00 2001 From: daboe01 Date: Wed, 28 Sep 2016 16:21:55 +0200 Subject: [PATCH 05/23] formatting --- AppKit/CPTextView/CPTextView.j | 40 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index d98000baa..16ec3740c 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -153,7 +153,7 @@ var kDelegateRespondsTo_textShouldBeginEditing CPTimer _scrollingTimer; BOOL _scrollingDownward; - CPRange _movingSelection; + CPRange _movingSelection; int _stickyXLocation; @@ -903,7 +903,7 @@ var kDelegateRespondsTo_textShouldBeginEditing - (CGPoint)_characterIndexFromRawPoint:(CGPoint)point { var fraction = [], - point = [self convertPoint:point fromView:nil]; + point = [self convertPoint:point fromView:nil]; // convert to container coordinate point.x -= _textContainerOrigin.x; @@ -939,9 +939,9 @@ var kDelegateRespondsTo_textShouldBeginEditing if ([self selectionGranularity] == CPSelectByCharacter && CPLocationInRange(_startTrackingLocation, _selectionRange)) { - _movingSelection = CPMaxRange(_startTrackingLocation, 0); + _movingSelection = CPMakeRange(_startTrackingLocation, 0); var dragPlaceholder = [CPTextField new], - originPoint = [_layoutManager locationForGlyphAtIndex:[self selectedRange].location]; + originPoint = [_layoutManager locationForGlyphAtIndex:[self selectedRange].location]; originPoint.y -= [_layoutManager _descentAtLocation:_selectionRange.location]; originPoint.x += _textContainerOrigin.x; @@ -951,8 +951,8 @@ var kDelegateRespondsTo_textShouldBeginEditing [dragPlaceholder sizeToFit]; 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]; @@ -988,7 +988,7 @@ var kDelegateRespondsTo_textShouldBeginEditing return; var oldRange = [self selectedRange], - index = [self _characterIndexFromEvent:event]; + index = [self _characterIndexFromEvent:event]; if (index > oldRange.location) _scrollingDownward = YES; @@ -1999,12 +1999,12 @@ var kDelegateRespondsTo_textShouldBeginEditing - (void)draggingUpdated:(CPDraggingInfo)info { - var point = [info draggingLocation], + var point = [info draggingLocation], location = [self _characterIndexFromRawPoint:point]; - _movingSelection = CPMakeRange(location, 0) - [_caret _drawCaretAtLocation:_movingSelection.location]; - [_caret setVisibility:YES]; + _movingSelection = CPMakeRange(location, 0) + [_caret _drawCaretAtLocation:_movingSelection.location]; + [_caret setVisibility:YES]; } #pragma mark - @@ -2012,11 +2012,11 @@ var kDelegateRespondsTo_textShouldBeginEditing - (void)performDragOperation:(CPDraggingInfo)aSender { - var location = [self convertPoint:[aSender draggingLocation] fromView:nil], + var location = [self convertPoint:[aSender draggingLocation] fromView:nil], pasteboard = [aSender draggingPasteboard]; - if ([pasteboard availableTypeFromArray:[CPRTFPboardType]]) - { + if ([pasteboard availableTypeFromArray:[CPRTFPboardType]]) + { [_caret setVisibility:NO]; if (CPLocationInRange(_movingSelection.location, _selectionRange)) @@ -2028,9 +2028,9 @@ var kDelegateRespondsTo_textShouldBeginEditing [self _deleteForRange:_selectionRange]; [self setSelectedRange:_movingSelection]; - var dataForPasting = [pasteboard stringForType:CPRTFPboardType]; + var dataForPasting = [pasteboard stringForType:CPRTFPboardType]; [self insertText:[[_CPRTFParser new] parseRTF:dataForPasting]]; - } + } if ([pasteboard availableTypeFromArray:[CPColorDragType]]) [self setTextColor:[CPKeyedUnarchiver unarchiveObjectWithData:[pasteboard dataForType:CPColorDragType]] range:_selectionRange]; @@ -2313,8 +2313,8 @@ var CPTextViewAllowsUndoKey = @"CPTextViewAllowsUndoKey", - (void)_drawCaretAtLocation:(int)aLoc { - var rect = [_textView._layoutManager boundingRectForGlyphRange:CPMakeRange(aLoc, 1) inTextContainer:_textView._textContainer]; - [self setRect:rect]; + var rect = [_textView._layoutManager boundingRectForGlyphRange:CPMakeRange(aLoc, 1) inTextContainer:_textView._textContainer]; + [self setRect:rect]; } @end @@ -2701,7 +2701,7 @@ var _CPCopyPlaceholder = '-'; -(void) _setRegularExpression:(JSObject)re toFontTrait:(CPFontTrait)aTrait { - var match; + var match; while (match = re.exec(_string)) { var attribs = [[self attributesAtIndex:match.index effectiveRange:nil] copy], @@ -2713,7 +2713,7 @@ var _CPCopyPlaceholder = '-'; -(void) _replaceEveryOccurenceOfRegularExpression:(JSObject)re withString:(CPString)aString { - var match; + var match; while (match = re.exec(_string)) [self replaceCharactersInRange:CPMakeRange(match.index, match[0].length) withString:aString]; } From 4befe17cab81805ddfcdb6e4e8956566b0d609aa Mon Sep 17 00:00:00 2001 From: daboe01 Date: Wed, 28 Sep 2016 17:24:39 +0200 Subject: [PATCH 06/23] fixed: target index in selection dragging was sometimes wrong --- AppKit/CPTextView/CPTextView.j | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 16ec3740c..8bd00a039 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -942,11 +942,11 @@ var kDelegateRespondsTo_textShouldBeginEditing _movingSelection = CPMakeRange(_startTrackingLocation, 0); var dragPlaceholder = [CPTextField new], originPoint = [_layoutManager locationForGlyphAtIndex:[self selectedRange].location]; - - originPoint.y -= [_layoutManager _descentAtLocation:_selectionRange.location]; + + originPoint.y += [_layoutManager _characterOffsetAtLocation:_selectionRange.location] + _textContainerOrigin.y - 1; originPoint.x += _textContainerOrigin.x; - originPoint.y += _textContainerOrigin.y; + dragPlaceholder._DOMElement.style.opacity = '0.6'; [dragPlaceholder setStringValue:[[self stringValue] substringWithRange:_selectionRange]]; [dragPlaceholder sizeToFit]; @@ -2025,6 +2025,9 @@ var kDelegateRespondsTo_textShouldBeginEditing return; } + if (_movingSelection.location > CPMaxRange(_selectionRange)) + _movingSelection.location -= _selectionRange.length; + [self _deleteForRange:_selectionRange]; [self setSelectedRange:_movingSelection]; From dafa6e031062e8d9b247a7a511b164df2bc3429f Mon Sep 17 00:00:00 2001 From: daboe01 Date: Wed, 28 Sep 2016 17:31:39 +0200 Subject: [PATCH 07/23] fixed: space escape was missed for rich text pasting --- AppKit/CPTextView/CPTextView.j | 1 + 1 file changed, 1 insertion(+) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 8bd00a039..ec8a5e7df 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -2730,6 +2730,7 @@ var _CPCopyPlaceholder = '-'; [self _replaceEveryOccurenceOfRegularExpression:/</i withString:'<']; [self _replaceEveryOccurenceOfRegularExpression:/>/i withString:'>']; [self _replaceEveryOccurenceOfRegularExpression:/&/i withString:'&']; + [self _replaceEveryOccurenceOfRegularExpression:/ /i withString:' ']; return self; } From 55cfe31dfe0afde028e4b62750a66028c6fcb3ad Mon Sep 17 00:00:00 2001 From: daboe01 Date: Wed, 28 Sep 2016 17:36:28 +0200 Subject: [PATCH 08/23] fixed: selection did not work directly after aborted drag --- AppKit/CPTextView/CPTextView.j | 1 + 1 file changed, 1 insertion(+) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index ec8a5e7df..a77006ce4 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -2022,6 +2022,7 @@ var kDelegateRespondsTo_textShouldBeginEditing if (CPLocationInRange(_movingSelection.location, _selectionRange)) { [self setSelectedRange:_movingSelection]; + _movingSelection = nil; return; } From b15cc59b95793f847f25bf4beee99f4504abe06e Mon Sep 17 00:00:00 2001 From: daboe01 Date: Wed, 28 Sep 2016 19:42:59 +0200 Subject: [PATCH 09/23] prettify drag placeholder --- AppKit/CPTextView/CPTextView.j | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index a77006ce4..d566b05a3 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -941,13 +941,22 @@ var kDelegateRespondsTo_textShouldBeginEditing { _movingSelection = CPMakeRange(_startTrackingLocation, 0); var dragPlaceholder = [CPTextField new], - originPoint = [_layoutManager locationForGlyphAtIndex:[self selectedRange].location]; + originPoint = [_layoutManager locationForGlyphAtIndex:_selectionRange.location]; - originPoint.y += [_layoutManager _characterOffsetAtLocation:_selectionRange.location] + _textContainerOrigin.y - 1; originPoint.x += _textContainerOrigin.x; - - dragPlaceholder._DOMElement.style.opacity = '0.6'; - [dragPlaceholder setStringValue:[[self stringValue] substringWithRange:_selectionRange]]; + originPoint.y += _textContainerOrigin.y; + + dragPlaceholder._DOMElement.style.opacity = '0.5'; + var attributes = [_textStorage attributesAtIndex:_selectionRange.location effectiveRange:nil]; + [dragPlaceholder setFont:[attributes objectForKey:CPFontAttributeName]]; + [dragPlaceholder setTextColor:[attributes objectForKey:CPForegroundColorAttributeName]]; + var effectiveRange = CPIntersectionRange(CPMakeRange(_selectionRange.location, 10), _selectionRange), + placeholderString = [[self stringValue] substringWithRange:effectiveRange]; + + if (_selectionRange.length > 10) + placeholderString += '...'; + + [dragPlaceholder setStringValue:placeholderString]; [dragPlaceholder sizeToFit]; var stringForPasting = [_textStorage attributedSubstringFromRange:CPMakeRangeCopy(_selectionRange)], From 285fafc46459eaaa7661b1c4d23ba8db78092b3f Mon Sep 17 00:00:00 2001 From: daboe01 Date: Wed, 28 Sep 2016 20:34:46 +0200 Subject: [PATCH 10/23] rtf parser fix + formatting --- AppKit/CPTextView/CPTextView.j | 5 ++--- AppKit/CPTextView/_CPRTFParser.j | 5 ++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index d566b05a3..e8f4459a5 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -929,7 +929,6 @@ var kDelegateRespondsTo_textShouldBeginEditing - (void)mouseDown:(CPEvent)event { [_CPNativeInputManager cancelCurrentInputSessionIfNeeded]; - [_caret setVisibility:NO]; _startTrackingLocation = [self _characterIndexFromEvent:event]; @@ -946,12 +945,12 @@ var kDelegateRespondsTo_textShouldBeginEditing originPoint.x += _textContainerOrigin.x; originPoint.y += _textContainerOrigin.y; - dragPlaceholder._DOMElement.style.opacity = '0.5'; + dragPlaceholder._DOMElement.style.opacity = '0.4'; var attributes = [_textStorage attributesAtIndex:_selectionRange.location effectiveRange:nil]; [dragPlaceholder setFont:[attributes objectForKey:CPFontAttributeName]]; [dragPlaceholder setTextColor:[attributes objectForKey:CPForegroundColorAttributeName]]; var effectiveRange = CPIntersectionRange(CPMakeRange(_selectionRange.location, 10), _selectionRange), - placeholderString = [[self stringValue] substringWithRange:effectiveRange]; + placeholderString = [[self stringValue] substringWithRange:effectiveRange]; if (_selectionRange.length > 10) placeholderString += '...'; diff --git a/AppKit/CPTextView/_CPRTFParser.j b/AppKit/CPTextView/_CPRTFParser.j index a94081c8d..ec76b0a1e 100644 --- a/AppKit/CPTextView/_CPRTFParser.j +++ b/AppKit/CPTextView/_CPRTFParser.j @@ -514,6 +514,9 @@ var kRgsymRtf = { return [self _applyPropChange:sym parameter:param]; case kRTFParserType_char: + if((param + '').length) + _currentParseIndex -= (param + '').length; + return [self _checkChar:sym parameter:param]; case kRTFParserType_dest: @@ -785,4 +788,4 @@ var kRgsymRtf = { return _result; } -@end \ No newline at end of file +@end From 1492763d0cf6aa4b80a06c9119dee56afe770e5c Mon Sep 17 00:00:00 2001 From: daboe01 Date: Wed, 28 Sep 2016 20:55:30 +0200 Subject: [PATCH 11/23] fixed: par issue in rtf parser --- AppKit/CPTextView/_CPRTFParser.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPTextView/_CPRTFParser.j b/AppKit/CPTextView/_CPRTFParser.j index ec76b0a1e..f1f94db99 100644 --- a/AppKit/CPTextView/_CPRTFParser.j +++ b/AppKit/CPTextView/_CPRTFParser.j @@ -514,7 +514,7 @@ var kRgsymRtf = { return [self _applyPropChange:sym parameter:param]; case kRTFParserType_char: - if((param + '').length) + if((param + '') !== 'NaN' && (param + '').length) _currentParseIndex -= (param + '').length; return [self _checkChar:sym parameter:param]; From 1206654d986e114203b22f98b661d6cbcff7b2dd Mon Sep 17 00:00:00 2001 From: daboe01 Date: Thu, 29 Sep 2016 15:41:46 +0200 Subject: [PATCH 12/23] fixed: drag placeholder was CPTextField instead of CPTextView --- AppKit/CPTextView/CPTextView.j | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index e8f4459a5..46a15a302 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -939,33 +939,24 @@ var kDelegateRespondsTo_textShouldBeginEditing if ([self selectionGranularity] == CPSelectByCharacter && CPLocationInRange(_startTrackingLocation, _selectionRange)) { _movingSelection = CPMakeRange(_startTrackingLocation, 0); - var dragPlaceholder = [CPTextField new], - originPoint = [_layoutManager locationForGlyphAtIndex:_selectionRange.location]; - - originPoint.x += _textContainerOrigin.x; - originPoint.y += _textContainerOrigin.y; - - dragPlaceholder._DOMElement.style.opacity = '0.4'; - var attributes = [_textStorage attributesAtIndex:_selectionRange.location effectiveRange:nil]; - [dragPlaceholder setFont:[attributes objectForKey:CPFontAttributeName]]; - [dragPlaceholder setTextColor:[attributes objectForKey:CPForegroundColorAttributeName]]; - var effectiveRange = CPIntersectionRange(CPMakeRange(_selectionRange.location, 10), _selectionRange), - placeholderString = [[self stringValue] substringWithRange:effectiveRange]; - - if (_selectionRange.length > 10) - placeholderString += '...'; - - [dragPlaceholder setStringValue:placeholderString]; - [dragPlaceholder sizeToFit]; + var placeholderRect = CGRectIntersection([_layoutManager boundingRectForGlyphRange:_selectionRange inTextContainer:_textContainer], _frame), + dragPlaceholder; + placeholderRect.size.width += 10; // prevent wrapping + dragPlaceholder = [[CPTextView alloc] initWithFrame:placeholderRect]; + [dragPlaceholder insertText:[_textStorage attributedSubstringFromRange:CPMakeRangeCopy(_selectionRange)]]; +#if PLATFORM(DOM) + dragPlaceholder._DOMElement.style.backgroundColor = "transparent"; + dragPlaceholder._DOMElement.style.opacity = "0.5"; +#endif var stringForPasting = [_textStorage attributedSubstringFromRange:CPMakeRangeCopy(_selectionRange)], richData = [_CPRTFProducer produceRTF:stringForPasting documentAttributes:@{}], draggingPasteboard = [CPPasteboard pasteboardWithName:CPDragPboard]; [draggingPasteboard declareTypes:[CPRTFPboardType] owner:nil]; [draggingPasteboard setString:richData forType:CPRTFPboardType]; - + [self dragView:dragPlaceholder - at:originPoint + at:placeholderRect.origin offset:nil event:event pasteboard:draggingPasteboard From 8dc1369ba3a97bfe5d5b269003f79c4aa5e416ed Mon Sep 17 00:00:00 2001 From: daboe01 Date: Fri, 30 Sep 2016 16:03:36 +0200 Subject: [PATCH 13/23] fixed: direct DOM manipulation on drag placeholder instead of using capp methods + formatting --- AppKit/CPTextView/CPTextView.j | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 46a15a302..917ef99d7 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -942,13 +942,12 @@ var kDelegateRespondsTo_textShouldBeginEditing var placeholderRect = CGRectIntersection([_layoutManager boundingRectForGlyphRange:_selectionRange inTextContainer:_textContainer], _frame), dragPlaceholder; - placeholderRect.size.width += 10; // prevent wrapping + placeholderRect.size.width += 2; // prevent wrapping dragPlaceholder = [[CPTextView alloc] initWithFrame:placeholderRect]; [dragPlaceholder insertText:[_textStorage attributedSubstringFromRange:CPMakeRangeCopy(_selectionRange)]]; -#if PLATFORM(DOM) - dragPlaceholder._DOMElement.style.backgroundColor = "transparent"; - dragPlaceholder._DOMElement.style.opacity = "0.5"; -#endif + [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]; @@ -2001,7 +2000,7 @@ var kDelegateRespondsTo_textShouldBeginEditing var point = [info draggingLocation], location = [self _characterIndexFromRawPoint:point]; - _movingSelection = CPMakeRange(location, 0) + _movingSelection = CPMakeRange(location, 0); [_caret _drawCaretAtLocation:_movingSelection.location]; [_caret setVisibility:YES]; } From 71d45a67b76fbfeda3559cb7d737b21fb1386dbe Mon Sep 17 00:00:00 2001 From: daboe01 Date: Sat, 1 Oct 2016 18:28:44 +0200 Subject: [PATCH 14/23] 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 From 39a695959d621566b2263405a96aa87afa93fc3c Mon Sep 17 00:00:00 2001 From: daboe01 Date: Sat, 1 Oct 2016 18:29:47 +0200 Subject: [PATCH 15/23] formatting --- AppKit/CPTextView/CPTextView.j | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index ddc986bb5..6d3623103 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -939,11 +939,11 @@ var kDelegateRespondsTo_textShouldBeginEditing if ([self selectionGranularity] == CPSelectByCharacter && CPLocationInRange(_startTrackingLocation, _selectionRange)) { 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; + placeholderRange = _MakeRangeFromAbs(lineBeginningIndex, CPMaxRange(_selectionRange)), + placeholderString = [_textStorage attributedSubstringFromRange:placeholderRange], + placeholderFrame = CGRectIntersection([_layoutManager boundingRectForGlyphRange:placeholderRange inTextContainer:_textContainer], _frame), + rangeToHide = CPMakeRange(0, _selectionRange.location - lineBeginningIndex), + dragPlaceholder; [placeholderString addAttribute:CPForegroundColorAttributeName value:[CPColor colorWithRed:1 green:1 blue:1 alpha:0] @@ -958,8 +958,8 @@ var kDelegateRespondsTo_textShouldBeginEditing [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]; From 47688bf016502540ec6202cac208bfee41deaecc Mon Sep 17 00:00:00 2001 From: daboe01 Date: Sat, 1 Oct 2016 18:32:19 +0200 Subject: [PATCH 16/23] formatting --- AppKit/CPTextView/CPTextView.j | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 6d3623103..39c4d83d0 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -945,9 +945,10 @@ var kDelegateRespondsTo_textShouldBeginEditing rangeToHide = CPMakeRange(0, _selectionRange.location - lineBeginningIndex), dragPlaceholder; + // hide the left part of the first line of the selection that is not included [placeholderString addAttribute:CPForegroundColorAttributeName value:[CPColor colorWithRed:1 green:1 blue:1 alpha:0] - range:CPMakeRangeCopy(rangeToHide)]; + range:rangeToHide]; _movingSelection = CPMakeRange(_startTrackingLocation, 0); From e0d42962e7bcfcd6a361c4fc610af49ea76d0a6e Mon Sep 17 00:00:00 2001 From: daboe01 Date: Sat, 1 Oct 2016 19:56:35 +0200 Subject: [PATCH 17/23] fixed: wrapping issue when dragging last word --- AppKit/CPTextView/CPLayoutManager.j | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AppKit/CPTextView/CPLayoutManager.j b/AppKit/CPTextView/CPLayoutManager.j index 99d403be3..54591368e 100644 --- a/AppKit/CPTextView/CPLayoutManager.j +++ b/AppKit/CPTextView/CPLayoutManager.j @@ -164,7 +164,7 @@ _oncontextmenuhandler = function () { return false; }; if (![self numberOfGlyphs]) return CGRectMake(0, 0, 1, 12); // crude hack to give a cursor in an empty doc. - if (CPMaxRange(aRange) >= [self numberOfGlyphs]) + if (CPMaxRange(aRange) > [self numberOfGlyphs]) aRange = CPMakeRange([self numberOfGlyphs] - 1, 1); var fragments = _objectsInRange(_lineFragments, aRange), @@ -1370,4 +1370,4 @@ var _objectsInRange = function(aList, aRange) "\n\t_attributes="+[_attributes description]; } -@end \ No newline at end of file +@end From a31912f710d0668748c3791e05b83bd906bc0f86 Mon Sep 17 00:00:00 2001 From: daboe01 Date: Sat, 1 Oct 2016 20:11:25 +0200 Subject: [PATCH 18/23] fixed: insertion marker was off by one --- AppKit/CPTextView/CPTextView.j | 1 + 1 file changed, 1 insertion(+) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 39c4d83d0..b8a67371f 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -2326,6 +2326,7 @@ var CPTextViewAllowsUndoKey = @"CPTextViewAllowsUndoKey", - (void)_drawCaretAtLocation:(int)aLoc { var rect = [_textView._layoutManager boundingRectForGlyphRange:CPMakeRange(aLoc, 1) inTextContainer:_textView._textContainer]; + rect.origin.x = CGRectGetMaxX(rect); [self setRect:rect]; } From 5f8d8988e37139162225e9ae5fb45eccfe593b3d Mon Sep 17 00:00:00 2001 From: daboe01 Date: Sat, 1 Oct 2016 20:21:52 +0200 Subject: [PATCH 19/23] revert: move drag indicator uncoditionally to the right side --- AppKit/CPTextView/CPTextView.j | 1 - 1 file changed, 1 deletion(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index b8a67371f..39c4d83d0 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -2326,7 +2326,6 @@ var CPTextViewAllowsUndoKey = @"CPTextViewAllowsUndoKey", - (void)_drawCaretAtLocation:(int)aLoc { var rect = [_textView._layoutManager boundingRectForGlyphRange:CPMakeRange(aLoc, 1) inTextContainer:_textView._textContainer]; - rect.origin.x = CGRectGetMaxX(rect); [self setRect:rect]; } From ec4d29c327249bfa9b0b8c9eb0d4be6d7b2d82c8 Mon Sep 17 00:00:00 2001 From: daboe01 Date: Sun, 2 Oct 2016 10:34:30 +0200 Subject: [PATCH 20/23] fixed: transaction issue from the undo manager --- AppKit/CPTextView/CPTextView.j | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 39c4d83d0..73a14b494 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -2039,9 +2039,12 @@ var kDelegateRespondsTo_textShouldBeginEditing [self _deleteForRange:_selectionRange]; [self setSelectedRange:_movingSelection]; - + var dataForPasting = [pasteboard stringForType:CPRTFPboardType]; - [self insertText:[[_CPRTFParser new] parseRTF:dataForPasting]]; + // setTimeout is to a work around a transaction issue with the undomanager + setTimeout(function(){ + [self insertText:[[_CPRTFParser new] parseRTF:dataForPasting]]; + }, 0); } if ([pasteboard availableTypeFromArray:[CPColorDragType]]) From 9d041c4b624fc3b5a4eda82a234fdc1941e081a3 Mon Sep 17 00:00:00 2001 From: daboe01 Date: Sun, 2 Oct 2016 21:28:38 +0200 Subject: [PATCH 21/23] fixed: unnecessary safety margin for dragview width --- AppKit/CPTextView/CPTextView.j | 1 - 1 file changed, 1 deletion(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 73a14b494..e082cb8d7 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -952,7 +952,6 @@ var kDelegateRespondsTo_textShouldBeginEditing _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]]; From 77031d70824032805ad43f60820973c6e2496235 Mon Sep 17 00:00:00 2001 From: Didier Korthoudt Date: Thu, 6 Oct 2016 22:54:32 +0200 Subject: [PATCH 22/23] Fixed: setFrameSize was calling _updateTrackingAreas too often --- AppKit/CPView.j | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/AppKit/CPView.j b/AppKit/CPView.j index cadcdf356..0b1008501 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -1030,7 +1030,7 @@ var CPViewHighDPIDrawingEnabled = YES; [[self superview] viewFrameChanged:[[CPNotification alloc] initWithName:CPViewFrameDidChangeNotification object:self userInfo:nil]]; if (!_inhibitUpdateTrackingAreas) - [self _updateTrackingAreas]; + [self _updateTrackingAreasWithRecursion:YES]; } /*! @@ -1103,7 +1103,7 @@ var CPViewHighDPIDrawingEnabled = YES; #endif if (!_inhibitUpdateTrackingAreas && !_inhibitFrameAndBoundsChangedNotifications) - [self _updateTrackingAreas]; + [self _updateTrackingAreasWithRecursion:YES]; } /*! @@ -1257,7 +1257,7 @@ var CPViewHighDPIDrawingEnabled = YES; [[self superview] viewFrameChanged:[[CPNotification alloc] initWithName:CPViewFrameDidChangeNotification object:self userInfo:nil]]; if (!_inhibitUpdateTrackingAreas && !_inhibitFrameAndBoundsChangedNotifications) - [self _updateTrackingAreas]; + [self _updateTrackingAreasWithRecursion:!_autoresizesSubviews]; } /*! @@ -1306,7 +1306,7 @@ var CPViewHighDPIDrawingEnabled = YES; [[self superview] viewBoundsChanged:[[CPNotification alloc] initWithName:CPViewBoundsDidChangeNotification object:self userInfo:nil]]; if (!_inhibitUpdateTrackingAreas) - [self _updateTrackingAreas]; + [self _updateTrackingAreasWithRecursion:YES]; } /*! @@ -1374,7 +1374,7 @@ var CPViewHighDPIDrawingEnabled = YES; [[self superview] viewBoundsChanged:[[CPNotification alloc] initWithName:CPViewBoundsDidChangeNotification object:self userInfo:nil]]; if (!_inhibitUpdateTrackingAreas && !_inhibitFrameAndBoundsChangedNotifications) - [self _updateTrackingAreas]; + [self _updateTrackingAreasWithRecursion:YES]; } /*! @@ -1418,7 +1418,7 @@ var CPViewHighDPIDrawingEnabled = YES; [[self superview] viewBoundsChanged:[[CPNotification alloc] initWithName:CPViewBoundsDidChangeNotification object:self userInfo:nil]]; if (!_inhibitUpdateTrackingAreas && !_inhibitFrameAndBoundsChangedNotifications) - [self _updateTrackingAreas]; + [self _updateTrackingAreasWithRecursion:YES]; } @@ -3590,21 +3590,21 @@ setBoundsOrigin: [_trackingAreas removeObjectIdenticalTo:trackingArea]; } -- (void)_updateTrackingAreas +- (void)_updateTrackingAreasWithRecursion:(BOOL)shouldCallRecursively { _inhibitUpdateTrackingAreas = YES; - [self _recursivelyUpdateTrackingAreas]; - - _inhibitUpdateTrackingAreas = NO; -} - -- (void)_recursivelyUpdateTrackingAreas -{ [self _updateTrackingAreasForOwners:[self _calcTrackingAreaOwners]]; - for (var i = 0; i < _subviews.length; i++) - [_subviews[i] _recursivelyUpdateTrackingAreas]; + if (shouldCallRecursively) + { + // Now, call _updateTrackingAreasWithRecursion on subviews + + for (var i = 0; i < _subviews.length; i++) + [_subviews[i] _updateTrackingAreasWithRecursion:YES]; + } + + _inhibitUpdateTrackingAreas = NO; } - (CPArray)_calcTrackingAreaOwners From e0fab808b96c440ba82b101819257189f581d22d Mon Sep 17 00:00:00 2001 From: Didier Korthoudt Date: Sat, 8 Oct 2016 17:33:21 +0200 Subject: [PATCH 23/23] fix-overlappingTA-could-be-empty --- AppKit/CPWindow/CPWindow.j | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index 380b2b149..fd1a0b469 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -4098,6 +4098,9 @@ var interpolate = function(fromValue, toValue, progress) [overlappingTrackingAreas addObject:aTrackingArea]; } + if (overlappingTrackingAreas.length === 0) + return; + var frontmostTrackingArea = overlappingTrackingAreas[0], frontmostView = [frontmostTrackingArea view];