2008年6月13日金曜日

MacVim inline patch

今まで使っていたパッチがあたらなくなってしまったので、微修正。


diff -r -u ../vim7-git/src/MacVim/MMTextView.h src/MacVim/MMTextView.h
--- ../vim7-git/src/MacVim/MMTextView.h 2008-06-13 10:40:34.000000000 +0900
+++ src/MacVim/MMTextView.h 2008-06-13 15:52:09.000000000 +0900
@@ -24,7 +24,9 @@
int insertionPointColumn;
int insertionPointShape;
int insertionPointFraction;
- NSTextField *markedTextField;
+ NSDictionary *markedTextAttributes;
+ NSAttributedString *markedText;
+ NSRange imRange;
int preEditRow;
int preEditColumn;
int mouseShape;
@@ -37,7 +39,6 @@

- (void)setShouldDrawInsertionPoint:(BOOL)on;
- (void)setPreEditRow:(int)row column:(int)col;
-- (void)hideMarkedTextField;
- (void)performBatchDrawWithData:(NSData *)data;
- (void)setMouseShape:(int)shape;
- (void)setAntialias:(BOOL)antialias;
diff -r -u ../vim7-git/src/MacVim/MMTextView.m src/MacVim/MMTextView.m
--- ../vim7-git/src/MacVim/MMTextView.m 2008-06-13 10:40:34.000000000 +0900
+++ src/MacVim/MMTextView.m 2008-06-13 15:51:10.000000000 +0900
@@ -130,10 +130,10 @@
{
//NSLog(@"MMTextView dealloc");

- if (markedTextField) {
- [[markedTextField window] autorelease];
- [markedTextField release];
- markedTextField = nil;
+ if (markedText) {
+ imRange = NSMakeRange(0, 0);
+ [markedText release];
+ markedText = nil;
}

if (invertRects) {
@@ -165,16 +165,6 @@
preEditColumn = col;
}

-- (void)hideMarkedTextField
-{
- if (markedTextField) {
- NSWindow *win = [markedTextField window];
- [win close];
- [markedTextField setStringValue:@""];
- }
-}
-
-
#define MM_DEBUG_DRAWING 0

- (void)performBatchDrawWithData:(NSData *)data
@@ -514,6 +504,19 @@
// NSStringFromRect(ipRect), insertionPointShape,
// [self insertionPointColor]);
}
+
+ if ( [self hasMarkedText] ) {
+ int len = [markedText length];
+ MMTextStorage *ts = (MMTextStorage*)[self textStorage];
+ int wfrac = ([ts cellSize].width* insertionPointFraction + 99)/100 + 1;
+ int hfrac = ([ts cellSize].height* insertionPointFraction + 99)/100 + 1;
+
+ [markedText drawInRect:NSMakeRect(
+ insertionPointColumn*[ts cellSize].width+wfrac,
+ insertionPointRow*[ts cellSize].height,
+ [ts cellSize].width*2*len, [ts cellSize].height+hfrac)];
+ }
+
#if 0
// this code invalidates the shadow, so we don't
// get shifting ghost text on scroll and resize
@@ -544,6 +547,17 @@
//
// TODO: Figure out a way to disable Cocoa key bindings entirely, without
// affecting input management.
+ [NSCursor setHiddenUntilMouseMoves: YES];
+ if ([self hasMarkedText]) {
+ NSString *unmod = [event charactersIgnoringModifiers];
+ if (([markedText length] == 1 && [unmod characterAtIndex:0] == 0x7f)
+ || [unmod characterAtIndex:0] == 0x1b || [unmod characterAtIndex:0] == 0x0d) {
+ [self unmarkText];
+ }
+ [super keyDown:event];
+ [self setNeedsDisplay: YES];
+ return;
+ }
int flags = [event modifierFlags];
if ((flags & NSControlKeyMask) ||
((flags & NSAlternateKeyMask) && (flags & NSFunctionKeyMask))) {
@@ -574,7 +588,9 @@
// modifiers are already included and should not be added to the input
// buffer using CSI, K_MODIFIER).

- [self hideMarkedTextField];
+ if([self hasMarkedText]) {
+ [self unmarkText];
+ }

NSEvent *event = [NSApp currentEvent];

@@ -720,14 +736,12 @@
- (BOOL)hasMarkedText
{
//NSLog(@"%s", _cmd);
- return markedTextField && [[markedTextField stringValue] length] > 0;
+ return markedText && [markedText length] > 0;
}

-- (NSRange)markedRange
+- (NSRange)selectedRange
{
- //NSLog(@"%s", _cmd);
- unsigned len = [[markedTextField stringValue] length];
- return NSMakeRange(len > 0 ? 0 : NSNotFound, len);
+ return NSMakeRange(NSNotFound, 0);
}

- (void)setMarkedText:(id)text selectedRange:(NSRange)range
@@ -735,67 +749,26 @@
//NSLog(@"setMarkedText:'%@' selectedRange:%@", text,
// NSStringFromRange(range));

- MMTextStorage *ts = (MMTextStorage*)[self textStorage];
- if (!ts) return;
-
- if (!markedTextField) {
- // Create a text field and put it inside a floating panel. This field
- // is used to display marked text.
- NSSize cellSize = [ts cellSize];
- NSRect cellRect = { 0, 0, cellSize.width, cellSize.height };
-
- markedTextField = [[NSTextField alloc] initWithFrame:cellRect];
- [markedTextField setEditable:NO];
- [markedTextField setSelectable:NO];
- [markedTextField setBezeled:NO];
- [markedTextField setBordered:YES];
-
- // NOTE: The panel that holds the marked text field is allocated here
- // and released in dealloc. No pointer to the panel is kept, instead
- // [markedTextField window] is used to access the panel.
- NSPanel *panel = [[NSPanel alloc]
- initWithContentRect:cellRect
- styleMask:NSBorderlessWindowMask|NSUtilityWindowMask
- backing:NSBackingStoreBuffered
- defer:YES];
-
- //[panel setHidesOnDeactivate:NO];
- [panel setFloatingPanel:YES];
- [panel setBecomesKeyOnlyIfNeeded:YES];
- [panel setContentView:markedTextField];
- }
-
+ [self unmarkText];
if (text && [text length] > 0) {
- [markedTextField setFont:[ts font]];
+ MMTextStorage *ts = (MMTextStorage*)[self textStorage];
if ([text isKindOfClass:[NSAttributedString class]])
- [markedTextField setAttributedStringValue:text];
+ markedText=[[NSAttributedString alloc] initWithString:[text string]
+ attributes:[self markedTextAttributes]];
else
- [markedTextField setStringValue:text];
-
- [markedTextField sizeToFit];
- NSSize size = [markedTextField frame].size;
-
- // Convert coordinates (row,col) -> view -> window base -> screen
- NSPoint origin;
- if (![self convertRow:preEditRow+1 column:preEditColumn
- toPoint:&origin])
- return;
- origin = [self convertPoint:origin toView:nil];
- origin = [[self window] convertBaseToScreen:origin];
-
- NSWindow *win = [markedTextField window];
- [win setContentSize:size];
- [win setFrameOrigin:origin];
- [win orderFront:nil];
- } else {
- [self hideMarkedTextField];
+ markedText=[[NSAttributedString alloc] initWithString:text
+ attributes:[self markedTextAttributes]];
+ imRange = NSMakeRange(0, [markedText length]);
+ [self setNeedsDisplay: YES];
}
}

- (void)unmarkText
{
//NSLog(@"%s", _cmd);
- [self hideMarkedTextField];
+ imRange = NSMakeRange(0, 0);
+ [markedText release];
+ markedText = nil;
}

- (NSRect)firstRectForCharacterRange:(NSRange)range
diff -r -u ../vim7-git/src/MacVim/MMWindowController.m src/MacVim/MMWindowController.m
--- ../vim7-git/src/MacVim/MMWindowController.m 2008-06-13 10:40:34.000000000 +0900
+++ src/MacVim/MMWindowController.m 2008-06-13 15:51:10.000000000 +0900
@@ -654,9 +654,6 @@
- (void)windowDidResignMain:(NSNotification *)notification
{
[vimController sendMessage:LostFocusMsgID data:nil];
-
- if ([vimView textView])
- [[vimView textView] hideMarkedTextField];
}

- (BOOL)windowShouldClose:(id)sender

0 件のコメント: