From 1a7ced34a7d65ffa40c3e8d60f79caa2d49859a4 Mon Sep 17 00:00:00 2001 From: daboe01 Date: Thu, 13 Jun 2019 16:17:52 +0200 Subject: [PATCH] Fixed: smart copy/paste cycle was leaving an additional whitespace on the LHS (#2776) --- AppKit/CPTextView/CPTextView.j | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 5e7be1de1..c71544bf3 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -467,12 +467,20 @@ var kDelegateRespondsTo_textShouldBeginEditing var shouldUseSmartPasting = [self _shouldUseSmartPasting]; - if (shouldUseSmartPasting && _selectionRange.location > 0) + if (shouldUseSmartPasting) { - if (!_isWhitespaceCharacter([[_textStorage string] characterAtIndex:_selectionRange.location - 1]) && - _selectionRange.location != [_layoutManager numberOfCharacters]) + if (_isWhitespaceCharacter([[stringForPasting string] characterAtIndex:0])) { - [self insertText:" "]; + if (_selectionRange.location == 0 || + _isWhitespaceCharacter([[_textStorage string] characterAtIndex:_selectionRange.location - 1]) && + _selectionRange.location != [_layoutManager numberOfCharacters]) + [stringForPasting deleteCharactersInRange:CPMakeRange(0, 1)]; + } + else + { + if (_selectionRange.location > 0 & + !_isWhitespaceCharacter([[_textStorage string] characterAtIndex:_selectionRange.location - 1])) + [self insertText:" "]; } }