Permalink
Browse files

if you don't like the backward delete behavior, then define SPECIAL_D…

…ELETE_FOR_SPACES_ONLY.

avoided the case in which adding or deleting characters (e.g., by tabbing) caused the insertion point to move into the automatic range, whereupon no more tabbing could be performed
  • Loading branch information...
1 parent 770d451 commit 302645511bc62e1d35200c9de2f0d4be232cc2ac Zachary Schneirov committed Feb 2, 2010
Showing with 20 additions and 4 deletions.
  1. +1 −0 LinkingEditor.h
  2. +19 −4 LinkingEditor.m
View
@@ -26,6 +26,7 @@
BOOL didRenderFully;
#endif
+ BOOL didChangeIntoAutomaticRange;
NSRange lastAutomaticallySelectedRange;
NSRange changedRange;
View
@@ -741,6 +741,7 @@ - (NSRange)selectedRangeWasAutomatic:(BOOL*)automatic {
- (void)setAutomaticallySelectedRange:(NSRange)newRange {
lastAutomaticallySelectedRange = newRange;
+ didChangeIntoAutomaticRange = NO;
[self setSelectedRange:newRange];
}
@@ -873,10 +874,11 @@ - (void)insertTab:(id)sender {
BOOL wasAutomatic = NO;
[self selectedRangeWasAutomatic:&wasAutomatic];
- if ([prefsController tabKeyIndents] && (!wasAutomatic || ![[self string] length]))
- [self insertTabIgnoringFieldEditor:sender];
- else
+ if ([prefsController tabKeyIndents] && (!wasAutomatic || ![[self string] length] || didChangeIntoAutomaticRange)) {
+ [self insertTabIgnoringFieldEditor:sender];
+ } else {
[[self window] selectNextKeyView:self];
+ }
}
- (void)insertBacktab:(id)sender {
@@ -917,7 +919,7 @@ - (void)insertTabIgnoringFieldEditor:(id)sender {
[self insertText:spacesString];
[spacesString release];
} else {
- [super insertText:@"\t"];
+ [self insertText:@"\t"];
}
}
@@ -949,6 +951,15 @@ - (void)deleteBackward:(id)sender {
// Not in leading whitespace. Delete normally.
[super deleteBackward:sender];
} else {
+#if SPECIAL_DELETE_FOR_SPACES_ONLY
+ NSString *leadingSpaceString = [string substringWithRange:leadingSpaceRange];
+ if ([leadingSpaceString rangeOfString:@"\t"].location != NSNotFound) {
+ //thar actually be tabs here; revert to normal backwards-deletion
+ [super deleteBackward:sender];
+ return;
+ }
+#endif
+
NSTextStorage *text = [self textStorage];
unsigned leadingIndents = leadingSpaces / indentWidth;
NSString *replaceString;
@@ -1165,6 +1176,10 @@ - (void)didChangeText {
//[[self window] invalidateCursorRectsForView:self];
[super didChangeText];
+
+ //if the result of changing the text caused us to move into the automatic range, then temporarily ignore the automatic range
+ //don't use -selectedRangeWasAutomatic: as it consults didRenderFully, which might not be true here
+ didChangeIntoAutomaticRange = NSEqualRanges(lastAutomaticallySelectedRange, [self selectedRange]);
}
- (BOOL)shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString {

0 comments on commit 3026455

Please sign in to comment.