From 251ee4d4912701726ea0dc75dc56d9ecae688b10 Mon Sep 17 00:00:00 2001 From: Wolfgang Lux Date: Sun, 26 Jun 2011 09:12:40 +0000 Subject: [PATCH] Fix implementation of NSTextView -deleteToEndOfLine: to work in the same way as under Emacs and OS X. In particular, the action now deletes the newline character when the insertion point is at the end of a line. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33377 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 ++++++ Source/NSTextView_actions.m | 47 ++++++++++++++----------------------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1bce01eb1..597c296be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-06-26 Wolfgang Lux + + * Source/NSTextView_actions.m (-deleteToEndOfLine:): Fix + implementation to work in the same way as under Emacs and OS X. + In particular, the action now deletes the newline character when + the insertion point is at the end of a line. + 2011-06-22 Fred Kiefer * Headers/AppKit/NSPrintPanel.h: Add missing APPKIT_EXPORT for new diff --git a/Source/NSTextView_actions.m b/Source/NSTextView_actions.m index bd13ed765..2223ab9d9 100644 --- a/Source/NSTextView_actions.m +++ b/Source/NSTextView_actions.m @@ -677,9 +677,6 @@ static NSNumber *float_plus_one(NSNumber *cur) - (void) deleteToEndOfLine: (id)sender { NSRange range = [self rangeForUserTextChange]; - NSRange linerange; - unsigned maxRange; - unsigned endCorrection = 0; NSDictionary *attributes; if (range.location == NSNotFound) @@ -687,39 +684,31 @@ static NSNumber *float_plus_one(NSNumber *cur) return; } - linerange = [[_textStorage string] lineRangeForRange: - NSMakeRange(range.location, 0)]; - maxRange = NSMaxRange (linerange); - - if (maxRange == range.location) + /* If the selection is not empty delete it, otherwise delete up to the + next line end from the insertion point or the delete the line end + itself when the insertion point is already at the end of the line. */ + if (range.length == 0) { - return; - } + NSUInteger start, end, contentsEnd; - // Only delete the linebreak, if the line is empty. - if (linerange.length > 1) - { - // Treat the last line special, as it does not have to end in a leine break. - if (maxRange == [_textStorage length]) - { - unichar u = [[_textStorage string] characterAtIndex: (maxRange - 1)]; - if (u == '\n' || u == '\r') - { - endCorrection = 1; - } - else - { - endCorrection = 0; - } + [[_textStorage string] getLineStart: &start + end: &end + contentsEnd: &contentsEnd + forRange: range]; + if (range.location == contentsEnd) + { + range = NSMakeRange(contentsEnd, end - contentsEnd); } else - { - endCorrection = 1; + { + range.length = contentsEnd - range.location; + } + if (range.length == 0) + { + return; } } - range = NSMakeRange(range.location, maxRange - range.location - endCorrection); - if (![self shouldChangeTextInRange: range replacementString: @""]) { return;