Changeset 275

Show
Ignore:
Timestamp:
01/01/08 09:04:11 (1 year ago)
Author:
wolf
Message:

[NEW] JRShellView:
- Completed left+right-moving logic.
- Add NSText (UndocumentedSelectionMovement?) category to suppress compiler warnings.
- Disable debug logging of -doCommandBySelector:
- Allow left-arrow when it wouldn't otherwise be allowed (selection directly to right of prompt section) when the selection's length is nonzero. Otherwise you can't kill the selection with the left arrow key when the whole command is selected.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cocoa/JRShellView/JRShellView.m

    r274 r275  
    11#import "JRShellView.h" 
     2 
     3@interface NSText (UndocumentedSelectionMovement) 
     4- (IBAction)moveParagraphBackwardAndModifySelection:(id)sender; 
     5- (IBAction)moveToBeginningOfDocumentAndModifySelection:(id)sender; 
     6- (IBAction)moveParagraphForwardAndModifySelection:(id)sender; 
     7- (IBAction)moveToEndOfDocumentAndModifySelection:(id)sender; 
     8- (IBAction)moveToBeginningOfLineAndModifySelection:(id)sender; 
     9- (IBAction)pageUpAndModifySelection:(id)sender; 
     10- (IBAction)pageDownAndModifySelection:(id)sender; 
     11@end 
    212 
    313#define PROMPT @">" 
     
    1727- (JRShellView_Section)selectionSection; 
    1828- (BOOL)selectionIsInImmutableSection; 
     29- (BOOL)canMoveSelectionBackwards; 
    1930@end 
    2031 
     
    5768} 
    5869 
     70#if 0 
    5971- (void)doCommandBySelector:(SEL)selector_ { 
    6072    NSLog(@"doCommandBySelector %@", NSStringFromSelector(selector_)); 
    6173    [super doCommandBySelector:selector_]; 
    6274} 
     75#endif 
    6376 
    6477#pragma mark Misc 
     
    210223 
    211224- (void)moveLeft:(id)sender_ { // left 
    212         NSLog(@"TODO moveLeft:"); 
    213        [super moveLeft:sender_]; 
     225    if ([self canMoveSelectionBackwards]) 
     226        [super moveLeft:sender_]; 
    214227} 
    215228- (void)moveToBeginningOfLine:(id)sender_ { // ctl-left, cmd-left 
    216         NSLog(@"TODO moveToBeginningOfLine:"); 
    217         [super moveToBeginningOfLine:sender_]; 
     229    if ([self selectionSection] == JRShellView_CommandSection) { 
     230        if ([[NSApp currentEvent] modifierFlags] & NSControlKeyMask) { 
     231            //  Ctl-left. TODO implement moveSubWordBackward: but for now just implement in terms of moveLeft. 
     232            [self moveLeft:sender_]; 
     233        } else { 
     234            [self setSelectedRange:NSMakeRange(commandStart, 0)]; 
     235        } 
     236    } else { 
     237        [super moveToBeginningOfLine:sender_]; 
     238    } 
    218239} 
    219240- (void)moveWordLeft:(id)sender_ { // opt-left 
    220         NSLog(@"TODO moveWordLeft:"); 
    221        [super moveWordLeft:sender_]; 
     241    if ([self canMoveSelectionBackwards]) 
     242        [super moveWordLeft:sender_]; 
    222243} 
    223244- (void)moveLeftAndModifySelection:(id)sender_ { // shift-left 
    224         NSLog(@"TODO moveLeftAndModifySelection:"); 
    225        [super moveLeftAndModifySelection:sender_]; 
     245    if ([self canMoveSelectionBackwards]) 
     246        [super moveLeftAndModifySelection:sender_]; 
    226247} 
    227248- (void)moveToBeginningOfLineAndModifySelection:(id)sender_ { // ctl-shift-left, cmd-shift-left 
    228         NSLog(@"TODO moveToBeginningOfLineAndModifySelection:"); 
    229         [super moveToBeginningOfLineAndModifySelection:sender_]; 
     249    if ([self selectionSection] == JRShellView_CommandSection) { 
     250        if ([[NSApp currentEvent] modifierFlags] & NSControlKeyMask) { 
     251            //  Ctl-left. TODO implement moveSubWordBackwardAndModifySelection: but for now just implement in terms of moveLeftAndModifySelection. 
     252            [self moveLeftAndModifySelection:sender_]; 
     253        } else { 
     254            unsigned oldSelectionLocation = [self selectedRange].location; 
     255            [self setSelectedRange:NSMakeRange(commandStart, (oldSelectionLocation - commandStart))]; 
     256        } 
     257    } else { 
     258        [super moveToBeginningOfLineAndModifySelection:sender_]; 
     259    } 
    230260} 
    231261- (void)moveWordLeftAndModifySelection:(id)sender_ { // opt-shift-left 
    232     if ([self selectedRange].location > commandStart
     262    if ([self canMoveSelectionBackwards]
    233263        [super moveWordLeftAndModifySelection:sender_]; 
    234264} 
    235265- (void)changeBaseWritingDirectionToRTL:(id)sender_ { // cmd-ctl-left, cmd-ctl-shift-left 
    236         NSLog(@"TODO changeBaseWritingDirectionToRTL:"); 
    237         [super changeBaseWritingDirectionToRTL:sender_]; 
     266    //  Changing writing direction doesn't make sense to a shell, so implement in terms of moveLeft. 
     267    if ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask) 
     268        [self moveLeftAndModifySelection:sender_]; 
     269    else 
     270        [self moveLeft:sender_]; 
    238271} 
    239272 
    240273#pragma mark Right 
     274 
     275#ifdef CommandsWeJustLetPassThrough 
    241276 
    242277- (void)moveRight:(id)sender_ { // right 
     
    264299        [super moveWordRightAndModifySelection:sender_]; 
    265300} 
     301 
     302#endif 
     303 
    266304- (void)changeBaseWritingDirectionToLTR:(id)sender_ { // cmd-ctl-right, cmd-ctl-shift-right 
    267         NSLog(@"TODO changeBaseWritingDirectionToLTR:"); 
    268         [super changeBaseWritingDirectionToLTR:sender_]; 
    269 
     305        //  Changing writing direction doesn't make sense to a shell, so implement in terms of moveRight. 
     306    if ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask) 
     307        [self moveRightAndModifySelection:sender_]; 
     308    else 
     309        [self moveRight:sender_]; 
     310
     311 
     312#ifdef CommandsWeJustLetPassThrough 
    270313 
    271314#pragma mark pageUp 
     
    291334} 
    292335 
    293 #pragma mark - 
    294 #pragma mark OLD 
    295 #pragma mark -  
    296  
    297 #if 0 
    298  
    299 - (void)moveToBeginningOfLine:(id)sender_ { // [cmd|ctl] <- (left arrow) 
    300     [self setSelectedRange:NSMakeRange(start,0)]; 
    301 } 
    302  
    303 - (void)moveToEndOfLine:(id)sender_ { // [cmd|ctl] -> (right arrow) 
    304     [self moveToEndOfDocument:sender_]; 
    305 } 
    306  
    307 - (void)moveToBeginningOfParagraph:(id)sender_ { // ctrl-a 
    308     NSLog(@"moveToBeginningOfParagraph"); moveToBeginningOfDocumentAndModifySelection 
    309     [self setSelectedRange:NSMakeRange(start,0)]; 
    310 } 
    311  
    312 - (void)moveToEndOfParagraph:(id)sender_ { // ctrl-e 
    313     [self moveToEndOfDocument:sender_]; 
    314 } 
    315  
    316 - (void)moveLeft:(id)sender_ { 
    317 } 
    318  
    319 - (void)moveWordLeftAndModifySelection:(id)sender_ { 
    320     if ([self selectedRange].location > start) 
    321         [super moveWordLeftAndModifySelection:sender_]; 
    322 } 
    323  
    324 - (void)moveWordLeft:(id)sender_ { 
    325     if ([self selectedRange].location > start) 
    326         [super moveWordLeft:sender_]; 
    327 } 
    328  
    329 - (void)moveUp:(id)sender_ { 
    330     NSLog(@"TODO moveUp"); 
    331     [super moveUp:sender_]; 
    332 } 
    333  
    334 - (void)moveDown:(id)sender_ { 
    335     NSLog(@"TODO moveDown"); 
    336     [super moveDown:sender_]; 
    337 } 
    338336#endif 
    339337 
     
    411409} 
    412410 
     411- (BOOL)canMoveSelectionBackwards { 
     412    switch ([self selectionSection]) { 
     413        case JRShellView_HistorySection: 
     414        case JRShellView_PromptSection: 
     415            return YES; 
     416        case JRShellView_CommandSection: { 
     417            NSRange range = [self selectedRange]; 
     418            return range.length ? YES : [self selectedRange].location > commandStart; 
     419        }   break; 
     420        default: 
     421            assert(!"unknown JRShellView_Section"); 
     422            return NO; 
     423    } 
     424} 
     425 
    413426@end