diff --git a/src/MacVim/MMTextView.h b/src/MacVim/MMTextView.h index 7e40a4a631..040af3011a 100644 --- a/src/MacVim/MMTextView.h +++ b/src/MacVim/MMTextView.h @@ -28,6 +28,7 @@ NSTextField *markedTextField; int preEditRow; int preEditColumn; + int mouseShape; } - (id)initWithFrame:(NSRect)frame; diff --git a/src/MacVim/MMTextView.m b/src/MacVim/MMTextView.m index 2e0b978840..6c4ac53558 100644 --- a/src/MacVim/MMTextView.m +++ b/src/MacVim/MMTextView.m @@ -46,6 +46,7 @@ enum { @interface MMTextView (Private) +- (void)setCursor; - (BOOL)convertPoint:(NSPoint)point toRow:(int *)row column:(int *)column; - (BOOL)convertRow:(int)row column:(int)column toPoint:(NSPoint *)point; - (NSRect)trackingRect; @@ -927,7 +928,14 @@ enum { [data appendBytes:&row length:sizeof(int)]; [data appendBytes:&col length:sizeof(int)]; + // NSTextView wants to set the cursor to an IBeam every now and then. + // Not even Apple's TextLinks example application works, so we set + // "our" cursor on every mouse move. + [self setCursor]; + [[self vimController] sendMessage:MouseMovedMsgID data:data]; + + //NSLog(@"Moved %d %d\n", col, row); } } @@ -1093,6 +1101,12 @@ enum { // The font panel is updated whenever the font is set. } +- (void)setMouseShape:(int)shape +{ + mouseShape = shape; + [self setCursor]; +} + @end // MMTextView @@ -1100,6 +1114,47 @@ enum { @implementation MMTextView (Private) +- (void)setCursor +{ + static NSCursor *customIbeamCursor = nil; + + if (!customIbeamCursor) { + // Use a custom Ibeam cursor that has better contrast against dark + // backgrounds. + // TODO: Is the hotspot ok? + NSImage *ibeamImage = [NSImage imageNamed:@"ibeam"]; + if (ibeamImage) { + NSSize size = [ibeamImage size]; + NSPoint hotSpot = { size.width*.5f, size.height*.5f }; + + customIbeamCursor = [[NSCursor alloc] + initWithImage:ibeamImage hotSpot:hotSpot]; + } + if (!customIbeamCursor) { + NSLog(@"WARNING: Failed to load custom Ibeam cursor"); + customIbeamCursor = [NSCursor IBeamCursor]; + } + } + + // This switch should match mshape_names[] in misc2.c. + // + // TODO: Add missing cursor shapes. + switch (mouseShape) { + case 2: [customIbeamCursor set]; break; + case 3: case 4: [[NSCursor resizeUpDownCursor] set]; break; + case 5: case 6: [[NSCursor resizeLeftRightCursor] set]; break; + case 9: [[NSCursor crosshairCursor] set]; break; + case 10: [[NSCursor pointingHandCursor] set]; break; + case 11: [[NSCursor openHandCursor] set]; break; + default: + [[NSCursor arrowCursor] set]; break; + } + + // Shape 1 indicates that the mouse cursor should be hidden. + if (1 == mouseShape) + [NSCursor setHiddenUntilMouseMoves:YES]; +} + - (BOOL)convertPoint:(NSPoint)point toRow:(int *)row column:(int *)column { MMTextStorage *ts = (MMTextStorage*)[self textStorage]; diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m index 7ff93748ca..abc691e72d 100644 --- a/src/MacVim/MMWindowController.m +++ b/src/MacVim/MMWindowController.m @@ -487,43 +487,7 @@ - (void)setMouseShape:(int)shape { - static NSCursor *customIbeamCursor = nil; - - if (!customIbeamCursor) { - // Use a custom Ibeam cursor that has better contrast against dark - // backgrounds. - // TODO: Is the hotspot ok? - NSImage *ibeamImage = [NSImage imageNamed:@"ibeam"]; - if (ibeamImage) { - NSSize size = [ibeamImage size]; - NSPoint hotSpot = { size.width*.5f, size.height*.5f }; - - customIbeamCursor = [[NSCursor alloc] - initWithImage:ibeamImage hotSpot:hotSpot]; - } - if (!customIbeamCursor) { - NSLog(@"WARNING: Failed to load custom Ibeam cursor"); - customIbeamCursor = [NSCursor IBeamCursor]; - } - } - - // This switch should match mshape_names[] in misc2.c. - // - // TODO: Add missing cursor shapes. - switch (shape) { - case 2: [customIbeamCursor set]; break; - case 3: case 4: [[NSCursor resizeUpDownCursor] set]; break; - case 5: case 6: [[NSCursor resizeLeftRightCursor] set]; break; - case 9: [[NSCursor crosshairCursor] set]; break; - case 10: [[NSCursor pointingHandCursor] set]; break; - case 11: [[NSCursor openHandCursor] set]; break; - default: - [[NSCursor arrowCursor] set]; break; - } - - // Shape 1 indicates that the mouse cursor should be hidden. - if (1 == shape) - [NSCursor setHiddenUntilMouseMoves:YES]; + [[vimView textView] setMouseShape:shape]; } - (void)adjustLinespace:(int)linespace