Changeset 274

Show
Ignore:
Timestamp:
01/01/08 07:05:49 (1 year ago)
Author:
wolf
Message:

[NEW] JRShellView: add previous uncompleted-command reinsertion upon down-arrow.

Files:

Legend:

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

    r273 r274  
    22 
    33#define PROMPT @">" 
     4 
     5typedef enum { 
     6    JRShellView_HistorySection, 
     7    JRShellView_PromptSection, 
     8    JRShellView_CommandSection 
     9}   JRShellView_Section; 
    410 
    511@interface JRShellView (Private) 
    612- (void)commonInit; 
    713- (NSString*)calcCurrentCommandString; 
     14- (void)setCurrentCommandString:(NSString*)command_; 
    815- (void)loadHistoricCommandFromCurrentCommandHistoryIndex; 
    916- (void)insertPrompt; 
     17- (JRShellView_Section)selectionSection; 
     18- (BOOL)selectionIsInImmutableSection; 
    1019@end 
    1120 
     
    3948    } 
    4049     
    41     if ((([event_ modifierFlags] & NSFunctionKeyMask) != NSFunctionKeyMask) && [self selectedRange].location < commandStart) { 
     50    if (!([event_ modifierFlags] & NSFunctionKeyMask) && [self selectionIsInImmutableSection]) { 
    4251        // User is typing while selection is in the immutable section of the text view. 
    4352        // Cope by moving the selection to the end of the current command before letting the keyDown through. 
     
    7685 
    7786- (void)moveUp:(id)sender_ { // up 
    78     if ([self selectedRange].location < commandStart) { 
     87    if ([self selectionIsInImmutableSection]) { 
    7988        //  Selection is before the command section. Act normally. 
    8089        [super moveUp:sender_]; 
     
    8392            //  User wishes to save off his uncompleted command (if any) and load previous-historic command. 
    8493            if ([commandHistory count]) { 
    85                 if ([[self string] length] > [self selectedRange].location) { 
     94                if ([self calcCurrentCommandString]) { 
    8695                    [uncompletedCommand release]; 
    8796                    uncompletedCommand = [[self calcCurrentCommandString] retain]; 
     
    140149 
    141150- (void)moveDown:(id)sender_ { // down 
    142     if ([self selectedRange].location < commandStart) { 
     151    if ([self selectionIsInImmutableSection]) { 
    143152        //  Selection is before the command section. Act normally. 
    144153        [super moveDown:sender_]; 
     
    151160            if (currentCommandHistoryIndex == ([commandHistory count]-1)) { 
    152161                //  No more historic commands. 
    153                 NSBeep(); 
     162                if (uncompletedCommand) { 
     163                    //  We have an previously uncompleted command. Reload it now. 
     164                    [self setCurrentCommandString:uncompletedCommand]; 
     165                    [uncompletedCommand release]; uncompletedCommand = nil; 
     166                } else { 
     167                    //  Nothing left. 
     168                    NSBeep(); 
     169                } 
    154170            } else { 
    155171                ++currentCommandHistoryIndex; 
     
    360376} 
    361377 
    362 - (void)loadHistoricCommandFromCurrentCommandHistoryIndex
     378- (void)setCurrentCommandString:(NSString*)command_
    363379    [self setSelectedRange:NSMakeRange(commandStart,[[self string] length])]; 
    364     [self insertText:[commandHistory objectAtIndex:currentCommandHistoryIndex]]; 
     380    [self insertText:command_]; 
    365381    [self moveToEndOfDocument:self]; 
    366382    [self scrollRangeToVisible:[self selectedRange]]; 
    367383} 
    368384 
     385- (void)loadHistoricCommandFromCurrentCommandHistoryIndex { 
     386    [self setCurrentCommandString:[commandHistory objectAtIndex:currentCommandHistoryIndex]]; 
     387} 
     388 
     389- (JRShellView_Section)selectionSection { 
     390    unsigned selectionLocation = [self selectedRange].location; 
     391    if (selectionLocation >= commandStart) { 
     392        return JRShellView_CommandSection; 
     393    } else if (selectionLocation >= (commandStart - ([PROMPT length]+1))) { 
     394        return JRShellView_PromptSection; 
     395    } else { 
     396        return JRShellView_HistorySection; 
     397    } 
     398} 
     399 
     400- (BOOL)selectionIsInImmutableSection { 
     401    switch ([self selectionSection]) { 
     402        case JRShellView_HistorySection: 
     403        case JRShellView_PromptSection: 
     404            return YES; 
     405        case JRShellView_CommandSection: 
     406            return NO; 
     407        default: 
     408            assert(!"unknown JRShellView_Section"); 
     409            return NO; 
     410    }  
     411} 
     412 
    369413@end