smart paste fix

This commit is contained in:
daboe01 committed 2015-06-12 17:28:48 +02:00
1 parent 1476fda014
commit cde83e9d7d
2 files changed
+41 -4

No files matched your search

+9 -2
View File
@@ -149,18 +149,25 @@ CPKernAttributeName = @"CPKernAttributeName";
}
}
- (void)paste:(id)sender
- (id)_stringForPasting
{
var pasteboard = [CPPasteboard generalPasteboard],
// dataForPasting = [pasteboard dataForType:CPRichStringPboardType],
stringForPasting = [pasteboard stringForType:CPStringPboardType];
if ([stringForPasting hasPrefix:"{\\rtf1\\ansi"])
if ([stringForPasting hasPrefix:"{\\rtf1\\ansi"])
stringForPasting = [[_CPRTFParser new] parseRTF:stringForPasting];
if (![self isRichText] && [stringForPasting isKindOfClass:[CPAttributedString class]])
stringForPasting = stringForPasting._string;
return stringForPasting;
}
- (void)paste:(id)sender
{
var stringForPasting = [self _stringForPasting];
if (stringForPasting)
[self insertText:stringForPasting];
}
+32 -2
View File
@@ -224,18 +224,48 @@ var kDelegateRespondsTo_textShouldBeginEditing
{
[[_window platformWindow] _propagateCurrentDOMEvent:NO]; // prevent double pasting from the additional 'synthetic' paste event
var stringForPasting = [self _stringForPasting];
if (!stringForPasting)
return;
if (_copySelectionGranularity > 0 && _selectionRange.location > 0)
{
if (!_isWhitespaceCharacter([[_textStorage string] characterAtIndex:_selectionRange.location - 1]))
{
[self insertText:" "];
}
}
[super paste:sender];
if (_copySelectionGranularity == CPSelectByParagraph)
{
var peekStr = stringForPasting,
i = 0;
if (![stringForPasting isKindOfClass:[CPString class]])
peekStr = stringForPasting._string;
while (_isWhitespaceCharacter([peekStr characterAtIndex:i]))
i++;
if (i)
{
if ([stringForPasting isKindOfClass:[CPString class]])
stringForPasting = [stringForPasting stringByReplacingCharactersInRange:CPMakeRange(0, i) withString:''];
else
[stringForPasting replaceCharactersInRange:CPMakeRange(0, i) withString:''];
}
}
[self insertText:stringForPasting];
if (_copySelectionGranularity > 0)
{
if (!_isWhitespaceCharacter([[_textStorage string] characterAtIndex:CPMaxRange(_selectionRange)]) && !_isNewlineCharacter([[_textStorage string] characterAtIndex:MAX(0, _selectionRange.location - 1)]))
if (!_isWhitespaceCharacter([[_textStorage string] characterAtIndex:CPMaxRange(_selectionRange)]) &&
!_isNewlineCharacter([[_textStorage string] characterAtIndex:MAX(0, _selectionRange.location - 1)]))
{
[self insertText:" "];
}
}
}