From 07a0be303fa42bcb52acfbcc4108c8f81c3439eb Mon Sep 17 00:00:00 2001 From: daboe01 Date: Fri, 23 May 2014 21:46:59 +0200 Subject: [PATCH] smart cutting+cleanup --- AppKit/CPTextView/CPTextView.j | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index bc504c2d6..63643caf5 100755 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -27,8 +27,6 @@ @import "CPTextStorage.j" @import "CPTextContainer.j" @import "CPFontManager.j" -//@import "_CPRTFProducer.j" -//@import "_CPRTFParser.j" @import "CPLayoutManager.j" @class _CPRTFProducer; @@ -128,16 +126,6 @@ var kDelegateRespondsTo_textShouldBeginEditing CPLog.error(@"-[CPText " + _cmd + "] subclass responsibility"); } -- (void)cut:(id)sender -{ - [self copy:sender]; - - var loc = [self selectedRange].location; - - [self replaceCharactersInRange:[self selectedRange] withString:""]; - [self setSelectedRange:CPMakeRange(loc,0) ]; -} - - (void)delete:(id)sender { CPLog.error(@"-[CPText "+_cmd+"] subclass responsibility"); @@ -291,6 +279,7 @@ var kDelegateRespondsTo_textShouldBeginEditing CPRange _selectionRange; CPDictionary _selectedTextAttributes; int _selectionGranularity; + int _previousSelectionGranularity; CPColor _insertionPointColor; @@ -831,6 +820,7 @@ var kDelegateRespondsTo_textShouldBeginEditing - (void)mouseUp:(CPEvent)event { + _previousSelectionGranularity = [self selectionGranularity]; /* will post CPTextViewDidChangeSelectionNotification */ [self setSelectionGranularity:CPSelectByCharacter]; [self setSelectedRange:[self selectedRange] affinity:0 stillSelecting:NO]; @@ -1273,6 +1263,11 @@ var kDelegateRespondsTo_textShouldBeginEditing else changedRange = _selectionRange; + if (_previousSelectionGranularity > 0 && + changedRange.location > 0 && [self _isCharacterAtIndex:changedRange.location-1 granularity:_previousSelectionGranularity] && + changedRange.location < [[self string] length] && [self _isCharacterAtIndex:CPMaxRange(changedRange) granularity:_previousSelectionGranularity]) + changedRange.length++; + [self _deleteForRange:changedRange]; }