From c5c42bd427eec86e5eebc2c97ffdcd54cb932fdc Mon Sep 17 00:00:00 2001 From: wlux Date: Sun, 26 Jun 2011 09:20:01 +0000 Subject: [PATCH] Implement NSTextView -deleteToEndOfParagraph:, which was introduced in OS X 10.3. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33378 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 ++++ Source/NSTextView_actions.m | 52 +++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/ChangeLog b/ChangeLog index 597c296be..5d6dba38e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-26 Wolfgang Lux + + * Source/NSTextView_actions.m (-deleteToEndOfParagraph:): + Implement method, which was introduced in OS X 10.3. + 2011-06-26 Wolfgang Lux * Source/NSTextView_actions.m (-deleteToEndOfLine:): Fix diff --git a/Source/NSTextView_actions.m b/Source/NSTextView_actions.m index 2223ab9d9..188ce19e6 100644 --- a/Source/NSTextView_actions.m +++ b/Source/NSTextView_actions.m @@ -725,6 +725,58 @@ static NSNumber *float_plus_one(NSNumber *cur) [self didChangeText]; } +- (void) deleteToEndOfParagraph: (id)sender +{ + NSRange range = [self rangeForUserTextChange]; + NSDictionary *attributes; + + if (range.location == NSNotFound) + { + return; + } + + /* If the selection is not empty delete it, otherwise delete up to + the next paragraph end from the insertion point or the delete the + paragraph end itself when the insertion point is already at the + end of the paragraph. */ + if (range.length == 0) + { + NSUInteger start, end, contentsEnd; + + [[_textStorage string] getParagraphStart: &start + end: &end + contentsEnd: &contentsEnd + forRange: range]; + if (range.location == contentsEnd) + { + range = NSMakeRange(contentsEnd, end - contentsEnd); + } + else + { + range.length = contentsEnd - range.location; + } + if (range.length == 0) + { + return; + } + } + + if (![self shouldChangeTextInRange: range replacementString: @""]) + { + return; + } + + ASSIGN(killBuffer, [[_textStorage string] substringWithRange: range]); + attributes = RETAIN([_textStorage attributesAtIndex: range.location + effectiveRange: NULL]); + [_textStorage beginEditing]; + [_textStorage deleteCharactersInRange: range]; + [_textStorage endEditing]; + [self setTypingAttributes: attributes]; + RELEASE(attributes); + [self didChangeText]; +} + - (void) yank: (id)sender { [self insertText: killBuffer];