Changeset 275
- Timestamp:
- 01/01/08 09:04:11 (1 year ago)
- Files:
-
- trunk/cocoa/JRShellView/JRShellView.m (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cocoa/JRShellView/JRShellView.m
r274 r275 1 1 #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 2 12 3 13 #define PROMPT @">" … … 17 27 - (JRShellView_Section)selectionSection; 18 28 - (BOOL)selectionIsInImmutableSection; 29 - (BOOL)canMoveSelectionBackwards; 19 30 @end 20 31 … … 57 68 } 58 69 70 #if 0 59 71 - (void)doCommandBySelector:(SEL)selector_ { 60 72 NSLog(@"doCommandBySelector %@", NSStringFromSelector(selector_)); 61 73 [super doCommandBySelector:selector_]; 62 74 } 75 #endif 63 76 64 77 #pragma mark Misc … … 210 223 211 224 - (void)moveLeft:(id)sender_ { // left 212 NSLog(@"TODO moveLeft:"); 213 [super moveLeft:sender_];225 if ([self canMoveSelectionBackwards]) 226 [super moveLeft:sender_]; 214 227 } 215 228 - (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 } 218 239 } 219 240 - (void)moveWordLeft:(id)sender_ { // opt-left 220 NSLog(@"TODO moveWordLeft:"); 221 [super moveWordLeft:sender_];241 if ([self canMoveSelectionBackwards]) 242 [super moveWordLeft:sender_]; 222 243 } 223 244 - (void)moveLeftAndModifySelection:(id)sender_ { // shift-left 224 NSLog(@"TODO moveLeftAndModifySelection:"); 225 [super moveLeftAndModifySelection:sender_];245 if ([self canMoveSelectionBackwards]) 246 [super moveLeftAndModifySelection:sender_]; 226 247 } 227 248 - (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 } 230 260 } 231 261 - (void)moveWordLeftAndModifySelection:(id)sender_ { // opt-shift-left 232 if ([self selectedRange].location > commandStart)262 if ([self canMoveSelectionBackwards]) 233 263 [super moveWordLeftAndModifySelection:sender_]; 234 264 } 235 265 - (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_]; 238 271 } 239 272 240 273 #pragma mark Right 274 275 #ifdef CommandsWeJustLetPassThrough 241 276 242 277 - (void)moveRight:(id)sender_ { // right … … 264 299 [super moveWordRightAndModifySelection:sender_]; 265 300 } 301 302 #endif 303 266 304 - (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 270 313 271 314 #pragma mark pageUp … … 291 334 } 292 335 293 #pragma mark -294 #pragma mark OLD295 #pragma mark -296 297 #if 0298 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-a308 NSLog(@"moveToBeginningOfParagraph"); moveToBeginningOfDocumentAndModifySelection309 [self setSelectedRange:NSMakeRange(start,0)];310 }311 312 - (void)moveToEndOfParagraph:(id)sender_ { // ctrl-e313 [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 }338 336 #endif 339 337 … … 411 409 } 412 410 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 413 426 @end
