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
This commit is contained in:
Wolfgang Lux 2011-06-26 09:12:40 +00:00
parent 425c40b07c
commit 251ee4d491
2 changed files with 25 additions and 29 deletions

View file

@ -1,3 +1,10 @@
2011-06-26 Wolfgang Lux <wolfgang.lux@gmail.com>
* 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 <FredKiefer@gmx.de> 2011-06-22 Fred Kiefer <FredKiefer@gmx.de>
* Headers/AppKit/NSPrintPanel.h: Add missing APPKIT_EXPORT for new * Headers/AppKit/NSPrintPanel.h: Add missing APPKIT_EXPORT for new

View file

@ -677,9 +677,6 @@ static NSNumber *float_plus_one(NSNumber *cur)
- (void) deleteToEndOfLine: (id)sender - (void) deleteToEndOfLine: (id)sender
{ {
NSRange range = [self rangeForUserTextChange]; NSRange range = [self rangeForUserTextChange];
NSRange linerange;
unsigned maxRange;
unsigned endCorrection = 0;
NSDictionary *attributes; NSDictionary *attributes;
if (range.location == NSNotFound) if (range.location == NSNotFound)
@ -687,39 +684,31 @@ static NSNumber *float_plus_one(NSNumber *cur)
return; return;
} }
linerange = [[_textStorage string] lineRangeForRange: /* If the selection is not empty delete it, otherwise delete up to the
NSMakeRange(range.location, 0)]; next line end from the insertion point or the delete the line end
maxRange = NSMaxRange (linerange); itself when the insertion point is already at the end of the line. */
if (range.length == 0)
if (maxRange == range.location)
{ {
return; NSUInteger start, end, contentsEnd;
}
// Only delete the linebreak, if the line is empty. [[_textStorage string] getLineStart: &start
if (linerange.length > 1) end: &end
{ contentsEnd: &contentsEnd
// Treat the last line special, as it does not have to end in a leine break. forRange: range];
if (maxRange == [_textStorage length]) if (range.location == contentsEnd)
{ {
unichar u = [[_textStorage string] characterAtIndex: (maxRange - 1)]; range = NSMakeRange(contentsEnd, end - contentsEnd);
if (u == '\n' || u == '\r')
{
endCorrection = 1;
}
else
{
endCorrection = 0;
}
} }
else 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: @""]) if (![self shouldChangeTextInRange: range replacementString: @""])
{ {
return; return;