Changeset 274
- Timestamp:
- 01/01/08 07:05:49 (1 year ago)
- Files:
-
- trunk/cocoa/JRShellView/JRShellView.m (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cocoa/JRShellView/JRShellView.m
r273 r274 2 2 3 3 #define PROMPT @">" 4 5 typedef enum { 6 JRShellView_HistorySection, 7 JRShellView_PromptSection, 8 JRShellView_CommandSection 9 } JRShellView_Section; 4 10 5 11 @interface JRShellView (Private) 6 12 - (void)commonInit; 7 13 - (NSString*)calcCurrentCommandString; 14 - (void)setCurrentCommandString:(NSString*)command_; 8 15 - (void)loadHistoricCommandFromCurrentCommandHistoryIndex; 9 16 - (void)insertPrompt; 17 - (JRShellView_Section)selectionSection; 18 - (BOOL)selectionIsInImmutableSection; 10 19 @end 11 20 … … 39 48 } 40 49 41 if ( (([event_ modifierFlags] & NSFunctionKeyMask) != NSFunctionKeyMask) && [self selectedRange].location < commandStart) {50 if (!([event_ modifierFlags] & NSFunctionKeyMask) && [self selectionIsInImmutableSection]) { 42 51 // User is typing while selection is in the immutable section of the text view. 43 52 // Cope by moving the selection to the end of the current command before letting the keyDown through. … … 76 85 77 86 - (void)moveUp:(id)sender_ { // up 78 if ([self select edRange].location < commandStart) {87 if ([self selectionIsInImmutableSection]) { 79 88 // Selection is before the command section. Act normally. 80 89 [super moveUp:sender_]; … … 83 92 // User wishes to save off his uncompleted command (if any) and load previous-historic command. 84 93 if ([commandHistory count]) { 85 if ([ [self string] length] > [self selectedRange].location) {94 if ([self calcCurrentCommandString]) { 86 95 [uncompletedCommand release]; 87 96 uncompletedCommand = [[self calcCurrentCommandString] retain]; … … 140 149 141 150 - (void)moveDown:(id)sender_ { // down 142 if ([self select edRange].location < commandStart) {151 if ([self selectionIsInImmutableSection]) { 143 152 // Selection is before the command section. Act normally. 144 153 [super moveDown:sender_]; … … 151 160 if (currentCommandHistoryIndex == ([commandHistory count]-1)) { 152 161 // 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 } 154 170 } else { 155 171 ++currentCommandHistoryIndex; … … 360 376 } 361 377 362 - (void) loadHistoricCommandFromCurrentCommandHistoryIndex{378 - (void)setCurrentCommandString:(NSString*)command_ { 363 379 [self setSelectedRange:NSMakeRange(commandStart,[[self string] length])]; 364 [self insertText: [commandHistory objectAtIndex:currentCommandHistoryIndex]];380 [self insertText:command_]; 365 381 [self moveToEndOfDocument:self]; 366 382 [self scrollRangeToVisible:[self selectedRange]]; 367 383 } 368 384 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 369 413 @end
