mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-29 20:17:38 +00:00
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:
parent
425c40b07c
commit
251ee4d491
2 changed files with 25 additions and 29 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue